Deploy the Guestbook application to your TKG cluster and explore Kubernetes.
Deploying the Guestbook application is a useful way to explore Kubernetes. The application uses Deployment and ReplicaSet objects to deploy pods in the default namespace, and exposes these pods using Services. Guestbook data is persisted so that if the application goes down, the data remains. This tutorial uses a dynamic persistent volume claim (PVC) to request persistent storage resources without knowing the details of the underlying storage. The storage used for the PVC is allocated from the storage quota for the vSphere Namespace. Containers by default are ephemeral and stateless. For stateful workloads, a common approach is to create a persistent volume claim (PVC). You can use a PVC to mount the persistent volumes and access storage. The request dynamically provisions a persistent volume object and a matching virtual disk. The claim is bound to the persistent volume. When you delete the claim, the corresponding persistent volume object and the provisioned virtual disk are also deleted.
Prerequisites
Review the following topics:
Procedure
- Log in to the TKG cluster.
- Create the Guestbook namespace.
kubectl create namespace guestbook
- Create role-based access control using the default privileged PSP.
kubectl create clusterrolebinding default-tkg-admin-privileged-binding --clusterrole=psp:vmware-system-privileged --group=system:authenticated
Note: If you require more security, apply a RoleBinding on the Guestbook namespace.
- Verify the storage class, or create one.
To verify an existing storage class:
kubectl describe namespace
Or, if you have vSphere administrator permissions:
kubectl get storageclass
- Create the dynamic persistent volume claims (PVCs) YAML files that reference the storage class.
Use the following YAML files. Update each with the name of the storage class.
- Apply the Guestbook PVCs to the cluster.
kubectl apply -f redis-leader-pvc.yaml -n guestbook
kubectl apply -f redis-follower-pvc.yaml -n guestbook
- Verify the status of the PVCs.
kubectl get pvc,pv -n guestbook
The PVCs and persistent volumes (PVs) are listed and available for use.
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
persistentvolumeclaim/redis-follower-pvc Bound pvc-37b72f35-3de2-4f84-be7d-50d5dd968f62 2Gi RWO tkgs-storage-class 66s
persistentvolumeclaim/redis-leader-pvc Bound pvc-2ef51f31-dd4b-4fe2-bf4c-f0149cb4f3da 2Gi RWO tkgs-storage-class 66s
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS
persistentvolume/pvc-2ef51f31-dd4b-4fe2-bf4c 2Gi RWO Delete Bound guestbook/redis-leader-pvc tkgs-storage-class
persistentvolume/pvc-37b72f35-3de2-4f84-be7d 2Gi RWO Delete Bound guestbook/redis-follower-pvc tkgs-storage-class
- Create the Guestbook YAML files.
Use the following YAML files:
- Deploy the Guestbook application in its namespace.
kubectl apply -f . --namespace guestbook
- Verify creation of the Guestbook resources.
kubectl get all -n guestbook
NAME READY STATUS RESTARTS AGE
pod/guestbook-frontend-deployment-56fc5b6b47-cd58r 1/1 Running 0 65s
pod/guestbook-frontend-deployment-56fc5b6b47-fh6dp 1/1 Running 0 65s
pod/guestbook-frontend-deployment-56fc5b6b47-hgd2b 1/1 Running 0 65s
pod/redis-follower-deployment-6fc9cf5759-99fgw 1/1 Running 0 65s
pod/redis-follower-deployment-6fc9cf5759-rhxf7 1/1 Running 0 65s
pod/redis-leader-deployment-7d89bbdbcf-flt4q 1/1 Running 0 65s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/guestbook-frontend LoadBalancer 10.10.89.59 10.19.15.99 80:31513/TCP 65s
service/redis-follower ClusterIP 10.111.163.189 <none> 6379/TCP 65s
service/redis-leader ClusterIP 10.111.70.189 <none> 6379/TCP 65s
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/guestbook-frontend-deployment 3/3 3 3 65s
deployment.apps/redis-follower-deployment 1/2 2 1 65s
deployment.apps/redis-leader-deployment 1/1 1 1 65s
NAME DESIRED CURRENT READY AGE
replicaset.apps/guestbook-frontend-deployment-56fc5b6b47 3 3 3 65s
replicaset.apps/redis-follower-deployment-6fc9cf5759 2 2 1 65s
replicaset.apps/redis-leader-deployment-7d89bbdbcf 1 1 1 65s
- Access the Guestbook web page using the
External-IP
address of the service/guestbook-frontend
load balancer, which in this example is 10.19.15.99
.
You see the Guestbook web interface, and you can enter values into the Guestbook database. If you restart the application, the data is persisted.