3

Trying to figure out how do I create multicontainer pod from terminal with kubectl without yaml config of any resource tried kubectl run --image=redis --image=nginx but second --image just overrides the first one .. :)

3 Answers3

2

You can't do this in a single kubectl command, but you could do it in two: using a kubectl run command followed by a kubectl patch command:

kubectl run mypod --image redis && kubectl patch deploy mypod --patch '{"spec": {"template": {"spec": {"containers": [{"name": "patch-demo", "image": "nginx"}]}}}}'
erstaples
  • 1,986
  • 16
  • 31
0

kubectl run is for running 1 or more instances of a container image on your cluster

see https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands

Go with yaml config file

Noman Khan
  • 920
  • 5
  • 12
0

follow the below steps

create 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)"
P Ekambaram
  • 15,499
  • 7
  • 34
  • 59