<p>I'm having trouble with the examples in section 5.1.1 <em>Using Named Ports</em> of <strong>Kubernetes In Action</strong> by Marko Luksa. The example goes like this:</p>

<h1>First - Create</h1>

<p>I'm creating a pod with a named port that runs a Node.js container that responds with <code>You've hit &lt;hostname&gt;</code> when it's hit:</p>

<pre class="lang-sh prettyprint-override"><code>apiVersion: v1
kind: Pod
metadata:
  name: named-port-pod
  labels:
    app: named-port
spec: 
  containers:
  - name: kubia
    image: michaellundquist/kubia
    ports:
    - name: http
      containerPort: 8080
</code></pre>

<p>And a service like this (note, this is a simplified version of the <a href="https://github.com/luksa/kubernetes-in-action/blob/master/Chapter05/kubia-svc-named-ports.yaml" rel="nofollow noreferrer">original example</a> which also doesn't work.:</p>

<pre class="lang-sh prettyprint-override"><code>apiVersion: v1
kind: Service
metadata:
  name: named-port-service
spec:
  ports:
  - name: http
    port: 80
    targetPort: http
  selector:
    app: named-port
</code></pre>

<h1>Second - Verify</h1>

<pre class="lang-sh prettyprint-override"><code>$ kubectl get po -o wide --show-labels
NAME             READY   STATUS    RESTARTS   AGE   IP           NODE       NOMINATED NODE   READINESS GATES   LABELS
named-port-pod   1/1     Running   0          45m   172.17.0.7   minikube   &lt;none&gt;           &lt;none&gt;            app=named-port


$ kubectl get services
NAME                 TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)   AGE
kubernetes           ClusterIP   10.96.0.1       &lt;none&gt;        443/TCP   53m
named-port-service   ClusterIP   10.96.115.108   &lt;none&gt;        80/TCP    19m

$ kubectl describe service named-port-service 
Name:              named-port-service
Namespace:         default
Labels:            &lt;none&gt;
Annotations:       &lt;none&gt;
Selector:          app=named-port
Type:              ClusterIP
IP:                10.96.115.108
Port:              http  80/TCP
TargetPort:        http/TCP
Endpoints:         172.17.0.7:8080
Session Affinity:  None
Events:            &lt;none&gt;
</code></pre>

<h1>Third - Test (Failing)</h1>

<pre><code>$ kubectl exec named-port-pod -- curl named-port-pod:8080
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    26    0    26    0     0   5494      0 --:--:-- --:--:-- --:--:--  6500
You've hit named-port-pod

$ kubectl exec named-port-pod -- curl --max-time 20 named-port-service
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:--  0:00:19 --:--:--     0curl: (28) Connection timed out after 20001 milliseconds
command terminated with exit code 28
</code></pre>

<p>As you can see, everything works when I hit <code>named-port-pod:8080</code>, but fails when I hit <code>named-port-service</code>. I'm pretty sure I have the mapping correct because <code>kubectl describe service named-port-service</code> has the correct endpoint I think minikube <a href="https://github.com/kubernetes/minikube/issues/3351" rel="nofollow noreferrer">can use named ports</a> but my service can't pass connections to my pod. Why?</p>

<p>p.s here's my minikube version:</p>

<pre class="lang-sh prettyprint-override"><code>$ minikube version
minikube version: v1.6.2
commit: 54f28ac5d3a815d1196cd5d57d707439ee4bb392
</code></pre>

mikeLundquist
<p>This is known issue with minikube. Pod cannot reach itself via service IP. You can try accesing your service from a different pod or use the following workaround to fix this. </p>

<pre><code>minikube ssh
sudo ip link set docker0 promisc on
</code></pre>

<p>Open issue: <a href="https://github.com/kubernetes/minikube/issues/1568" rel="nofollow noreferrer">https://github.com/kubernetes/minikube/issues/1568</a></p>
