k8s:Two images but single container [duplicate]

被刻印的时光 ゝ 提交于 2021-02-11 14:33:03

问题


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


回答1:


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"]



回答2:


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


来源:https://stackoverflow.com/questions/65666271/k8stwo-images-but-single-container

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!