user1578872
user1578872

Reputation: 9088

Kubernetes Docker process inside pod

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 does it work internally?

Upvotes: 2

Views: 28770

Answers (2)

iwita
iwita

Reputation: 91

Kubernetes using the yaml file that the user provides, deploys a pod (smaller unit of Kubernetes deployment) with one or more containers in it.

You can access the containers inside the pod using the kubectl tool. For example, in case your pod has one container you can open a shell inside it:

kubectl exec -ti <pod-name> -n <pod-namespace> bash

Through this shell, you can run ps commands and your output will be the isolated processes running inside your container.

In case you want to observe the Docker containers which Kubernetes has deployed in a node, you can connect to that node and run docker ps commands.

Upvotes: 1

Here_2_learn
Here_2_learn

Reputation: 5451

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.

Upvotes: 8

Related Questions