Kubernetes - Pod

Intro to smallest deployable unit in Kubernetes

ta-ching chen

3 minute read

 Table of Contents


A Pod is a group of one or more containers and it is the smallest deployable unit in Kubernetes. Pod and VM (virtual machine) are similar in many ways:

  • Containers in pod share the same IP address and port space
  • Shared storage (volumes)
  • Relatively tightly coupled applications in one pod

Shared IP address and port space 

Kubernetes applies IP at Pod scope. Containers within a pod share an IP address and port space, and can find each other via localhost. Its just like what we do in VM: one prcoess find others with localhost:port.

Also pod can be accessed by other pod in Kubernetes cluster, it helps developer no need to worry about how to access other containers cross hosts. However, normally we don’t access other Pod directly but using service instead and we will discuss it in later article.

Shared storage (volumes) 

For example, emptyDir is one of volume types in Kubernetes, it share the lifetime with Pod which means that it exists as long as the Pod is running on that node. Containers in same pod share the emptyDir, its quite helpful when you want to access the same files across Pod. Imagine that there is a service running in Pod and you need a log parser to parse the service log in order to monitor service state, we can access the log files easily in different containers through mounting shared emptyDir volume.

Relatively tightly coupled applications 

Container often runs single application. But sometimes we also need a sidecar container to help the main container, for example we need a monitor container to monitor service container and sending alerts if something goes wrong. In a pre-container world, these tightly coupled applications would have run on the VM, and now they runs on different containers in the same Pod.

Service container and sidecar containers


Lets create a web server pod with two containers backend and frontend in it.

  • backend: prints current date to index.html(/tmp/index.html) located at the share volume every second.
  • frontend: runs a simple http server that display the index.html, which the directory is mount to /var/www, to user.
apiVersion: v1
kind: Pod
  name: example-pod
    service: example-pod
    - name: backend
      image: ubuntu
        - "bash"
        - "-c"
        - "while true; do date > /tmp/index.html ; sleep 1; done"
        - mountPath: /tmp # the mount point for volume
          name: content-volume # should match the volume name defined below
    - name: frontend
      image: trinitronx/python-simplehttpserver
        - "sh"
        - "-c"
        - "python -m SimpleHTTPServer 8080"
        - containerPort: 8080
      - mountPath: /var/www # we can define different mount point for different container
        name: content-volume
    - name: content-volume
      emptyDir: {}

Find the internal IP Address of pod in Kubernetes cluster

$ kubectl get pod -o wide
NAME                    READY     STATUS    RESTARTS   AGE       IP             NODE
example-pod             2/2       Running   0          4m

The address is only accessible in Kubernetes cluster, so we create another pod to perform curl command.

$ kubectl -n default run curl-test --image=radial/busyboxplus:curl -i --tty --rm

Now, you should be able to see the response from the web server pod.

[ root@curl-test-74cc7dc45f-4qjk4:/ ]$ curl
Mon Jun 25 05:51:54 UTC 2018

See Also

comments powered by Disqus