Hello, how do you add multiple images (nginx + redis) in one container?

Pradeep Mahapatra:
Hello, how do you add multiple images (nginx + redis) in one container?

Jesus Arechiga Jimenez:
One container = one image

What you may be looking for is to add two containers into one pod.

Mohamed Ayman:
Check this:
https://discuss.kubernetes.io/t/can-we-have-a-single-container-with-multiple-image-like-nginx-redis-alpine/12017

Mohamed Ayman:
I think the question means multi-containers POD

Pradeep Mahapatra:
I am able to create multiple containers in a single pod - which can say use C1 for nginx, C2 for redis

Pradeep Mahapatra:
It seems we can do it from docker natively — trying to find how to do this via a single yaml file in K8

Jesus Arechiga Jimenez:
You can have multiple processes inside a container but it wouldn’t really be a best practice.

Pradeep Mahapatra:
I understand that aspect, was try to see if I could have an “All in one container” where my frontend+app _server+DB are going to run.

Pradeep Mahapatra:
It seems the patch command is the way to go… just trying out

Jesus Arechiga Jimenez:
You could, but I don’t understand why. Doing it that way goes against the micro services design principles.

Harindha Fernando:
with patch we can’t add extra containers to same pod but we can do it for deployments…

Harindha Fernando:

 > k run multi-pod --image nginx:1.19-alpine --port 80 --dry-run=client -o yaml 
apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    run: multi-pod
  name: multi-pod
spec:
  containers:
  - image: nginx:1.19-alpine
    name: multi-pod
    ports:
    - containerPort: 80
    resources: {}
  dnsPolicy: ClusterFirst
  restartPolicy: Always
status: {}

> k get pods multi-pod -o jsonpath='{.spec.containers[*].image}{"\n"}'
nginx:1.19-alpine

> k patch pod multi-pod -p '{"spec":{"containers":[{"name":"c2","image":"redis"}]}}'
The Pod "multi-pod" is invalid: spec.containers: Forbidden: pod updates may not add or remove containers
> k patch pod multi-pod -p '{"spec":{"containers":[{"name":"multi-pod","image":"nginx:latest"}]}}'
pod/multi-pod patched
> k get pods multi-pod -o jsonpath='{.spec.containers[*].image}{"\n"}'
nginx:latest

Harindha Fernando:

For Deployment

> k create deploy multi-cont-deploy --image nginx --port 80 --replicas 1 --dry-run=client -o yaml 
apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    app: multi-cont-deploy
  name: multi-cont-deploy
spec:
  replicas: 1
  selector:
    matchLabels:
      app: multi-cont-deploy
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: multi-cont-deploy
    spec:
      containers:
      - image: nginx
        name: nginx
        ports:
        - containerPort: 80
        resources: {}
status: {}

> k get deploy multi-cont-deploy -o jsonpath='{.spec.template.spec.containers[*].image}{"\n"}'
nginx

cat patch-file.yaml 
spec:
  template:
    spec:
      containers:
      - name: patch-demo-ctr-2
        image: redis
        ports:
        - containerPort: 6379
      - name: patch-demo-ctr-3
        image: busybox:1.28
        command:
        - sleep
        - "4800" 

> k patch deploy multi-cont-deploy --patch "$(cat patch-file.yaml)"
deployment.apps/multi-cont-deploy patched
> k get deploy multi-cont-deploy -o jsonpath='{.spec.template.spec.containers[*].image}{"\n"}'
redis busybox:1.28 nginx