<p>I have a simple restful django project that return 'hello world' when you GET localhost:8000.
I want to run it using microk8s.
Using following instruction (<a href="https://microk8s.io/docs/registry-images" rel="nofollow noreferrer">https://microk8s.io/docs/registry-images</a>) i created the image and apply my yaml file</p>
<p>yaml file:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello-deployment
  labels:
    app: hello
spec:
  selector:
    matchLabels:
      app: hello
  template:
    metadata:
      labels:
        app: hello
    spec:
      containers:
      - name: hello
        image: hello1:local
        imagePullPolicy: Never
        ports:
        - containerPort: 8000
---
apiVersion: v1
kind: Service
metadata:
  name: hello
spec:
  selector:
    app: hello
  ports:
  - name: hello
    port: 8000
    protocol: TCP
    targetPort: 8000
</code></pre>
<p>The pod is running properly.</p>
<pre><code>NAME                                    READY   STATUS    RESTARTS   AGE
pod/hello-deployment-6567ccc4f7-7j6nj   1/1     Running   0          61m

NAME                 TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
service/hello        ClusterIP   10.152.183.241   &lt;none&gt;        8000/TCP         59m

</code></pre>
<p>but when i want to access the 10.152.183.241:8000 nothing works.</p>
<p>I also connect to pod by following command</p>
<pre><code>microk8s kubectl exec -it hello-deployment-6567ccc4f7-7j6nj -- bash
</code></pre>
<p>then install curl and test these:</p>
<pre><code>root@hello-deployment-6567ccc4f7-7j6nj:/code# curl localhost:8000
Hello World
root@hello-deployment-6567ccc4f7-7j6nj:/code# curl 10.152.183.241:8000
curl: (7) Failed to connect to 10.152.183.241 port 8000: Connection refused
</code></pre>
<p>Obviously the program is running but there is a problem with kubernetes service. what's wrong with my yaml file?</p>
<p><strong>Update 1:</strong>
found that image file have problem and it's work with other images.
still don't know what is the problem.</p>
<p>my Dockerfile:</p>
<pre><code>FROM python:3
WORKDIR /code
COPY requirements.txt /code/
RUN pip install -r requirements.txt
COPY . /code/
CMD python3 manage.py runserver
EXPOSE 8000
</code></pre>

M.Dara
<p>It's due to you are using the <strong>ClusterIP</strong> which is only accessible internally from CLuster.</p>
<p>Here you require the <strong>Nginx</strong> ingress controller to expose the service. Or you can try with the Host IP once to connect with the service.</p>
<p>You can also try the command</p>
<pre><code>kubectl port-forward svc/hello 8080:8080
</code></pre>
<p>once the port is forwarded you can hit the <code>curl</code> on <strong>localhost:8080</strong>.</p>
<p>However, for production use-case it's always suggested to use the <code>ingress</code> for managing the cluster traffic.</p>
<p>Ingress basically work as the Proxy it's same as Nginx.</p>
<p><strong>Ingress</strong> is configuration object which managed by the <code>Ingress controller</code>. When you enable the ingress you require the Ingress controller in minikube it will be there however for other Cluster on <strong>GKE &amp; EKS</strong> you have to setup manually.</p>
<p>Here is good example for the implementation of the ingress in minikube :</p>
<p><a href="https://kubernetes.io/docs/tasks/access-application-cluster/ingress-minikube/" rel="nofollow noreferrer">https://kubernetes.io/docs/tasks/access-application-cluster/ingress-minikube/</a></p>
<p>ingress example</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: example-ingress
  annotations:
spec:
  rules:
    - host: hello-world.info
      http:
        paths:
          - path: /
            backend:
              service:
                name: hello
                port:
                  number: 8080
</code></pre>
