Illidan
Illidan

Reputation: 4237

Kubernetes service is not getting external IP

I running Kubernetes cluster on premises, initialized using KubeAdm. I configured flannel networking plugin.

When I exposing service as a NodePort, I'm not able to receive external IP. What do I miss?

enter image description here

My deployment yaml looks as the following:

apiVersion: v1
kind: Service
metadata:
  name: testapp
  labels:
    run: testapp
spec:
  type: NodePort
  ports:
  - port: 8080
    targetPort: 80
    protocol: TCP
    name: http
  - port: 443
    protocol: TCP
    name: https
  selector:
    run: testapp
---------
apiVersion: apps/v1
kind: Deployment
metadata:
  name: testapp
spec:
  selector:
    matchLabels:
      run: testapp
  replicas: 2
  template:
    metadata:
      name: testapp
      labels:
        run: testapp
    spec:
      containers:
        - image: [omitted]
          name: testapp
          ports:
          - containerPort: 80
             livenessProbe:
               httpGet:
               path: /api/health
               port: 80

Environment details:

Kubernetes version:

Client Version: version.Info{Major:"1", Minor:"9", GitVersion:"v1.9.3", GitCommit:"d2835416544f298c919e2ead3be3d0864b52323b", GitTreeState:"clean", BuildDate:"2018-02-07T12:22:21Z", GoVersion:"go1.9.2", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"9", GitVersion:"v1.9.3", GitCommit:"d2835416544f298c919e2ead3be3d0864b52323b", GitTreeState:"clean", BuildDate:"2018-02-07T11:55:20Z", GoVersion:"go1.9.2", Compiler:"gc", Platform:"linux/amd64"}

Running Ubuntu Server 16.04 on vSphere VM (on-prem).

Upvotes: 13

Views: 29553

Answers (3)

Vijay
Vijay

Reputation: 391

In NodePort you won't get an external IP , Try to use type:LoadBalancer instead of NodePort to get external IP that's what you actually want ,

apiVersion: v1

kind: Service

metadata:

name: my-service

spec:

selector:

app.kubernetes.io/name: MyApp

ports:

- protocol: TCP

  port: 80

  targetPort: 9376

clusterIP: 10.0.171.239

type: LoadBalancer

status:

loadBalancer:

ingress:

- ip: 192.0.2.127

Upvotes: 1

Vijay
Vijay

Reputation: 296

You would not get an external IP when exposing service as a nodeport. Exposing Service on a Nodeport means that your service would be available on externally via the NodeIP of any node in the cluster at a random port between 30000-32767(default behaviour) .

In your case , the port on which your service is exposed is port 31727.

Each of the nodes in the cluster proxy that port (the same port number on every Node) into the pod where your service is launched.

Easiest way to see this using

kubectl describe service <service-name>

Check for detail of the Nodeport in the result above.

Later get any the node Ip of any of the nodes in the cluster using

kubectl get nodes -o wide

You can now access your service externally using <Node-IP>:<Node-Port>

Additionally, if you want a fixed Node port, you can specify that in the yaml.

PS: Just make sure you add a security rule on your nodes to allow traffic on the particular port.

Upvotes: 17

Anton Kostenko
Anton Kostenko

Reputation: 8973

You will not see an "External-IP" value here if you using a node port.

From documentation:

If you set the type field to "NodePort", the Kubernetes master will allocate a port from a flag-configured range (default: 30000-32767), and each Node will proxy that port (the same port number on every Node) into your Service. That port will be reported in your Service’s spec.ports[*].nodePort field.

So, you don't have a one IP which can be shown there. You can connect to any of your nodes to defined NodePort.

Upvotes: 5

Related Questions