<p>I have a docker nginx container image <code>nha/my-nginx-img</code>.
And I have a one-node kubernetes cluster, installed on bare metal. I am trying to deploy and expose this nginx container (which works fine locally otherwise).</p>

<p>I ran <code>kubectl apply -f nginx.yaml</code> on this file:</p>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-nginx
  labels:
    app: nginx
spec:
  selector:
    matchLabels:
      run: my-nginx
  replicas: 2
  template:
    metadata:
      labels:
        run: my-nginx
    spec:
      containers:
      - name: my-nginx
        image: nha/my-nginx-img
        ports:
        - containerPort: 80
        - containerPort: 443
      imagePullSecrets:
        - name: regcred
#
# Expose Service
#
apiVersion: v1
kind: Service
metadata:
  name: my-nginx
  labels:
    run: my-nginx
spec:
  # I thought using NodePort here 
  # would expose the port on the node?
  type: NodePort
  ports:
  - name: http
    protocol: TCP
    port: 80
    targetPort: 80
  - name: https
    protocol: TCP
    port: 443
    targetPort: 443
  selector:
    run: my-nginx
</code></pre>

<p>I can see them running:</p>

<pre><code>kubectl get pods -l run=my-nginx -o wide
NAME                        READY     STATUS    RESTARTS   AGE       IP               NODE
my-nginx-5ccbf78584-4lxsn   1/1       Running   0          1d        10.233.102.181   node1
my-nginx-5ccbf78584-6qkml   1/1       Running   0          1d        10.233.102.182   node1
</code></pre>

<p>However:
- the IPs show in the resulting command above are NOT the IP of my machine
- when I curl the IP of my machine, I do not get a reply on either the port 80 or 443</p>

<p><strong>How do I get this static content to be served by nginx?</strong></p>

<p><strong><em>Additional information</em></strong></p>

<p><code>kubectl get services</code> gives:</p>

<pre><code>NAME         TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)                      AGE
kubernetes   ClusterIP   10.233.0.1     &lt;none&gt;        443/TCP                      2d
my-nginx     NodePort    10.233.16.91   &lt;none&gt;        80:31081/TCP,443:31856/TCP   5h
</code></pre>

<p>(10.233.16.91 is NOT my IP)</p>

<p>And <code>kubectl describe service my-nginx</code>:</p>

<pre><code>Name:                     my-nginx
Namespace:                default
Labels:                   run=my-nginx
Annotations:              kubectl.kubernetes.io/last-applied-configuration={"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"labels":{"run":"my-nginx"},"name":"my-nginx","namespace":"default"},"spec":{"ports":[...
Selector:                 run=my-nginx
Type:                     NodePort
IP:                       10.233.16.91
Port:                     http  80/TCP
TargetPort:               80/TCP
NodePort:                 http  31081/TCP
Endpoints:                10.233.102.181:80,10.233.102.182:80
Port:                     https  443/TCP
TargetPort:               443/TCP
NodePort:                 https  31856/TCP
Endpoints:                10.233.102.181:443,10.233.102.182:443
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   &lt;none&gt;
</code></pre>

<p>Again, I do not see my IP anywhere in there. </p>

<p>Also, I created the cluster using <a href="https://github.com/kubernetes-incubator/kubespray" rel="nofollow noreferrer">kubespray</a>.</p>

nha
<p>You'll want the service, not the pod. The pod is not exposed to anything except the local kubernetes network, this is why you create the service.</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: my-nginx
  labels:
    run: my-nginx
spec:
  # I thought using NodePort here 
  # would expose the port on the node?
  type: NodePort
  ports:
  - name: http
    protocol: TCP
    port: 80
    targetPort: 80
  - name: https
    protocol: TCP
    port: 443
    targetPort: 443
  selector:
    run: my-nginx
</code></pre>

<p>This here defines the service, and it does expose the port on the node, but the IP you see is the internal "cluster IP" which can only be accessed by other pods.</p>

<p>So you might try <code>kubectl get services</code> </p>

<p><a href="https://i.stack.imgur.com/lOPYu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lOPYu.png" alt=""></a> </p>

<p>This will show you the external ip of the port that is exposed.</p>

<p>Also check out <code>kubectl describe service yourServiceName</code></p>
