Hi, I would like to create a Kubernetes Pod which ...
# ask-community
d
Hi, I would like to create a Kubernetes Pod which contains multiple containers. Can I use the execute_k8s_job function to do so? The
image
parameter is not optional, so this leads me to believe that the Pod will only have one container based on that image but then I also see that I can specify
pod_spec_config
which tells me that I can define a Pod with multiple containers, like:
Copy code
apiVersion: batch/v1
kind: Job
metadata:
  name: hello
spec:
  template:
    # This is the pod template
    spec:
      containers:
      - name: hello
        image: busybox:1.28
        command: ['sh', '-c', 'echo "Hello, Kubernetes!" && sleep 3600']
      restartPolicy: OnFailure
    - name: world
    .....
    # The pod template ends here
but then I'm not sure where the
image
parameter fits in, since each container has its image specified in the Pod Specification. So which is the case? Are there any examples on this?
d
Hey Daniel - it's a bit confusing but 'image' will control the image for the 'main' container, and pod_spec_config.containers will let you specify additional sidecar containers
d
I see! So if I want to deploy 3 containers, I can specify 1 in the "image" field and the other 2 in the Pod Specification container, right?
d
That’s right - although k8s sidecars can be a bit frustrating since k8s doesn’t actually have the concept of a “main” container - so they all need to be shut down somehow before it thinks the pod has completed
d
okay, got it! I'll try this out 🙂 Thanks!