Secret IT Engineer

Blogs you've never heard of

About Kubernetes Pods

Pods are the smallest workload construct which can be managed with Kubernetes.  Pods house containers, Kubernetes does not manage containers itself, just Pods, which are deployed onto worker nodes.

If an application container is deployed into a Pod, and then it becomes oversubscribed, we do not increase the number of those application containers within the same Pod, we instantiate another Pod with another deployment of that application.  Either on the same NODE, or a different NODE.

Typically, Apps / Pods have a 1:1 relationship.

To display a list of pods, use the command:

kubectl get pods

To get detailed information about pods, use the  command.

kubectl descripe pod myapp-pod

A single Pod CAN house multiple containers, just usually not multiple containers of the same application.  Typically they are helper containers located within the same Pod.  This helps to maintain the application ecosystem, if another application is deployed then the worker container is deployed/destroyed also.

Use the command  to deploy a simple Pod, this will download the nginx docker container from the publc docker hub location (or another location depending on config).  This is known as an imperative command:

kubectl run nginx –image nginx

The ‘kubectl get pods’ command will display all Pods and their status:

ubuntu@kube1:~$ kubectl get pods

NAME READY STATUS RESTARTS AGE

command-demo 0/1 Completed 0 36h

nginx 1/1 Running 0 11m

Using YAML to create description files for Pods

Pods can be created using a YAML file.  The pod descriptor YAML file must always contain 4 pieces of information

  1. apiVersion:
  2. kind:
  3. metadata:
  4. spec:

apiVersion: is the version of the Kubernetes API version of the object we are trying to create

kind: this is the type of object we are trying to create

*Possible combinations are in the table below:

kind: apiVersion:
Pod v1
Service v1
ReplicaSet apps/v1
Deployment apps/v1

metadata: is information about the object.  Such as Labels and name etc.   Under the metadata key-pair values (dictionary) include (note the indents / siblings):

metadata:

name: MyPOD

labels:

app: MyPod

In the above example, name: is a string value, labels: is an embedded dictionary where more labels can be added.

spec: is additional information for kubernetes.

In its simplest form, spec is a list/array of information about the pod.

spec:

containers:

– name: nginx-container

image: nginx

The containers node is a list, so the – before the name of the container is important.

A complete example can be seen below:

apiVersion:v1

kind:Pod

metadata:

name: myapp-pod

labels:

app: myapp

spec:

containers:

– name: nginx-container

image: nginx

Once the above file has been saved, we could create the pod using the command:

kubectl create -f pod-definition.yaml


Published by

Leave a comment