$ kubectl -n $(id -un) apply -f https://kubernetes.io/examples/application/guestbook/redis-leader-deployment.yaml
$ kubectl -n $(id -un) get pods -l app=redis
$ kubectl -n $(id -un) apply -f https://kubernetes.io/examples/application/guestbook/redis-leader-service.yaml
$ kubectl -n $(id -un) get service -l app=redis
1. Example: Deploying PHP Guestbook application with Redis
This section describes how to run the official example published on kubernetes.io on this k8s cluster.
This is a guestbook (doodle) application written in PHP language using a Non-SQL database server called Redis.
1.1. Basic method
I’m going to look at the Tutorial 2 page and run the commands,
Here is a list of commands with -n $(id -n)
added mainly.
1.1.1. Database Server - Starting Redis
1.1.2. Start Slave Database Server
$ kubectl -n $(id -un) apply -f https://kubernetes.io/examples/application/guestbook/redis-follower-deployment.yaml
$ kubectl -n $(id -un) get pods -l app=redis
$ kubectl -n $(id -un) apply -f https://kubernetes.io/examples/application/guestbook/redis-follower-service.yaml
$ kubectl -n $(id -un) get service -l app=redis
1.1.3. Start the guestbook application
$ kubectl -n $(id -un) apply -f https://kubernetes.io/examples/application/guestbook/frontend-deployment.yaml
$ kubectl -n $(id -un) get pods -l app=guestbook
$ kubectl -n $(id -un) apply -f https://kubernetes.io/examples/application/guestbook/frontend-service.yaml
$ kubectl -n $(id -un) get services -l app=guestbook
Check the current status with the following command.
$ kubectl -n $(id -un) get all -l "app in (redis, guestbook)"
If all goes well, you should get output like this
NAME READY STATUS RESTARTS AGE
pod/frontend-767747dfdd-hgsl7 1/1 Running 0 5m48s
pod/frontend-767747dfdd-mnqt2 1/1 Running 0 5m48s
pod/frontend-767747dfdd-s8pz9 1/1 Running 0 5m48s
pod/redis-follower-86546888fd-488pt 1/1 Running 0 6m45s
pod/redis-follower-86546888fd-xzv4t 1/1 Running 0 6m45s
pod/redis-leader-55b556899d-r4lds 1/1 Running 0 9m2s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/frontend ClusterIP 10.233.9.162 <none> 80/TCP 7s
service/redis-follower ClusterIP 10.233.50.148 <none> 6379/TCP 6m5s
service/redis-leader ClusterIP 10.233.10.36 <none> 6379/TCP 6m58s
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/redis-follower 2/2 2 2 6m45s
deployment.apps/redis-leader 1/1 1 1 9m2s
NAME DESIRED CURRENT READY AGE
replicaset.apps/frontend-767747dfdd 3 3 3 5m48s
replicaset.apps/redis-follower-86546888fd 2 2 2 6m45s
replicaset.apps/redis-leader-55b556899d 1 1 1 9m2s
1.1.4. Viewing the Frontend Service via LoadBalancer
Although not detailed in the official tutorial, there are two ways to access the service.
-
use LoadBalancer to obtain an EXTERNAL-IP as described in the official tutorial
-
modify cm/nginx-conf and access via each individual’s Reverse Proxy.
1.1.4.1. (1) Use LoadBalancer as follows
$ env EDITOR=emacs kubectl -n $(id -un) edit svc frontend
Change the .spec.type value to LoadBalancer as follows
sessionAffinity: None
type: LoadBalancer
status:
loadBalancer: {}
1.1.4.2. (2) Modify cm/nginx-conf as follows
$ env EDITOR=emacs kubectl -n $(id -un) edit cm nginx-conf
Inside location /<your namespace>/ { } should look like proxy_pass http://frontend/; as follows
apiVersion: v1
data:
proxy.conf: |
server {
listen 80;
location /<your namespace>/ {
proxy_pass http://frontend/;
}
}
kind: ConfigMap
metadata:
Be sure to restart pod/my-proxy after making any changes to cm/nginx-conf.
$ kubectl -n $(id -un) delete pod -l app=my-proxy
Change to access the service one way or the other, and access the guestbook app assigned to service/frontend from a web browser.
1.2. Running considerations - edit command description
At the end of the day, Creating the Frontend Service, you will find instructions for registering the Service.
The next section Viewing the Frontend Service via NodePort, there is a place to run the minikube command, which does not exist. The description says "If you deployed this application to Minikube or a local cluster, you need to find the IP address to view your Guestbook. If you deployed this application to Minikube or a local cluster, you need to find the IP address to view your Guestbook.
On the contrary, the following Viewing the Frontend Service via LoadBalancer needs to be executed.
There are two main ways to do this, and you can fix it in either of the following two ways.
-
https://kubernetes.io/examples/application/ Download [guestbook/frontend-service.yaml and modify the file with type: NodePort to type: LoadBalancer and again $ kubectl -n $(id -un) apply -f <changed filename >2. update the definition with **$ kubectl -n $(id -un)
-
run $ kubectl -n $(id -un) edit svc frontend and rewrite type: NodePort to type: LoadBalancer using an editor and save it.
Run kubectl edit to launch the vi command. If you still can’t get it to work, use emacs in the following way.
$ env EDITOR=emacs kubectl -n $(id -un) edit svc frontend
If the final working application runs, you are done.
Please be careful not to run kubectl delete before checking from a web browser, as the official tutorial follows the process of deleting (kubectl delete) as is.
1.3. Delete used objects
Deletion can be performed by specifying the YAML file at the time of apply to delete the created object without omission.
$ kubectl -n $(id -un) delete -f https://kubernetes.io/examples/application/guestbook/frontend-deployment.yaml
$ kubectl -n $(id -un) delete -f https://kubernetes.io/examples/application/guestbook/frontend-service.yaml
$ kubectl -n $(id -un) delete -f https://kubernetes.io/examples/application/guestbook/redis-slave-deployment.yaml
$ kubectl -n $(id -un) delete -f https://kubernetes.io/examples/application/guestbook/redis-slave-service.yaml
$ kubectl -n $(id -un) delete -f https://kubernetes.io/examples/application/guestbook/redis-master-deployment.yaml
$ kubectl -n $(id -un) delete -f https://kubernetes.io/examples/application/guestbook/redis-master-service.yaml
## Verify that the last created pod, svc has been deleted
$ kubectl -n $(id -un) get all
After confirming, delete the created Pod, Service definition.
1.4. [For advanced users] Confirm the contents stored in the Redis server.
First, login to the appropriate pod/frontend.
$ kubectl -n $(id -un) exec -it "$(kubectl -n $(id -un) get pod -l app=guestbook -o jsonpath='{.items[0].metadata.name}')" -- bash
From within this pod, connect to the Redis server with the curl command.
# curl telnet://redis-follower:6379
get guestbook
Type get guestbook
and you will see the message you typed into your web browser until then.
$38
,test message by yasu-abe,next message