<p>I have a Kubernetes scenario where I will need to deploy 3 Redis servers (pods), and each needs to be exposed with a ClusterIP service. Something like;</p>

<ul>
<li>RedisClusterIP1 -> RedisPod1 </li>
<li>RedisClusterIP2 -> RedisPod2</li>
<li>RedisClusterIP3 -> RedisPod3</li>
</ul>

<p>I have deployment plan like below, but as you can see it is creating ClusterIP service manually, and binds single of them to all pods.</p>

<p>Is there any way to set a deployment plan, there it will create same amount of services with Pods?</p>

<p>I checked <a href="https://kubernetes.io/docs/concepts/workloads/controllers/deployment/" rel="nofollow noreferrer">deployments</a> and <a href="https://kubernetes.io/docs/concepts/workloads/controllers/replicaset/" rel="nofollow noreferrer">replica sets</a> but could not figure out if there is something already exists.</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: redisharedis
spec:
  replicas: 3
  template:
    metadata:
      labels:
        app: redisharedis
    spec:
      containers:
        - name: redisharedis
          image: aozdemir/redisharedis:v6
          resources:
            limits:
              cpu: "1"
              memory: "800Mi"
            requests:
              cpu: "0.1"
              memory: "200Mi"
          ports:
            - containerPort: 6379


---
apiVersion: v1
kind: Service
metadata:
  name: redisharedis-service
  labels:
    name: redisharedis-service
spec:
  ports:
    - port: 6379
      targetPort: 6379
      protocol: TCP
  selector:
    app: redisharedis
  type: ClusterIP
</code></pre>

Teoman shipahi
<p>This can be done If you're deploying your redis cluster as <code>Statefulset</code> rather than <code>deployment</code>. In Kubernetes 1.9+, StatefulSet automatically adds the Pod name as a label on each of its Pods, so you can enable Service-Per-Pod like this:</p>

<pre><code>apiVersion: apps/v1beta2
kind: StatefulSet
metadata:
  annotations:
    service-per-pod-label: "statefulset.kubernetes.io/pod-name"
    service-per-pod-ports: "80:8080"
</code></pre>

<p>You need to install <code>MetaController</code> in your kubernetes cluster to install one service per pod. Please refer following link for detailed instructions:</p>

<blockquote>
  <p><a href="https://github.com/GoogleCloudPlatform/metacontroller/tree/master/examples/service-per-pod" rel="noreferrer">https://github.com/GoogleCloudPlatform/metacontroller/tree/master/examples/service-per-pod</a></p>
</blockquote>
