当前位置:   article > 正文

k8s-一个pod中有多个容器_k8s pod 多个container

k8s pod 多个container

k8s - 一个 pod 中有多个 容器

在一个pod中创建多个容器

[root@k8s-master pod]# cat multi_pod.yaml 
apiVersion: v1
kind: Pod
metadata:
  name: multi-pod
  labels:
    app: multi-pod
spec:
  containers:
    - name: nginx
      image: nginx:latest
      imagePullPolicy: IfNotPresent
      ports:
        - containerPort: 80
          hostPort: 80
    - name: redis
      image: redis:latest
      imagePullPolicy: IfNotPresent
      ports:
        - containerPort: 6379
          hostPort: 6379
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

启动:

kubectl apply -f multi_pod.yaml
  • 1

查看

[root@k8s-master pod]# kubectl get pod -o wide
NAME        READY   STATUS    RESTARTS   AGE     IP            NODE        NOMINATED NODE   READINESS GATES
multi-pod   2/2     Running   0          5m48s   10.244.1.21   k8s-node1   <none>           <none>
  • 1
  • 2
  • 3

到 k8s-node1 节点上查看容器:

[root@k8s-node1 ~]# docker ps|grep multi
7cb321a927ca        7614ae9453d1           "docker-entrypoint.s…"      k8s_redis_multi-pod_default_cc4adb3b-7103-4ac6-981f-94d6b2ea9b20_0
4e568d0580d6        f6987c8d6ed5           "/docker-entrypoint.…"      k8s_nginx_multi-pod_default_cc4adb3b-7103-4ac6-981f-94d6b2ea9b20_0
940398a790b5        k8s.gcr.io/pause:3.5   "/pause"                    k8s_POD_multi-pod_default_cc4adb3b-7103-4ac6-981f-94d6b2ea9b20_0
  • 1
  • 2
  • 3
  • 4

进入pod中一个container

# kubectl exec -it pod_name -c pod_container_name -- bash
[root@k8s-master pod]# kubectl exec -it multi-pod -c redis -- bash
  • 1
  • 2
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/162195
推荐阅读
相关标签
  

闽ICP备14008679号