<p>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,</p>

<pre><code>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" ]
</code></pre>

<p>The pipeline completes successfully and uploads the image in the repository.</p>

<p>Now I use kubectl to deploy using the deployment file,</p>

<pre><code>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
</code></pre>

<p>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?</p>

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

<pre><code>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
</code></pre>

<p>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.</p>

2713
<p>just configure your service to be of type <code>LoadBalancer</code> and do a proper port mapping:</p>

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

<p><a href="https://kubernetes.io/docs/concepts/services-networking/service/" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/services-networking/service/</a></p>
