How to get a external IP of VM running Kubernet Services

12/12/2019

I have hosted Docker Images in a VM of Azure and I'm trying to access the Service outside VM. This is not working because of External IP is not generated for the Service.

After building the Docker image, I've applied yml file for creating Deployment and Service. My yml file looks as below:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: planservice-deployment
  labels: 
    app: planservice-deploy
spec:
  selector:
    matchLabels:
      run: planservice-deploy
  replicas: 2
  template:
    metadata:
      labels:
        run: planservice-deploy
    spec:
      containers:
      - name: planservice-deploy
        image: planserviceimage
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 8086
---
apiVersion: v1
kind: Service
metadata:
  name: planservice-service
  labels: 
    app: planservice-deploy
spec:
  type: NodePort
  ports:
  - port: 80
    protocol: TCP
    targetPort: 8086
  selector:
    run: planservice-deploy
---

After I ran the following command to look running services:

kubectl get pods --output=wide

This command returned all the running services and it's external IP information. But, when I saw the list, all the services are generated with blank external IPs.

How to set external IP for all the services, so that I can access my web services outside VM?

-- 55SK55
azure
docker
ip
kubernetes
virtual-machine

1 Answer

12/12/2019

you need to change type to LoadBalancer:

apiVersion: v1
kind: Service
metadata:
  name: planservice-service
  labels: 
    app: planservice-deploy
spec:
  type: LoadBalancer
  ports:
  - port: 80
    protocol: TCP
    targetPort: 8086
  selector:
    run: planservice-deploy

https://kubernetes.io/docs/concepts/services-networking/service/#loadbalancer

-- 4c74356b41
Source: StackOverflow