Kubernetes node is not accessible on port 80 and 443

4/17/2018

I deployed a bunch of services and with all of them I have the same problem: the defined port (e.g. 80 and 443) is not accessible, but anyway the automatically assigned node port.

enter image description here

The following service definition is exported from the first service:

{
  "kind": "Service",
  "apiVersion": "v1",
  "metadata": {
    "name": "traefik",
    "namespace": "kube-system",
    "selfLink": "/api/v1/namespaces/kube-system/services/traefik",
    "uid": "70df3a55-422c-11e8-b7c0-b827eb28c626",
    "resourceVersion": "1531399",
    "creationTimestamp": "2018-04-17T10:45:27Z",
    "labels": {
      "app": "traefik",
      "chart": "traefik-1.28.1",
      "heritage": "Tiller",
      "release": "traefik"
    }
  },
  "spec": {
    "ports": [
      {
        "name": "http",
        "protocol": "TCP",
        "port": 80,
        "targetPort": "http",
        "nodePort": 31822
      },
      {
        "name": "https",
        "protocol": "TCP",
        "port": 443,
        "targetPort": "httpn",
        "nodePort": 32638
      }
    ],
    "selector": {
      "app": "traefik",
      "release": "traefik"
    },
    "clusterIP": "10.109.80.108",
    "type": "LoadBalancer",
    "sessionAffinity": "None",
    "externalTrafficPolicy": "Cluster"
  },
  "status": {
    "loadBalancer": {}
  }
}

enter image description here

any idea how i can reach this service with http://node-ip-addr:80 and the other service with http://node-ip-addr:443?

-- bbholzbb
kubernetes
linux
raspberry-pi

2 Answers

4/17/2018

The ports that you defined for your services --in this case 443 and 80-- are only reachable from within the cluster. You can try to call your service from another pod (which runs busy box, for example) with curl http://traefik.kube-system.svc.cluster.local or http://.

If you want to access your services from outside the cluster (which is your use case you need to expose your service as one of the following

  • NodePort
  • LoadBalancer
  • ExternalName

You chose NodePort which means that every node of the cluster listens for requests on a specific port (in your case 31822 for http and 32638 for https) which will then be delegated to your service. This is why http://node-ip-addr:31822 should work for your provided service config.

To adapt your configuration according to your requirements you must set "nodePort": 80 which in turn will reserve port 80 on every cluster node to delegate to you service. This is generally not the best idea. You would rather keep the port as currently defined and add a proxy server or a load balancer in front of your cluster which would then listen for port 80 and forward to one of the nodes to port 31822 for your service.

For more information on publishing services please refer to the docs at Kubernetes docs

-- Javatar81
Source: StackOverflow

4/18/2018

Check the following working example.

Note:

  1. The container listens at port 4000 which is specified as containerPort in the Deployment
  2. The Service maps the container port 4000 (targetPort) to port 80
  3. The Ingress is now pointing to servicePort 80

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: testui-deploy
spec:
  replicas: 1
  revisionHistoryLimit: 1
  selector: 
    matchLabels: 
      app: testui
  template:
    metadata:
      labels:
        app: testui
    spec:
      containers:
        - name: testui
          image: gcr.io/test2018/testui:latest
          ports:
            - containerPort: 4000
---
apiVersion: v1
kind: Service
metadata:
  name: testui-svc
  labels: 
    app: testui-svc
spec:
  type: NodePort
  selector:
    app: testui
  ports:
  - protocol: TCP
    port: 80
    targetPort: 4000
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: test-ing
  annotations:
    kubernetes.io/ingress.global-static-ip-name: test-ip
spec:
  backend:
    serviceName: testui-svc
    servicePort: 80
-- Saptarshi Basu
Source: StackOverflow