How to create a pod in Kubernetes.

How to create a pod in Kubernetes.


Pods:

Pods are the smallest deployable units of computing that you can create and manage in Kubernetes.

A Pod (as in a pod of whales or pea pod) is a group of one or more containers, with shared storage and network resources, and a specification for how to run the containers. A Pod's contents are always co-located and co-scheduled, and run in a shared context. A Pod models an application-specific "logical host": it contains one or more application containers which are relatively tightly coupled. In non-cloud contexts, applications executed on the same physical or virtual machine are analogous to cloud applications executed on the same logical host.

What is a Pod?

The shared context of a Pod is a set of Linux namespaces, cgroups, and potentially other facets of isolation - the same things that isolate a container. Within a Pod's context, the individual applications may have further sub-isolations applied.

A Pod is similar to a set of containers with shared namespaces and shared filesystem volumes.

Creating a pod using yaml file:

The following is an example of a Pod which consists of a container running the image: docker.io/httpd and save this yaml code in a file.

apiVersion: v1
kind: Pod
metadata:
  name: mypod #name of the pod
  labels:
     class: cka #labels 
spec:
  containers:
  - name: httpd #name of the conatiner
    image: docker.io/httpd #container image
    ports:
    - containerPort: 80
  • To run this yaml file use command:
  kubectl create -f (filename)
  • To check if the pods are in a running state or have some issue
kubectl get pods
  • To go inside the pod and use terminal
kubectl exec -it (podname) bash
  • To delete a pod
kubectl delete pod (podname)