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 .. :)
Asked
Active
Viewed 3,440 times
3

Chetanya Chopra
- 87
- 2
- 7
3 Answers
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
-
exactly what searching for ... Cheers @ericstaples – Chetanya Chopra Oct 09 '19 at 18:12
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
-
got it right but I was trying to create the resource from kubectl without yaml config files @p-ekambaram – Chetanya Chopra Oct 17 '19 at 09:41