<p>I want to link services to specific pod by using <code>StatefulSets</code> in Kubernetes as below.</p>
<ul>
<li><code>service_1</code> links to <code>web-0</code>, <code>web-1</code> pod</li>
<li><code>service_2</code> links to <code>web-2</code>, <code>web-3</code> pod</li>
</ul>
<p>I know there is a label to select specific pod</p>
<p>&quot;statefulset.kubernetes.io/pod-name: web-01&quot;</p>
<p>but this label seems only select one pod. Is there a way to select multiple pod?</p>

user2286858
<p>If you need to point services into a portion of pods in a StatefulSet, the best practice is to create multiple StatefulSets, or use <a href="https://cloud.redhat.com/blog/simple-canary-deployments-using-kubernetes-statefulsets-on-openshift" rel="nofollow noreferrer">Canary Deployments with StatefulSets</a></p>
<p>If you need to know <strong>how to point a service into a StatefulSet</strong>, there is three options:</p>
<ol>
<li><p><a href="https://kubernetes.io/docs/tutorials/stateful-application/basic-stateful-set/#creating-a-statefulset" rel="nofollow noreferrer">Create a headless service for the StatefulSet</a>.</p>
</li>
<li><p>Use the service name as the hostname in the StatefulSet pod specification.</p>
</li>
</ol>
<pre><code>apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: my-statefulset
spec:
  serviceName: my-statefulset
  replicas: 3
  selector:
    matchLabels:
      app: my-statefulset
  template:
    metadata:
      labels:
        app: my-statefulset
    spec:
      hostname: my-statefulset
      subdomain: my-namespace.svc.cluster.local
      containers:
      - name: my-container
        image: my-image
        command: [&quot;/bin/sh&quot;]
        args: [&quot;-c&quot;, &quot;while true; do sleep 3600; done&quot;]
</code></pre>
<ol start="3">
<li>Use environment variables or DNS resolution to connect to the service from within the pod.</li>
</ol>
<hr />
<p>To point a service to multiple pod names, there is no possible way,
According to <a href="https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#label-selectors" rel="nofollow noreferrer">documentation</a>:</p>
<blockquote>
<p>Caution: For both equality-based and set-based conditions there is no
logical OR (||) operator. Ensure your filter statements are structured
accordingly</p>
</blockquote>
