Azure kubernetes service loadbalancer external IP not accessible

12/22/2019

I am new to the world of Kubernetes and was testing a sample Django "Hello world" app deployment. Using docker-compose I was able to access the hell world page on a browser but I need to use Kubernetes. So I tested two options and none of them worked. 1) I created an Azure CICD pipeline to build and push the image in ACR using the following Dockerfile,

FROM python:3.8
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
RUN mkdir /hello_world
WORKDIR /hello_world
COPY . /hello_world/
RUN pip install -r requirements.txt
CMD [ "python", "manage.py", "runserver", "0.0.0.0:8000" ]

The pipeline completes successfully and uploads the image in the repository.

Now I use kubectl to deploy using the deployment file,

apiVersion: apps/v1
kind: Deployment
metadata:
  name: django-helloworld
spec:
  replicas: 3
  selector:
    matchLabels:
      app: django-helloworld
  template:
    metadata:
      labels:
        app: django-helloworld
    spec:
      containers:
      - name: django-helloworld
        image: acrshgpdev1.azurecr.io/django-helloworld:194
        #imagePullPolicy: Always
        ports:
        - containerPort: 8000

---

apiVersion: v1
kind: Service
metadata:
  name: django-helloworld-service
spec:
  type: LoadBalancer
  ports:
  - port: 80
  selector:
    app: django-helloworld

The deployment and service are created but when I try to access the external IP of the LB service through a browser the page is inaccessible. I used the external ip:port and it didn't work. Any thoughts why would this be happening?

2) I used the same Dockerfile but a different deployment file(changed the image to the locally created image & removed LB service) to deploy the app to my local Kubernetes. the deployment file was as follows,

apiVersion: v1
kind: Service
metadata:
  name: django-helloworld-service
spec:
  selector:
    app: django-helloworld
  ports:
  - protocol: TCP
    port: 80
    targetPort: 30800
  type: NodePort

---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: django-helloworld
spec:
  replicas: 3
  selector:
    matchLabels:
      app: django-helloworld
  template:
    metadata:
      labels:
        app: django-helloworld
    spec:
      containers:
      - name: django-helloworld
        image: django-helloworld:1.0
        #imagePullPolicy: Always
        ports:
        - containerPort: 8000

It creates the deployment and service but doesn't assign an external IP to the NodePort service so I am not able to figure out what service should I choose to test the app is successful. I know I can't choose a LB as it doesn't go locally and I need to deploy using a cloud service.

-- Ja13
azure
azure-aks
azure-kubernetes
docker
kubernetes

2 Answers

12/25/2019

Make sure the deployment has associated healthy pods too (they show as Running and with 1/1 next to their name). If there aren't, make sure your cluster can successfully pull from acrshgpdev1.azurecr.io registry; you can integrate directly an AKS cluster with an ACR registry following this article:

az aks update -n myAKSCluster -g myResourceGroup --attach-acr acrshgpdev1.azurecr.io

or by adding the SP of the AKS cluster manually to the Reader role on the ACR.

-- Alessandro Vozza
Source: StackOverflow

12/22/2019

just configure your service to be of type LoadBalancer and do a proper port mapping:

apiVersion: v1
kind: Service
metadata:
  name: django-helloworld-service
spec:
  type: LoadBalancer
  ports:
  - port: 80
    targetPort: 8000
  selector:
    app: django-helloworld

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

-- 4c74356b41
Source: StackOverflow