简体   繁体   中英

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?

在此处输入图片说明

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).

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.

Disclaimer: I work for Netris

You can use Netris to automatically assign an external IP address to the L4LB VIP and load balance across your ingress nodes.

https://netris.ai/start

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM