<p>given a database that is part of a statefulset and behind a headless service, how can I use a local client (outside of the cluster) to access the database? Is it possible to create a separate service that targets a specific pod by its stable id?</p>

<p>There are multiple ways you can conect to this database service</p>
<p>You can use</p>
<p>Port-forward : <a href="https://kubernetes.io/docs/tasks/access-application-cluster/port-forward-access-application-cluster/" rel="nofollow noreferrer">https://kubernetes.io/docs/tasks/access-application-cluster/port-forward-access-application-cluster/</a></p>
<p>Service as LoadBalancer : <a href="https://kubernetes.io/docs/concepts/services-networking/service/#loadbalancer" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/services-networking/service/#loadbalancer</a></p>
<p>Service as Nodeport : <a href="https://kubernetes.io/docs/concepts/services-networking/service/#nodeport" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/services-networking/service/#nodeport</a></p>
<p>Example MySQL database running on K8s : <a href="https://kubernetes.io/docs/tasks/run-application/run-single-instance-stateful-application/" rel="nofollow noreferrer">https://kubernetes.io/docs/tasks/run-application/run-single-instance-stateful-application/</a></p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: mysql
spec:
  ports:
  - port: 3306
  selector:
    app: mysql
  clusterIP: None
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mysql
spec:
  selector:
    matchLabels:
      app: mysql
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: mysql
    spec:
      containers:
      - image: mysql:5.6
        name: mysql
        env:
          # Use secret in real usage
        - name: MYSQL_ROOT_PASSWORD
          value: password
        ports:
        - containerPort: 3306
          name: mysql
        volumeMounts:
        - name: mysql-persistent-storage
          mountPath: /var/lib/mysql
      volumes:
      - name: mysql-persistent-storage
        persistentVolumeClaim:
          claimName: mysql-pv-claim
</code></pre>
<p>The easiest way is to try with <code>port-forwarding</code> :</p>
<pre><code>kubectl port-forward -n &lt;NAMESPACE Name&gt; &lt;POD name&gt; 3306:3306
</code></pre>
<p>using the above command you can create the proxy from local to K8s cluster and test the <code>localhost:3306</code></p>
<p>This is not a method for <strong>Prod</strong> use case it's can be used for <strong>debugging</strong>.</p>
<p>NodePort : Expose the port but use the worker node IPs so if worker not get killed during autoscaling IP may changed with time</p>
<p>I would recommend creating a new service with the respective <strong>label</strong> and type as <code>LoadBalancer</code>.</p>
