Kubernetes Pod creation
There are two ways of creating a Kubernetes pod.
Kubernetes pod creation way 1
kubectl run nginx --image=nginx : creates a deployment nginx which creates a pod from the image nginx
Kubernetes pod creation way2 : using pod definition file
Kubernetes pod definition file
The kubernetes pod definition file is composed from 3 parts :
- apiVersion
- kind
- metadata
- spec
Example of kubernetes pod definition file
apiVersion: v1 kind: Pod metadata: name: nginx labels: name: nginx app: nginx-app spec: containers: - name: nginx image: nginx ports: - containerPort: 80
In the case of a pod, the kind section is always equal to Pod.
The labels part is used to distinguish the pods created by this definition file (it is used by replication set to monitor a subset of pods having a label)
The spec part contains the containers which will be created in the pod.
We notice that the containers section contains an array of objects : this means that we can run multiple containers in the same
pod.
Her ewe specified a unique container created using the nginx image and running on the port 80.
In order to create the pod, we run this command :
kubectl create pod -f pod-definition-file.yml
This command creates only a pod resource based on the pod definition file described above.
It doesn't create any resource other than the pod.
Displaying informations about kubernetes pods:
kubectl describe pod <pod_name> : checks informations about a pod (image name, node name, how many containers are running on the pod, get the state of the container in the pod, etc)
Container image name: we find it in the containers section of the out put of the describe command
Here we figure out that there is one container running in the pod and the corresponding image is the nginx image.
kubectl get pods -o wide : displays on which node each kubernetes pod is running
Here the pod is running on the node vps-a45eb589.
This kubernetes pod tutorial for beginners arrives at its end.
To check our others tutorials, you can like our how to program facebook page.
Post a Comment