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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With