<p>I am following this doc <a href="https://kubernetes.io/docs/concepts/services-networking/connect-applications-service/" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/services-networking/connect-applications-service/</a></p>
<p>but I am expecting to be able to curl some localhost:8080 or something like that.</p>
<p>What the the exact curl command and port that is expect FROM THE HOST. Not on the cluster, not on a node, but FROM THE HOST.</p>
<p>I am running in microk8s.</p>
<p>This is the file I have applied, copied from the docs:</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: my-nginx
  labels:
    run: my-nginx
spec:
  type: NodePort
  ports:
  - port: 8080
    targetPort: 80
    protocol: TCP
    name: http
  - port: 443
    protocol: TCP
    name: https
  selector:
    run: my-nginx
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-nginx
spec:
  selector:
    matchLabels:
      run: my-nginx
  replicas: 1
  template:
    metadata:
      labels:
        run: my-nginx
    spec:
      volumes:
      - name: secret-volume
        secret:
          secretName: nginxsecret
      - name: configmap-volume
        configMap:
          name: nginxconfigmap
      containers:
      - name: nginxhttps
        image: bprashanth/nginxhttps:1.0
        ports:
        - containerPort: 443
        - containerPort: 80
        volumeMounts:
        - mountPath: /etc/nginx/ssl
          name: secret-volume
        - mountPath: /etc/nginx/conf.d
          name: configmap-volume
</code></pre>
<p>This is the output of the <code>k get deployment my-nginx -o yaml</code> command:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    deployment.kubernetes.io/revision: &quot;1&quot;
    kubectl.kubernetes.io/last-applied-configuration: |
      {&quot;apiVersion&quot;:&quot;apps/v1&quot;,&quot;kind&quot;:&quot;Deployment&quot;,&quot;metadata&quot;:{&quot;annotations&quot;:{},&quot;name&quot;:&quot;my-nginx&quot;,&quot;namespace&quot;:&quot;default&quot;},&quot;spec&quot;:{&quot;replicas&quot;:1,&quot;selector&quot;:{&quot;matchLabels&quot;:{&quot;run&quot;:&quot;my-nginx&quot;}},&quot;template&quot;:{&quot;metadata&quot;:{&quot;labels&quot;:{&quot;run&quot;:&quot;my-nginx&quot;}},&quot;spec&quot;:{&quot;containers&quot;:[{&quot;image&quot;:&quot;bprashanth/nginxhttps:1.0&quot;,&quot;name&quot;:&quot;nginxhttps&quot;,&quot;ports&quot;:[{&quot;containerPort&quot;:443},{&quot;containerPort&quot;:80}],&quot;volumeMounts&quot;:[{&quot;mountPath&quot;:&quot;/etc/nginx/ssl&quot;,&quot;name&quot;:&quot;secret-volume&quot;},{&quot;mountPath&quot;:&quot;/etc/nginx/conf.d&quot;,&quot;name&quot;:&quot;configmap-volume&quot;}]}],&quot;volumes&quot;:[{&quot;name&quot;:&quot;secret-volume&quot;,&quot;secret&quot;:{&quot;secretName&quot;:&quot;nginxsecret&quot;}},{&quot;configMap&quot;:{&quot;name&quot;:&quot;nginxconfigmap&quot;},&quot;name&quot;:&quot;configmap-volume&quot;}]}}}}
  creationTimestamp: &quot;2021-01-31T19:25:30Z&quot;
  generation: 1
  managedFields:
  - apiVersion: apps/v1
    fieldsType: FieldsV1
    fieldsV1:
      f:metadata:
        f:annotations:
          .: {}
          f:kubectl.kubernetes.io/last-applied-configuration: {}
      f:spec:
        f:progressDeadlineSeconds: {}
        f:replicas: {}
        f:revisionHistoryLimit: {}
        f:selector: {}
        f:strategy:
          f:rollingUpdate:
            .: {}
            f:maxSurge: {}
            f:maxUnavailable: {}
          f:type: {}
        f:template:
          f:metadata:
            f:labels:
              .: {}
              f:run: {}
          f:spec:
            f:containers:
              k:{&quot;name&quot;:&quot;nginxhttps&quot;}:
                .: {}
                f:image: {}
                f:imagePullPolicy: {}
                f:name: {}
                f:ports:
                  .: {}
                  k:{&quot;containerPort&quot;:80,&quot;protocol&quot;:&quot;TCP&quot;}:
                    .: {}
                    f:containerPort: {}
                    f:protocol: {}
                  k:{&quot;containerPort&quot;:443,&quot;protocol&quot;:&quot;TCP&quot;}:
                    .: {}
                    f:containerPort: {}
                    f:protocol: {}
                f:resources: {}
                f:terminationMessagePath: {}
                f:terminationMessagePolicy: {}
                f:volumeMounts:
                  .: {}
                  k:{&quot;mountPath&quot;:&quot;/etc/nginx/conf.d&quot;}:
                    .: {}
                    f:mountPath: {}
                    f:name: {}
                  k:{&quot;mountPath&quot;:&quot;/etc/nginx/ssl&quot;}:
                    .: {}
                    f:mountPath: {}
                    f:name: {}
            f:dnsPolicy: {}
            f:restartPolicy: {}
            f:schedulerName: {}
            f:securityContext: {}
            f:terminationGracePeriodSeconds: {}
            f:volumes:
              .: {}
              k:{&quot;name&quot;:&quot;configmap-volume&quot;}:
                .: {}
                f:configMap:
                  .: {}
                  f:defaultMode: {}
                  f:name: {}
                f:name: {}
              k:{&quot;name&quot;:&quot;secret-volume&quot;}:
                .: {}
                f:name: {}
                f:secret:
                  .: {}
                  f:defaultMode: {}
                  f:secretName: {}
    manager: kubectl-client-side-apply
    operation: Update
    time: &quot;2021-01-31T19:25:30Z&quot;
  - apiVersion: apps/v1
    fieldsType: FieldsV1
    fieldsV1:
      f:metadata:
        f:annotations:
          f:deployment.kubernetes.io/revision: {}
      f:status:
        f:availableReplicas: {}
        f:conditions:
          .: {}
          k:{&quot;type&quot;:&quot;Available&quot;}:
            .: {}
            f:lastTransitionTime: {}
            f:lastUpdateTime: {}
            f:message: {}
            f:reason: {}
            f:status: {}
            f:type: {}
          k:{&quot;type&quot;:&quot;Progressing&quot;}:
            .: {}
            f:lastTransitionTime: {}
            f:lastUpdateTime: {}
            f:message: {}
            f:reason: {}
            f:status: {}
            f:type: {}
        f:observedGeneration: {}
        f:readyReplicas: {}
        f:replicas: {}
        f:updatedReplicas: {}
    manager: kube-controller-manager
    operation: Update
    time: &quot;2021-01-31T19:25:31Z&quot;
  name: my-nginx
  namespace: default
  resourceVersion: &quot;764711&quot;
  selfLink: /apis/apps/v1/namespaces/default/deployments/my-nginx
  uid: 77061fd6-8a88-4e0d-891b-6dcc5df2c95e
spec:
  progressDeadlineSeconds: 600
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      run: my-nginx
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      creationTimestamp: null
      labels:
        run: my-nginx
    spec:
      containers:
      - image: bprashanth/nginxhttps:1.0
        imagePullPolicy: IfNotPresent
        name: nginxhttps
        ports:
        - containerPort: 443
          protocol: TCP
        - containerPort: 80
          protocol: TCP
        resources: {}
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
        volumeMounts:
        - mountPath: /etc/nginx/ssl
          name: secret-volume
        - mountPath: /etc/nginx/conf.d
          name: configmap-volume
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30
      volumes:
      - name: secret-volume
        secret:
          defaultMode: 420
          secretName: nginxsecret
      - configMap:
          defaultMode: 420
          name: nginxconfigmap
        name: configmap-volume
status:
  availableReplicas: 1
  conditions:
  - lastTransitionTime: &quot;2021-01-31T19:25:31Z&quot;
    lastUpdateTime: &quot;2021-01-31T19:25:31Z&quot;
    message: Deployment has minimum availability.
    reason: MinimumReplicasAvailable
    status: &quot;True&quot;
    type: Available
  - lastTransitionTime: &quot;2021-01-31T19:25:30Z&quot;
    lastUpdateTime: &quot;2021-01-31T19:25:31Z&quot;
    message: ReplicaSet &quot;my-nginx-5b6fb7fb46&quot; has successfully progressed.
    reason: NewReplicaSetAvailable
    status: &quot;True&quot;
    type: Progressing
  observedGeneration: 1
  readyReplicas: 1
  replicas: 1
  updatedReplicas: 1
</code></pre>
<p>There is also this default.conf as in the docs</p>
<pre><code> cat default.conf
server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;

        listen 443 ssl;

        root /usr/share/nginx/html;
        index index.html;

        server_name localhost;
        ssl_certificate /etc/nginx/ssl/tls.crt;
        ssl_certificate_key /etc/nginx/ssl/tls.key;

        location / {
                try_files $uri $uri/ =404;
        }
}
</code></pre>

mathtick
<p>try <code>curl -k 127.0.0.1:80</code> or <code>curl -k localhost:80</code>. actually the <code>8080</code> port is for the <code>service</code> but when you try <code>localhost</code> or <code>127.0.0.1</code> they don't connect through <code>service</code> so the <code>port</code> need to be the <code>container</code>'s port which is <code>80</code>.</p>
