To demonstrate independent scaling, let's use the guestbook example that we used in the previous chapter. Let's follow these steps to learn how to implement independent scaling:
- Install the guestbook by running the kubectl create command in the Azure command line:
kubectl create -f https://raw.githubusercontent.com/kubernetes/examples/master/guestbook/all-in-one/guestbook-all-in-one.yaml
- After you have entered the preceding command, you should see the following output in your command-line output:
ab443838-9b3e-4811-b287-74e417a9@Azure:~$ kubectl create -f https://raw.githubusercontent.com/kubernetes/examples/master/guestbook/all-in-one/guestbook-all-in-one.yaml
service/redis-master created
deployment.apps/redis-master created
service/redis-slave created
deployment.apps/redis-slave created
service/frontend created
deployment.apps/frontend created
- After a few minutes, you should get the following output in which you will see that none of the containers are accessible from the internet, and no external IP is assigned:
ab443838-9b3e-4811-b287-74e417a9@Azure:~$ kc get all
NAME READY STATUS RESTARTS AGE
pod/frontend-56f7975f44-7sdn5 1/1 Running 0 1m
pod/frontend-56f7975f44-hscn7 1/1 Running 0 1m
pod/frontend-56f7975f44-pqvbg 1/1 Running 0 1m
pod/redis-master-6b464554c8-8nv4s 1/1 Running 0 1m
pod/redis-slave-b58dc4644-597qt 1/1 Running 0 1m
pod/redis-slave-b58dc4644-xtdkx 1/1 Running 0 1m
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/frontend ClusterIP 10.0.174.190 <none> 80/TCP 1m
service/kubernetes ClusterIP 10.0.0.1 <none> 443/TCP 3d
service/redis-master ClusterIP 10.0.208.204 <none> 6379/TCP 1m
service/redis-slave ClusterIP 10.0.225.59 <none> 6379/TCP 1m
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
deployment.apps/frontend 3 3 3 3 1m
deployment.apps/redis-master 1 1 1 1 1m
deployment.apps/redis-slave 2 2 2 2 1m
NAME DESIRED CURRENT READY AGE
replicaset.apps/frontend-56f7975f44 3 3 3 1m
replicaset.apps/redis-master-6b464554c8 1 1 1 1m
replicaset.apps/redis-slave-b58dc4644 2 2 2 1m
- Expose the frontend to the public internet by default using the following command:
kc get -o yaml svc/frontend > frontend-service.yaml
code frontend-service.yaml
- Edit the frontend-service.yaml file to set the labels, ports, and selector, which should appear as follows (or you can cut and paste the following):
apiVersion: v1
kind: Service
metadata:
labels:
app: guestbook
tier: frontend
name: frontend
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
app: guestbook
tier: frontend
type: LoadBalancer
- Save the file and recreate the frontend service so that we can access it publicly by deleting the frontend service and recreating it as follows:
kubectl delete -f frontend-service.yaml
kubectl create -f frontend-service.yaml
- Use the following command to get the public IP to access the application via the internet:
kubectl get svc
You will get the following output. You need to look for the IP displayed under the EXTERNAL-IP column:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
frontend LoadBalancer 10.0.196.116 <EXTERNAL-IP> 80:30063/TCP 2m
- Type the IP address from the preceding output into your browser navigation bar as follows: http://<EXTERNAL-IP>/. The result of this is shown in the following screenshot:
The familiar guestbook sample should be visible. You have successfully publically accessed the guestbook.