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