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 .. :)
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
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)"
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"}]}}}}'