简体   繁体   English

Pod 内的 Kubernetes Docker 进程

[英]Kubernetes Docker process inside pod

I have a Docker image with the CMD to run a Java application.我有一个带有 CMD 的 Docker 映像来运行 Java 应用程序。

This application is being deployed to container into Kubernetes.此应用程序正在部署到 Kubernetes 的容器中。 Since, I am deploying it as a Docker image, I was expecting it as running as a Docker process.因为,我将它部署为 Docker 映像,所以我期望它像 Docker 进程一样运行。 So, I just logged into the pods and was trying " docker ps ".所以,我刚刚登录到 pod 并尝试使用“ docker ps ”。

But, I was surprised that it is running as a Java process and not as a docker process.但是,令我惊讶的是它作为 Java 进程而不是 docker 进程运行。 I am able to see the process by " ps -ef "我可以通过“ ps -ef ”看到这个过程

I am confused, how does it work internally?我很困惑,它如何在内部工作?

As others stated, Kubernetes uses docker internally to deploy the containers .正如其他人所说, Kubernetes 在内部使用 docker 来部署容器 To explain in detail consider the cluster which has 4 nodes, 1 master and 3 slaves.为了详细解释,请考虑具有 4 个节点、1 个主节点和 3 个从节点的集群。

$ 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 .我正在部署一个带有nignx docker image的 pod。

$ 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:您可以获取 pod 的状态,如下所示:

$ 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. Kube-scheduler将在可用节点之一上调度 pod。

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.现在 pod 已部署到服务器,您可以在其中登录该特定服务器并找到您要查找的信息。

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.在该服务器中运行docker exec命令以查看内部运行的进程。

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. https://kubernetes.io/docs/home/-这可以为您提供有关 pod 以及如何使用 pod/容器进行部署的更多信息。

Hope this helps.希望这可以帮助。

Kubernetes using the yaml file that the user provides, deploys a pod (smaller unit of Kubernetes deployment) with one or more containers in it. Kubernetes 使用用户提供的 yaml 文件部署一个 pod(Kubernetes 部署的较小单元),其中包含一个或多个容器。

You can access the containers inside the pod using the kubectl tool.您可以使用kubectl工具访问 pod 内的容器。 For example, in case your pod has one container you can open a shell inside it:例如,如果您的 pod 有一个容器,您可以在其中打开一个 shell:

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.通过这个 shell,你可以运行ps命令,你的输出将是在你的容器内运行的隔离进程。

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.如果您想观察 Kubernetes 部署在节点中的 Docker 容器,您可以连接到该节点并运行docker ps命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM