<p>I currently trying to create a cluster of X pods witch each have a personal persistent volume. To do that I've created a <code>StateFulSet</code> with X replicas and a <code>PersistentVolumeClaimTemplate</code> This part is working.</p>

<p>The problem is that it's seem's to be impossible to expose thoses pods with a LoadBalancer in the same way as a <code>deployment</code> (because of the uniqueness of a pods in a statefulset).</p>

<p>At this moment I've tried to expose it as a simple deployment witch is not working and the only way I've found is to expose each pods one by one (I've not tested it but I saw it on <a href="https://github.com/kow3ns/kubernetes-kafka/issues/3#issuecomment-358646027" rel="noreferrer">this</a>) but it's not that scalable...</p>

<p>I'm not running kubernetes on any cloud provider platform then please avoid exclusive command line.</p>

yatsukino
<blockquote>
  <p>The problem is that it's seem's to be impossible to expose thoses pods with a LoadBalancer in the same way as a deployment (because of the uniqueness of a pods in a statefulset).</p>
</blockquote>

<p>Why not? Here is my StatefulSet with default Nginx</p>

<pre><code>$ k -n test get statefulset
NAME      DESIRED   CURRENT   AGE
web       2         2         5d
$ k -n test get pods
web-0                    1/1       Running   0          5d
web-1                    1/1       Running   0          5d
</code></pre>

<p>Here is my Service type LoadBalancer which is NodePort (in fact) in case of Minikube</p>

<pre><code>$ k -n test get svc
NAME      TYPE           CLUSTER-IP     EXTERNAL-IP   PORT(S)        AGE
nginx     LoadBalancer   10.110.22.74   &lt;pending&gt;     80:32710/TCP   5d
</code></pre>

<p>Let's run some pod with curl and do some requests to ClusterIP:</p>

<pre><code>$ kubectl -n test run -i --tty tools --image=ellerbrock/alpine-bash-curl-ssl -- bash
bash-4.4$ curl 10.110.22.74 &amp;&gt; /dev/null
bash-4.4$ curl 10.110.22.74 &amp;&gt; /dev/null
bash-4.4$ curl 10.110.22.74 &amp;&gt; /dev/null
bash-4.4$ curl 10.110.22.74 &amp;&gt; /dev/null
</code></pre>

<p>Let's check out Nginx logs:</p>

<pre><code>$ k -n test logs web-0
172.17.0.7 - - [18/Apr/2019:23:35:04 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.61.0"
172.17.0.7 - - [18/Apr/2019:23:35:05 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.61.0"
172.17.0.7 - - [18/Apr/2019:23:35:17 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.61.0"
$ k -n test logs web-1
172.17.0.7 - - [18/Apr/2019:23:35:15 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.61.0"
</code></pre>

<p>172.17.0.7 - is my pod with curl:</p>

<pre><code>NAME                     READY     STATUS    RESTARTS   AGE       IP           NODE
tools-654cfc5cdc-8zttt   1/1       Running   1          5d        172.17.0.7   minikube
</code></pre>

<p>Actually ClusterIP is totally enough in case of load balancing between StatefulSet's pods, because you have a list of Endpoints</p>

<pre><code>$ k -n test get endpoints
NAME      ENDPOINTS                     AGE
nginx     172.17.0.5:80,172.17.0.6:80   5d
</code></pre>

<p>YAMLs:</p>

<pre><code>apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
  name: web
spec:
  serviceName: "nginx"
  replicas: 2
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: k8s.gcr.io/nginx-slim:0.8
        ports:
        - containerPort: 80
          name: web
</code></pre>

<hr>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: nginx
  labels:
    app: nginx
spec:
  type: LoadBalancer
  ports:
  - port: 80
    name: web
  selector:
    app: nginx
</code></pre>
