kubectl get command

To see the overall picture of deployed applications, x provides the get command. The get command lists the resources that you specify. Resources can be pods, replication controllers, ingress, nodes, deployments, secrets, and so on. We have already run this in the previous chapters to verify whether our application is ready to be used or not. Perform the following steps:

  1. Run the following get command, which will get us the resources and their statuses:
kubectl get all

You will get something like this, as shown in the following block:

NAME                                                            READY     STATUS    RESTARTS   AGE
pod/frontend-5785f8455c-2dsgt 0/1 Pending 0 9s
pod/frontend-5785f8455c-f8knz 0/1 Pending 0 9s
pod/frontend-5785f8455c-p9mh9 0/1 Pending 0 9s
pod/redis-master-6b464554c8-sghfh 0/1 Pending 0 9s
pod/redis-slave-b58dc4644-2ngwx 0/1 Pending 0 9s
pod/redis-slave-b58dc4644-58lv2 0/1 Pending 0 9s

...
  1. Now to view the pods, run the following command:
kubectl get -w pods

The command doesn't exit and changes output only if the state of any pod changes. For example, you will see an output that is similar to this:

ab443838-9b3e-4811-b287-74e417a9@Azure:~$ kubectl get -w pods
NAME READY STATUS RESTARTS AGE
frontend-5785f8455c-2dsgt 0/1 Pending 0 5m
frontend-5785f8455c-f8knz 0/1 Pending 0 5m
frontend-5785f8455c-p9mh9 0/1 Pending 0 5m
redis-master-6b464554c8-sghfh 0/1 Pending 0 5m
redis-slave-b58dc4644-2ngwx 0/1 Pending 0 5m
redis-slave-b58dc4644-58lv2 0/1 Pending 0 5m

If you wait long enough, you will get the following:

frontend-5785f8455c-f8knz   0/1       ContainerCreating   0         8m
frontend-5785f8455c-2dsgt 0/1 ContainerCreating 0 8m
redis-master-6b464554c8-sghfh 0/1 ContainerCreating 0 8m
redis-slave-b58dc4644-58lv2 0/1 ContainerCreating 0 8m
redis-slave-b58dc4644-2ngwx 0/1 ContainerCreating 0 8m
frontend-5785f8455c-p9mh9 0/1 ContainerCreating 0 8m
frontend-5785f8455c-f8knz 1/1 Running 0 8m
frontend-5785f8455c-2dsgt 1/1 Running 0 8m
redis-master-6b464554c8-sghfh 1/1 Running 0 8m
redis-slave-b58dc4644-58lv2 1/1 Running 0 8m
redis-slave-b58dc4644-2ngwx 1/1 Running 0 8m
frontend-5785f8455c-p9mh9 1/1 Running 0 8m

You will see only the pods are shown. Also, you get a view of the state changes of the pods that kubernetes handles. The first column is the pod name (frontend-5785f8455c-f8knz), for example. The second column is how many containers in the pod are ready over the total number of containers in the pod (0/1 initially meaning 0 containers are up while a total of 1 is expected). The third column is the status (Pending/ContainerCreating/Running/...). The fourth column is the number of restarts. The fifth column is the age (when the pod was asked to be created).

Press Ctrl + C to stop the monitoring.

Once the state changes, you don't see the history of state changes. For example, if you run the same command now, it will be stuck at the running state till you press Ctrl + C:

ab443838-9b3e-4811-b287-74e417a9@Azure:~$ kubectl get -w pods
NAME READY STATUS RESTARTS AGE
frontend-5785f8455c-2dsgt 1/1 Running 0 26m
frontend-5785f8455c-f8knz 1/1 Running 0 26m
frontend-5785f8455c-p9mh9 1/1 Running 0 26m
redis-master-6b464554c8-sghfh 1/1 Running 0 26m
redis-slave-b58dc4644-2ngwx 1/1 Running 0 26m
redis-slave-b58dc4644-58lv2 1/1 Running 0 26m

To see the history if something goes wrong, run the following command:

kubectl get events
Kubernetes maintains events for only one hour by default. All the commands work only if the event was fired within the past hour.

If everything went well, you should have an output something similar to the following one:

   42s         42s          1         frontend-5785f8455c-wxsdm.1581ea340ab4ab56       Pod                                       Normal    Scheduled              default-scheduler                   Successfully assigned default/frontend-5785f8455c-wxsdm to aks-agentpool-26533852-0
42s 42s 1 frontend-5785f8455c.1581ea34098640c9 ReplicaSet Normal SuccessfulCreate replicaset-controller Created pod: frontend-5785f8455c-lkjgc
40s 40s 1 frontend-5785f8455c-2trpg.1581ea3487c328b5 Pod spec.containers{php-redis} Normal Pulled kubelet, aks-agentpool-26533852-0 Container image "gcr.io/google-samples/gb-frontend:v3" already present on machine
40s 40s 1 frontend-5785f8455c-2trpg.1581ea34b5abca9e Pod spec.containers{php-redis} Normal Created kubelet, aks-agentpool-26533852-0 Created container
39s 39s 1 frontend-5785f8455c-2trpg.1581ea34d18c96f8 Pod spec.containers{php-redis} Normal Started kubelet, aks-agentpool-26533852-0 Started container

The general states for a pod are Scheduled->Pulled->Created->Started. As we will see next, things can fail at any of the states, and we need to use the kubectl get command to dig deeper.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset