如何从没有Pod或部署的Yaml配置的情况下创建多容器Pod

时间:2019-09-26 16:57:57

标签: kubernetes kubectl kubernetes-pod kubernetes-container

试图弄清楚如何在没有任何资源的yaml配置的情况下使用kubectl从终端创建多容器容器 尝试过kubectl run --image=redis --image=nginx,但第二个--image只是覆盖了第一个..:)

3 个答案:

答案 0 :(得分:1)

您无法在单个kubectl命令中执行此操作,但是可以在两个命令中执行:使用kubectl run命令后跟kubectl patch命令:

kubectl run mypod --image redis && kubectl patch deploy mypod --patch '{"spec": {"template": {"spec": {"containers": [{"name": "patch-demo", "image": "nginx"}]}}}}'

答案 1 :(得分:0)

kubectl运行用于在群集上运行1个或多个 a 容器映像的实例

请参阅https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands

使用Yaml配置文件

答案 2 :(得分:0)

按照以下步骤

创建patch-demo.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: patch-demo
spec:
  replicas: 2
  selector:
    matchLabels:
      app: myapp
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
      - name: nginx
        image: nginx
----

deploy patch-demo.yaml

create patch-containers.yaml as below
---
spec:
  template:
    spec:
      containers:
      - name: redis
        image: redis
---
patch the above yaml to include redis container

kubectl patch deployment patch-demo --patch "$(cat patch-containers.yaml)"