<blockquote>
<p>I have two containers, worker and dispatcher. I want to be able to
deploy N copies of worker and 1 copy of dispatcher to the cluster. Is
there a deployment that will make this work?</p>
</blockquote>
<p>Both a Deployment or Statefulset will work.</p>
<blockquote>
<p>dispatcher needs to be able to know about and talk to all of the
worker instances (worker is running a web server).</p>
</blockquote>
<p>This has to do with <a href="https://kubernetes.io/docs/concepts/extend-kubernetes/compute-storage-net/network-plugins/" rel="nofollow noreferrer">Kubernetes Networking plugins</a> and will depend on which plugin your cluster was configured with. Most clusters I have used by default allow traffic across the entire cluster.</p>
<blockquote>
<p>However, the
external world only needs to talk to dispatcher.</p>
</blockquote>
<p>The main ways to do this would be a Service or an Ingress both are explained <a href="https://kubernetes.io/docs/concepts/services-networking/" rel="nofollow noreferrer">here</a>.</p>
<blockquote>
<p>I'd like to be able to scale N up and down based on demand.</p>
</blockquote>
<p><a href="https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/" rel="nofollow noreferrer">https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/</a></p>
<blockquote>
<p>Should I be using a Deployment or a StatefulSet? or something else?</p>
</blockquote>
<p>Does your container have state? If so then use a stateful set. The Kubernetes page explains why to use a statefulset <a href="https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/</a></p>
<blockquote>
<p>Do I actually need multiple deployments? Can containers from multiple
deployments talk to each other?</p>
</blockquote>
<p>These things are not really related. You would use multiple deployments so you can configure multiple workloads differently.</p>

CC BY-SA 4.0
2022-07-20T01:31:01.170Z
2022-07-20T06:33:01.633Z
2022-07-20T06:33:01.633Z
Levi
<p>I have two containers, <code>worker</code> and <code>dispatcher</code>.
I want to be able to deploy N copies of <code>worker</code> and 1 copy of <code>dispatcher</code> to the cluster.
Is there a deployment that will make this work?</p>
<p><code>dispatcher</code> needs to be able to know about and talk to all of the <code>worker</code> instances (<code>worker</code> is running a web server). However, the external world only needs to talk to <code>dispatcher</code>.</p>
<p>As a stretch goal, I'd like to be able to scale N up and down based on demand.</p>
<p>Questions:</p>
<ol>
<li>Should I be using a Deployment or a StatefulSet? or something else?</li>
<li>Do I actually need multiple deployments? Can containers from multiple deployments talk to each other?</li>
<li>How do I dynamically scale this?</li>
</ol>
<p>It seems like I can get partway there with a single Deployment:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp
spec:
  replicas: 3
  selector:
    matchLabels:
      deploy: myapp
  template:
    metadata:
      labels:
        deploy: myapp
    spec:
      containers:
        - name: worker
          image: localhost/worker:latest
</code></pre>
<p>I expect this will give me 3 workers, but 0 dispatchers. However, if I add <code>dispatcher</code> to the <code>containers</code> list, I would expect to get 3 of those too, which is not what I want.</p>

<kubernetes>
Kubernetes deployment with multiple containers
fr0
# Kubernetes deployment with multiple containers

(Asked by: username_0 on 2022-07-19)

I have two containers, worker and dispatcher.
I want to be able to deploy N copies of worker and 1 copy of dispatcher to the cluster.
Is there a deployment that will make this work?
dispatcher needs to be able to know about and talk to all of the worker instances (worker is running a web server). However, the external world only needs to talk to dispatcher.
As a stretch goal, I'd like to be able to scale N up and down based on demand.
Questions:

Should I be using a Deployment or a StatefulSet? or something else?
Do I actually need multiple deployments? Can containers from multiple deployments talk to each other?
How do I dynamically scale this?

It seems like I can get partway there with a single Deployment:
apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp
spec:
  replicas: 3
  selector:
    matchLabels:
      deploy: myapp
  template:
    metadata:
      labels:
        deploy: myapp
    spec:
      containers:
        - name: worker
          image: localhost/worker:latest

I expect this will give me 3 workers, but 0 dispatchers. However, if I add dispatcher to the containers list, I would expect to get 3 of those too, which is not what I want.

**Tags:** kubernetes


---

## 1 answers

### Answer by username_1 on 2022-07-20. Score: 2 | Accepted answer

> I have two containers, worker and dispatcher. I want to be able to
> deploy N copies of worker and 1 copy of dispatcher to the cluster. Is
> there a deployment that will make this work?

Both a Deployment or Statefulset will work.

> dispatcher needs to be able to know about and talk to all of the
> worker instances (worker is running a web server).

This has to do with [Kubernetes Networking plugins](https://kubernetes.io/docs/concepts/extend-kubernetes/compute-storage-net/network-plugins/) and will depend on which plugin your cluster was configured with. Most clusters I have used by default allow traffic across the entire cluster.

> However, the
> external world only needs to talk to dispatcher.

The main ways to do this would be a Service or an Ingress both are explained [here](https://kubernetes.io/docs/concepts/services-networking/).

> I'd like to be able to scale N up and down based on demand.

<https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/>

> Should I be using a Deployment or a StatefulSet? or something else?

Does your container have state? If so then use a stateful set. The Kubernetes page explains why to use a statefulset <https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/>

> Do I actually need multiple deployments? Can containers from multiple
> deployments talk to each other?

These things are not really related. You would use multiple deployments so you can configure multiple workloads differently.


---

