Kubernetes docker process inside pod

6/27/2018

I have a docker image with the CMD to run a java application.

This application is being deployed to container into kubernetes. Since, I am deploying it as a docker image, I was expecting it as running as a docker process. So, I just logged into the pods and was trying "docker ps".

But, I was surprised that it is running as a Java process and not as a docker process. I am able to see the process by "ps -ef"

I am confused, How it works internally? Not sure where to get more details on this. Any link or theory behind this pls ...

Thanks

-- user1578872
docker
kubernetes

1 Answer

6/27/2018

As others stated, Kubernetes uses docker internally to deploy the containers. To explain in detail consider the cluster which has 4 nodes, 1 master and 3 slaves.

$ kubectl get nodes
NAME                           STATUS    ROLES     AGE       VERSION
******.mylabserver.com   Ready     master    13d       v1.10.5
******.mylabserver.com   Ready     <none>    13d       v1.10.5
******.mylabserver.com   Ready     <none>    13d       v1.10.5
******.mylabserver.com   Ready     <none>    13d       v1.10.5

I am deploying a pod with nignx docker image.

$ cat pod-nginx.yml 
apiVersion: v1
kind: Pod
metadata:
  name: alpine
  namespace: default
spec:
  containers:
  - name: alpine
    image: alpine
    command:
      - sleep
      - "3600"
    imagePullPolicy: IfNotPresent
  restartPolicy: Always

You can get the status of the pod as below:

$ kubectl get pods -o wide
NAME      READY     STATUS    RESTARTS   AGE       IP           NODE
alpine    1/1       Running   0          21s       10.244.3.4   ******.mylabserver.com

Kube-scheduler will schedule the pod on one of the available nodes.

Now the pod is deployed to a server, where you can login to that particular server and find the information that you are looking for.

root@******:/home/user# docker ps
CONTAINER ID        IMAGE                                                                            COMMAND                  CREATED              STATUS         
     PORTS               NAMES
6486de4410ad        alpine@sha256:e1871801d30885a610511c867de0d6baca7ed4e6a2573d506bbec7fd3b03873f   "sleep 3600"             58 seconds ago       Up 57 seconds  
                         k8s_alpine_alpine_default_2e2b3016-79c8-11e8-aaab-

Run the docker exec command in that server to see the process running inside.

root@******:/home/user# docker exec -it 6486de4410ad /bin/sh
/ # ps -eaf
PID   USER     TIME   COMMAND
    1 root       0:00 sleep 3600
    7 root       0:00 /bin/sh
   11 root       0:00 ps -eaf
/ # 

https://kubernetes.io/docs/home/- this can give you more info about pods and how deployments happen with pods/containers.

Hope this helps.

-- Here_2_learn
Source: StackOverflow