External IP not responding after Kubernetes deployment

12/16/2019

I am new to Kubernetes and was testing a sample deployment. The following is the output from the kubectl get services command. After I deployed the application thru a deployment yml it completes successfully and the pods are provisioned. Now I go to EXTERNAL-IP:80 but I don't get a response and the page keeps spinning.

NAME                    TYPE           CLUSTER-IP     EXTERNAL-IP     PORT(S)        AGE
demotest2               LoadBalancer   XX.X.XX.XX     XX.XXX.XXX.XX   80:30904/TCP   35m

Please let me know if I need to provide more information.

-- Ja13
azure
azure-aks
kubernetes

1 Answer

12/17/2019

From the message you provided, there are two possible reasons. One is that the pod of your deployment does not run well. It means your image which hosts your application does not work as you want. For this, you need to check if your image can work well locally. Another one is that the demotest2 service does not route the request to the pod of your deployment. For this, you need to check if the selector of the service was set correctly for your pod.

For example:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  selector:
    matchLabels:
      run: nginx1
  replicas: 1
  template:
    metadata:
      labels:
        run: nginx1
    spec:
      containers:
      - name: nginx
        image: nginx:latest
        ports:
        - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: nginx-service
spec:
  type: LoadBalancer
  ports:
  - name: test1
    port: 80
    targetPort: 80
  selector:
    run: nginx1

In this example, the pods of the deployment use the label run: nginx1, so you need to set the selector of the service as run: nginx1.

-- Charles Xu
Source: StackOverflow