Home Explore Blog CI



kubernetes

1st chunk of `content/en/docs/tutorials/stateless-application/guestbook.md`
7ed3e84b7eee08cedd5c981764f056f7a5ec809b038c141c0000000100000fac
---
title: "Example: Deploying PHP Guestbook application with Redis"
reviewers:
- ahmetb
- jimangel
content_type: tutorial
weight: 20
card:
  name: tutorials
  weight: 30
  title: "Stateless Example: PHP Guestbook with Redis"
min-kubernetes-server-version: v1.14
source: https://cloud.google.com/kubernetes-engine/docs/tutorials/guestbook
---

<!-- overview -->
This tutorial shows you how to build and deploy a simple _(not production
ready)_, multi-tier web application using Kubernetes and
[Docker](https://www.docker.com/). This example consists of the following
components:

* A single-instance [Redis](https://www.redis.io/) to store guestbook entries
* Multiple web frontend instances

## {{% heading "objectives" %}}

* Start up a Redis leader.
* Start up two Redis followers.
* Start up the guestbook frontend.
* Expose and view the Frontend Service.
* Clean up.

## {{% heading "prerequisites" %}}

{{< include "task-tutorial-prereqs.md" >}}

{{< version-check >}}

<!-- lessoncontent -->

## Start up the Redis Database

The guestbook application uses Redis to store its data.

### Creating the Redis Deployment

The manifest file, included below, specifies a Deployment controller that runs a single replica Redis Pod.

{{% code_sample file="application/guestbook/redis-leader-deployment.yaml" %}}

1. Launch a terminal window in the directory you downloaded the manifest files.
1. Apply the Redis Deployment from the `redis-leader-deployment.yaml` file:

   <!---
   for local testing of the content via relative file path
   kubectl apply -f ./content/en/examples/application/guestbook/redis-leader-deployment.yaml
   -->

   ```shell
   kubectl apply -f https://k8s.io/examples/application/guestbook/redis-leader-deployment.yaml
   ```

1. Query the list of Pods to verify that the Redis Pod is running:

   ```shell
   kubectl get pods
   ```

   The response should be similar to this:

   ```
   NAME                           READY   STATUS    RESTARTS   AGE
   redis-leader-fb76b4755-xjr2n   1/1     Running   0          13s
   ```

1. Run the following command to view the logs from the Redis leader Pod:

   ```shell
   kubectl logs -f deployment/redis-leader
   ```

### Creating the Redis leader Service

The guestbook application needs to communicate to the Redis to write its data.
You need to apply a [Service](/docs/concepts/services-networking/service/) to
proxy the traffic to the Redis Pod. A Service defines a policy to access the
Pods.

{{% code_sample file="application/guestbook/redis-leader-service.yaml" %}}

1. Apply the Redis Service from the following `redis-leader-service.yaml` file:

   <!---
   for local testing of the content via relative file path
   kubectl apply -f ./content/en/examples/application/guestbook/redis-leader-service.yaml
   -->

   ```shell
   kubectl apply -f https://k8s.io/examples/application/guestbook/redis-leader-service.yaml
   ```

1. Query the list of Services to verify that the Redis Service is running:

   ```shell
   kubectl get service
   ```

   The response should be similar to this:

   ```
   NAME           TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)    AGE
   kubernetes     ClusterIP   10.0.0.1     <none>        443/TCP    1m
   redis-leader   ClusterIP   10.103.78.24 <none>        6379/TCP   16s
   ```

{{< note >}}
This manifest file creates a Service named `redis-leader` with a set of labels
that match the labels previously defined, so the Service routes network
traffic to the Redis Pod.
{{< /note >}}

### Set up Redis followers

Although the Redis leader is a single Pod, you can make it highly available
and meet traffic demands by adding a few Redis followers, or replicas.

{{% code_sample file="application/guestbook/redis-follower-deployment.yaml" %}}

1. Apply the Redis Deployment from the following `redis-follower-deployment.yaml` file:

   <!---
   for local testing of the content via relative file path
   kubectl apply -f ./content/en/examples/application/guestbook/redis-follower-deployment.yaml

Title: Deploying a PHP Guestbook Application with Redis on Kubernetes: Setting up Redis
Summary
This section of the tutorial guides you through deploying a simple multi-tier web application (PHP Guestbook) using Kubernetes and Docker. It focuses on setting up the Redis database, which includes creating a Redis leader deployment and service, and then setting up Redis followers (replicas) for high availability and increased traffic handling.