<p>I'm new to k8s and I'm trying to build a distributed system. The idea is that a stateful pod will be spawened for each user.</p>
<p>Main services are two Python applications <code>MothershipService</code> and <code>Ship</code>. MothershipService's purpose is to keep track of ship-per-user, do health checks, etc. <code>Ship</code> is running some (untrusted) user code.</p>
<pre><code>MothershipService           Ship-user1
|              | ---------- |        |---vol1
|..............| -----.     |--------|
                       \    
                        \   Ship-user2
                         '- |        |---vol2
                            |--------|
</code></pre>
<p>I can manage fine to get up the ship service</p>
<pre><code>&gt; kubectl get all -o wide
NAME           READY   STATUS    RESTARTS   AGE   IP            NODE       NOMINATED NODE   READINESS GATES
pod/ship-0     1/1     Running   0          7d    10.244.0.91   minikube   &lt;none&gt;           &lt;none&gt;

NAME                 TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)    AGE   SELECTOR
service/ship         ClusterIP   None         &lt;none&gt;        8000/TCP   7d    app=ship
service/kubernetes   ClusterIP   10.96.0.1    &lt;none&gt;        443/TCP    7d    &lt;none&gt;

NAME                      READY   AGE   CONTAINERS   IMAGES
statefulset.apps/ship     1/1     7d    ship       ship
</code></pre>
<p>My question is how do I go about testing this via <code>curl</code> or a browser? These are all backend services so <code>NodePort</code> seems not the right approach since none of this should be accessible to the public. Eventually I will build a test-suite for all this and deploy on GKE.</p>
<p>ship.yml (pseudo-spec)</p>
<pre><code>kind: Service
metadata:
  name: ship
spec:
  ports:
  - port: 8000
    name: ship
  clusterIP: None  # headless service
  ..

---

kind: StatefulSet
metadata:
  name: ship
spec:
  serviceName: &quot;ship&quot;
  replicas: 1
  template:
    spec:
      containers:
      - name: ship
        image: ship
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 8000
          name: ship
  ..
</code></pre>

<p>One possibility is to use the <code>kubectl port-forward</code> command to expose the pod port locally on your system. For example, if I'm use this deployment to run a simple web server listening on port 8000:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: example
  name: example
spec:
  selector:
    matchLabels:
      app: example
  template:
    metadata:
      labels:
        app: example
    spec:
      containers:
      - args:
        - --port
        - &quot;8000&quot;
        image: docker.io/alpinelinux/darkhttpd
        name: web
        ports:
        - containerPort: 8000
          name: http
</code></pre>
<p>I can expose that on my local system by running:</p>
<pre><code>kubectl port-forward deploy/example 8000:8000
</code></pre>
<p>As long as that <code>port-forward</code> command is running, I can point my browser (or <code>curl</code>) at <code>http://localhost:8000</code> to access the service.</p>
<hr />
<p>Alternately, I can use <code>kubectl exec</code> to run commands (like <code>curl</code> or <code>wget</code>) inside the pod:</p>
<pre><code>kubectl exec -it web -- wget -O- http://127.0.0.1:8000
</code></pre>
