How to create multi container pod from without yaml config of pod or deployment

9/26/2019

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 .. :)

-- Chetanya Chopra
kubectl
kubernetes
kubernetes-container
kubernetes-pod

3 Answers

9/26/2019

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
Source: StackOverflow

9/27/2019

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
Source: StackOverflow

9/26/2019

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
Source: StackOverflow