DEV Community

Wycliffe A. Onyango
Wycliffe A. Onyango

Posted on

100 Days of DevOps: Day 67

Three-Tier Guestbook Application Deployment on Kubernetes

Executive Summary

I have successfully deployed the required three-tier Guestbook application on the Kubernetes cluster. All six resources—three Deployments and three Services—were created and are now running correctly. The Redis master and slave tiers, along with the PHP frontend, are operational, and the application is exposed externally via the required NodePort 30009.


Deployment Execution and Manifest (guestbook-deployment.yaml)

The following unified YAML manifest (guestbook-deployment.yaml) was used to create all application components:

# ----------------------------------------------------
# BACK-END TIER: REDIS MASTER DEPLOYMENT
# ----------------------------------------------------
apiVersion: apps/v1
kind: Deployment
metadata:
  name: redis-master
  labels:
    app: redis
    role: master
    tier: backend
spec:
  replicas: 1
  selector:
    matchLabels:
      app: redis
      role: master
  template:
    metadata:
      labels:
        app: redis
        role: master
        tier: backend
    spec:
      containers:
      - name: master-redis-datacenter
        image: redis
        resources:
          requests:
            cpu: 100m
            memory: 100Mi
        ports:
        - containerPort: 6379

---
# ----------------------------------------------------
# BACK-END TIER: REDIS MASTER SERVICE
# ----------------------------------------------------
apiVersion: v1
kind: Service
metadata:
  name: redis-master
  labels:
    app: redis
    role: master
    tier: backend
spec:
  ports:
  - port: 6379
    targetPort: 6379
  selector:
    app: redis
    role: master

---
# ----------------------------------------------------
# BACK-END TIER: REDIS SLAVE DEPLOYMENT
# ----------------------------------------------------
apiVersion: apps/v1
kind: Deployment
metadata:
  name: redis-slave
  labels:
    app: redis
    role: slave
    tier: backend
spec:
  replicas: 2
  selector:
    matchLabels:
      app: redis
      role: slave
  template:
    metadata:
      labels:
        app: redis
        role: slave
        tier: backend
    spec:
      containers:
      - name: slave-redis-datacenter
        image: gcr.io/google_samples/gb-redisslave:v3
        resources:
          requests:
            cpu: 100m
            memory: 100Mi
        env:
        - name: GET_HOSTS_FROM
          value: dns
        ports:
        - containerPort: 6379

---
# ----------------------------------------------------
# BACK-END TIER: REDIS SLAVE SERVICE
# ----------------------------------------------------
apiVersion: v1
kind: Service
metadata:
  name: redis-slave
  labels:
    app: redis
    role: slave
    tier: backend
spec:
  ports:
  - port: 6379
    targetPort: 6379
  selector:
    app: redis
    role: slave

---
# ----------------------------------------------------
# FRONT-END TIER DEPLOYMENT
# ----------------------------------------------------
apiVersion: apps/v1
kind: Deployment
metadata:
  name: frontend
  labels:
    app: guestbook
    tier: frontend
spec:
  replicas: 3
  selector:
    matchLabels:
      app: guestbook
      tier: frontend
  template:
    metadata:
      labels:
        app: guestbook
        tier: frontend
    spec:
      containers:
      - name: php-redis-datacenter
        image: gcr.io/google-samples/gb-frontend@sha256:a908df8486ff66f2c4daa0d3d8a2fa09846a1fc8efd65649c0109695c7c5cbff
        resources:
          requests:
            cpu: 100m
            memory: 100Mi
        env:
        - name: GET_HOSTS_FROM
          value: dns
        ports:
        - containerPort: 80

---
# ----------------------------------------------------
# FRONT-END TIER SERVICE (NODEPORT)
# ----------------------------------------------------
apiVersion: v1
kind: Service
metadata:
  name: frontend
  labels:
    app: guestbook
    tier: frontend
spec:
  type: NodePort
  ports:
  - port: 80
    targetPort: 80
    nodePort: 30009
  selector:
    app: guestbook
    tier: frontend
Enter fullscreen mode Exit fullscreen mode

Deployment Execution and Verification

The following commands and their outputs confirm the successful creation and status of all components:

Execution Commands

Command Output
thor@jumphost ~$ kubectl apply -f guestbook-deployment.yaml deployment.apps/redis-master created
service/redis-master created
deployment.apps/redis-slave created
service/redis-slave created
deployment.apps/frontend created
service/frontend created

Deployment Health Check

Command Output
thor@jumphost ~$ kubectl get deployments NAME READY UP-TO-DATE AVAILABLE AGE
frontend 3/3 3 3 50s
redis-master 1/1 1 1 51s
redis-slave 2/2 2 2 51s

Pod Status Check

Command Output
thor@jumphost ~$ kubectl get pods NAME READY STATUS RESTARTS AGE
frontend-5dc567d575-9mfnq 1/1 Running 0 50s
frontend-5dc567d575-tmq4s 1/1 Running 0 50s
frontend-5dc567d575-xfxng 1/1 Running 0 50s
redis-master-554f64dc8b-fwbt8 1/1 Running 0 51s
redis-slave-bf4ff5dbf-krsb4 1/1 Running 0 51s
redis-slave-bf4ff5dbf-r6h2q 1/1 Running 0 50s

Service and Networking Verification

Command Output
thor@jumphost ~$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
frontend NodePort 10.96.58.65 <none> 80:30009/TCP 40s
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 11m
redis-master ClusterIP 10.96.127.189 <none> 6379/TCP 41s
redis-slave ClusterIP 10.96.34.8 <none> 6379/TCP 41s

The application is deployed and ready for access on NodePort 30009.

Top comments (0)