Kubernetes Certification Training Course : Lecture 2

kubectl get nodes – command that show all the nodes in the cluster. This command is executed on Master. If kubelet service is not running on the nodes(s), then in the STATUS column Not Ready will be shown (normally there must be Ready status).

kubectl describe – command to know about any object in Kubernetes. For example, kubectl describe node node01 shows all the information about node in the cluster that has the name node01.

kubectl get pods – command that by default shows all pods from all nodes in the cluster. kubectl get pods -o wide shows more information about the pods. It is essential to note that kubelet does not run in a pod (does not run as a container), it runs as a service.

Pod is an extra layer on top of the CRI (usually Docker) container. This layer (pod) is presented by Kubernetes. Pods contain IP addresses, like Docker containers do. IP addresses remain the same, even if container restarts. Pod is the least object that can be created by Kubernetes for running applications. Single Pod in Kubernetes can contain more than one containers. It is not a good practice though. Recommended relation is 1 Pod – 1 Container. In Kubernetes if one container of those in the same Pod is down, another one will down automatically. There cannot be identical containers in one Pod (no two nginx – s, no two tomcat – s etc).

kubectl api-resources – command that shows all the possible resources on the system, all the possible Kubernetes topics and concepts.

kubectl explain – command used to know about any object in Kubernetes. It is unlike describe command, which shows information about existing object in the system. kubectl explain is like a knowledge base. For example, kubectl explain pods (not some certain pod).

kubectl run <pod name> –image <name of the CRI (usually Docker) image> – command for creating and running a pod (for example, kubectl run pod1 –image nginx)

kubectl delete pod <pod name> – command to delete Pod

kubectl delete pods –all – deletes all the pods in the cluster

Note: images with a plain operating system never run continuously because there are no running processes inside them. Solution is to run some process inside. For instance, kubectl run pod3 –image centos sleep 120 – will be running for 120 seconds before dying.

yaml is data serialization language or a structured language to represent the data. Data in yaml can be represented in several ways

  • key: values pairs
  • lists (set of values)
  • dictionary (each value in a set has a set of items)

Important to note that yaml files are about indentations. Spaces must be treated carefully in yaml as spaces are defining the structure. Tab should not be used, only spaces.

The frame of the yaml file incorporates the following 4 fields (kubectl explain pods command has their description) :

  • apiVersion
  • kind
  • metadata
  • spec

Below is a simple example of yaml file :

apiVersion: v1
kind : Pod
metadata:
   name: somePod
spec:
   containers:
      - image: nginx
        name: one

It creates and runs a container with name one based on nginx image and creates and runs a pod named somePod on top of CRI container. Note that containers is a list item (set of values), since Pod can have more than one container (but it is not recommended). That is why each element in the list (even if it is one element like in above example) is preceeded by hyphen “-“.

Number of spaces for indentations is not critical, first of all they must shape the proper structure (with subsections).

kubectl create -f <name of yaml(or yml) file> – command used for creating and running pod(s) via using yaml syntax

kubectl apply -f <name of yaml(or yml) file> – command used for creating and running pod(s) via using yaml syntax. Unlike create command that tries to create new object, apply first tries to find the Pod with the same name. If it finds, then changes defined in yaml syntax are applied (configured). Otherwise new Pod is created and run.

kubectl logs <pod name> – command for watching pod log (what is happening inside pod)

kubectl exec -it <pod name> — bash – command for entering the Pod, -it is used for interactive entering, with the access to command prompt; bash is the type of command prompt (it can be sh, ksh etc, bash is not mandatory). To come out of the pod, Ctrl + P + Q combination is used

Command cat /etc/os-release lets see the Operating System used by Pod (container).

Pod cannot be restarted like a Docker container. Pod can be created or deleted, that is all.

kubectl run <pod name> –image <image name from docker hub> –dry-run=client -o yaml – command that generates yaml file based on the information inside the command. This command does not create the Pod. Without –dry-run parameter the output of the command will contain much more information (which often can be excessive) about the Pod. Besides without –dry-run parameter the command will create the Pod

kubectl get pods <pod name> -o yaml – command that shows precise information about defined Pod in yaml format

kubectl get pods <pod name> -o yaml > <file name> – command that exports information about defined Pod in defined file

kubectl get pods <pod name> -o json – command that shows precise information about defined Pod in json format. yaml is easier to use than json

The file with the information about the Pod can be corrected for generating pods with different predefined settings. For instance, an image name can be changed.

Next

Leave a Reply

Your email address will not be published. Required fields are marked *