Label is a way to identify a thing, particular object. When running many pods in Kubernetes labels are used for pods identification. When using yaml (yml) files, labels are in metadata section.
kubectl run <pod name> –image <image name from docker hub> –labels='<list of labels in the form labelName=labelValue separated by commas>’ – command that creates and runs Pod supplying the Pod with labels
kubectl get pods –show-labels – command that shows pods labels in separate column in the output
kubectl get pods -l <labelName=labelValue> – command that shows only pods with defined label
kubectl run <pod name> –image <image name from docker hub> –env='<list of environment variables in the form name=value separated by commas>’ – command that creates and runs Pod supplying the Pod with environment variables
Environment variables are used inside the Pod (container). Environment variables are in spec:containers section of yaml file.
kubectl run <pod name> –image <image name from docker hub> –requests=’cpu=1,memory=500Mi’ –limits=’cpu=1.5,memory=1000Mi’ – command that requests minimum 1 cpu and 500Mi memory for execution (values can be different), but not more than 1.5 cpu and 1000Mi (–requests are for minimum, –limits are for maximum)
1 cpu core = 1000 m cpus (1 cpu core is equal to 1000 milli cpus)
1 Mi = 1024Kb (whereas 1 Mb = 1000 Kb)
Resources restrictions are in spec:containers section of yaml file
lscpu – command that gathers and shows CPU architecture information
Namespaces in Kubernetes are “separate rooms” that isolate pods within them.
kubectl create ns <name of namespace> – command for creating Namespace
kubectl run <pod name> –image <image name from docker hub> -n <name of namespace> – command that creates and runs Pod in defined Namespace
kubectl get pods -n <name of namespace> – shows all the pods of given Namespace (without -n parameter pods from default Namespace are shown)
kubectl delete pods –all -n <name of namespace> – command that deletes all pods from given Namespace (without -n parameter pods are deleted from default Namespace)
kubectl get ns – command that shows all namespaces
All system pods are resided in kube-system Namespace.
There is a kube-public Namespace, it is created automatically and is readable by all users. This Namespace is used for resources that should be visible and readable publicly by the whole cluster.
By default Scheduler can choose any Node for creating and running a Pod. But sometimes it is mandatory to use specific Node for specific Pod.
service kubelet status – command for checking the state of kubelet service on the current Node
/var/lib/kubelet is the folder where kubelet information sits. /var/lib/kubelet/config.yaml is the file containing the configuration of kubernetes on the Node. Between others there is a StaticPodPath property, its value is the location of yaml files for static pods.
Static pods are defined using yaml files located in StaticPodPath on proper Node. kubectl get pods command shows static pods with the names followed by-<node name>. Static Pod is recreated every time it is deleted by kubectl, because Static Pod is created by kubelet, not kubectl. To delete Static Pod yaml file in StaticPodPath should be deleted. If respective Node fails, static pods from this Node won’t be available.
Master components (Api-Server, Scheduler, etcd, Controller Manager) are run in static pods.
InitContainer is a container that executes before starting the “main” container. When InitContainer executes, it dies.
watch kubectl get pods – command that shows execution of kubectl get pods interactively (every two seconds). watch is applicable to all commands.