<p>I'm trying to setup Redis cluster in Kubernetes. The major requirement is that all of nodes from Redis cluster have to be available from outside of Kubernetes. So clients can connect every node directly. But I got no idea how to configure service that way. </p>

<p>Basic config of cluster right now. It's ok for services into k8s but no full access from outside.</p>

<pre><code>    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: redis-cluster
      labels:
        app: redis-cluster
    data:
      redis.conf: |+
        cluster-enabled yes
        cluster-require-full-coverage no
        cluster-node-timeout 15000
        cluster-config-file /data/nodes.conf
        cluster-migration-barrier 1
        appendonly no
        protected-mode no
    ---
    apiVersion: v1
    kind: Service
    metadata:
      annotations:
        service.alpha.kubernetes.io/tolerate-unready-endpoints: "false"
      name: redis-cluster
      labels:
        app: redis-cluster
    spec:
      type: NodePort
      ports:
      - port: 6379
        targetPort: 6379
        name: client
      - port: 16379
        targetPort: 16379
        name: gossip
      selector:
        app: redis-cluster
    ---
    apiVersion: apps/v1beta1
    kind: StatefulSet
    metadata:
      name: redis-cluster
      labels:
        app: redis-cluster
    spec:
      serviceName: redis-cluster
      replicas: 6
      template:
        metadata:
          labels:
            app: redis-cluster
        spec:
          hostNetwork: true
          containers:
          - name: redis-cluster
            image: redis:4.0.10
            ports:
            - containerPort: 6379
              name: client
            - containerPort: 16379
              name: gossip
            command: ["redis-server"]
            args: ["/conf/redis.conf"]
            readinessProbe:
              exec:
                command:
                - sh
                - -c
                - "redis-cli -h $(hostname) ping"
              initialDelaySeconds: 15
              timeoutSeconds: 5
            livenessProbe:
              exec:
                command:
                - sh
                - -c
                - "redis-cli -h $(hostname) ping"
              initialDelaySeconds: 20
              periodSeconds: 3
            volumeMounts:
            - name: conf
              mountPath: /conf
              readOnly: false
          volumes:
          - name: conf
            configMap:
              name: redis-cluster
              items: 
              - key: redis.conf
                path: redis.conf
</code></pre>

Shtlzut
<p>Given:</p>

<pre><code>    spec:
      hostNetwork: true
      containers:
      - name: redis-cluster
        ports:
        - containerPort: 6379
          name: client 
</code></pre>

<p>It appears that your <code>StatefulSet</code> is misconfigured, since if <code>hostNetwork</code> is <code>true</code>, you have to provide <code>hostPort</code>, and that value should match <code>containerPort</code>, according to the PodSpec docs:</p>

<blockquote>
  <p><code>hostPort integer</code> - Number of port to expose on the host. If specified, this must be a valid port number, 0 &lt; x &lt; 65536. If HostNetwork is specified, this must match ContainerPort.</p>
</blockquote>

<p><a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.11/#containerport-v1-core" rel="nofollow noreferrer">https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.11/#containerport-v1-core</a></p>
