skip to Main Content

Below are the exact words of a question that came up in an online test.

Create an single container app running in a pod named "bla-bla" with
any 3 of the four images listed below. Images: nginx + redis+
memcached.

I’m not sure whether this is a wordplay or a typo but what I would like to know is whether there is any syntax for launching multiple images in a single container? I know this can be done by having multiple containers within a single pod but according to the wordings in the question, I don’t think that is what they expect. I saw this same exact question in Kubernetes official forum but no answer there too. Hence posting it here so it can reach a wider audience.

Forum Question: https://discuss.kubernetes.io/t/can-we-have-a-single-container-with-multiple-image-like-nginx-redis-alpine/12017

2

Answers


  1. If you are looking for a single command like "kubectl run bla-bla –image xyz" I dont think there is one.

    Easiest way imo is to do something like that.

    1. kubectl run bla-blah –image nginx –dry-run=client -o yaml > multi-container-pod.yaml.
    2. edit the yaml and run kubectl apply -f
    Login or Signup to reply.
  2. I don’t see the problem with the question. It asks to create a single "container app running in a pod", not a "single container".

    So single pod with multiple containers is the answer. Here is the example.

    apiVersion: v1
    kind: Pod
    metadata:
      name: two-containers
    spec:
    
      restartPolicy: Never
    
      volumes:
      - name: shared-data
        emptyDir: {}
    
      containers:
    
      - name: nginx-container
        image: nginx
        volumeMounts:
        - name: shared-data
          mountPath: /usr/share/nginx/html
    
      - name: debian-container
        image: debian
        volumeMounts:
        - name: shared-data
          mountPath: /pod-data
        command: ["/bin/sh"]
        args: ["-c", "echo Hello from the debian container > /pod-data/index.html"]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search