Kubernetes Pods








While we work with kubernetes, there are different things that we can create to manage our application. Various components come together and build up a Kubernetes ecosystem.

Lets discuss about these parts of kubernetes ecosystem




Pods


As of now we assume that an application is already developed in a containerized form and docker image is available in a docker registry(like docker hub) and also a kubernetes cluster has been setup.


With kubernetes our ultimate aim is to deploy the application in the form of containers on a set of nodes. However kubernetes do not deploy application directly in the form of containers but it does so in the form of pods which is the smallest object in kubernetes. We can say that a pod is a single instance of an application.


To scale up, we deploy more pods and to scale down we delete pods.




Usually its good to have one container per pod but its not mandatory, we can have multi container pods as well but these containers are usually not of the same type.The multiple containers may be dependent upon each other to provide overall functionality so they coexist together in a single pod.

The two containers can communicate with each other directly by referring each other as localhost since they share the same network and storage space.


Create a pod


Creating a pod is fairly easy and can be done by writing few lines in YAML format.

Here in this file, we need to define the pod specification, what container image to use etc.

After writing in a yaml file we can use kubectl commands to create a pod.


Any kubernetes object , be it a pod,replicas,controllers,deployments,services etc can be created by a definition file created in YAML. This yaml file surely consists of below four properties ( additional fields may be there depending upon the object) i.e. apiVersion, kind,metadata and spec.




Example

[root@node1 kubernetes]# cat nginx_pod.yaml
apiVersion: v1
kind: Pod
metadata:
   name: nginx-pod
   labels:
     app: myapp
spec:
   containers:
   - name: nginx-container
     image: nginx

[root@node1 kubernetes]# kubectl create -f nginx_pod.yaml
pod/nginx-pod created
[root@node1 kubernetes]# kubectl get pods
NAME        READY   STATUS              RESTARTS   AGE
nginx-pod   0/1     ContainerCreating   0          5s
[root@node1 kubernetes]# kubectl get pods
NAME        READY   STATUS    RESTARTS   AGE
nginx-pod   1/1     Running   0          12s






We have created our first pod. That is so cool right . In the future lectures, we will deep dive and learn about kubernetes in greater depth.









386 views0 comments

Recent Posts

See All