Search code examples
kuberneteskubernetes-ingressminikubenginx-ingresskustomize

Create ingress deployment with Minikube


I'm going through this tutorial to create a deployment and an ingress controller on Minikube. When I run, as instructed in the tutorial, curl --resolve "hello-world.info:80:$( minikube ip )" -i http://hello-world.info I simply get HTTP/1.1 503 Service Temporarily Unavailable.

Here are my deployment, service, ingress and kustomization files:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: example-deployment
  labels:
    app: example
spec:
  replicas: 2
  selector:
    matchLabels:
      app: example
  template:
    metadata:
      labels:
        app: example
    spec:
      containers:
      - name: nginx
        image: localhost:5000/example-app:latest
        ports:
        - name: web
          containerPort: 80

---

apiVersion: v1
kind: Service
metadata:
  name: example
spec:
  ports:
    - name: web
      port: 80
      targetPort: web
  selector:
    app.kubernetes.io/name: example

---

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: example-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
  rules:
  - host: hello-world.info
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: example
            port:
              number: 80

---

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
metadata:
  name: arbitrary

# Example configuration for the webserver
# at https://github.com/monopole/hello
commonLabels:
  app: example

resources:
- deployment.yaml
- service.yaml
- ingress.yaml


Here is the output from kubectl get ingress:

NAME              CLASS   HOSTS              ADDRESS        PORTS   AGE
example-ingress   nginx   hello-world.info   192.168.49.2   80      3m29s

Here is the output from kubectl get services:

kubectl get services
NAME         TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)   AGE
example      ClusterIP   10.109.63.32   <none>        80/TCP    10m

So as you can see everything is up and running. Here is my nginx:

[jenia@archlinux ibn-battuta]$ kubectl get pods -n ingress-nginx
NAME                                        READY   STATUS      RESTARTS   AGE
ingress-nginx-admission-create-fvj4v        0/1     Completed   0          3h37m
ingress-nginx-admission-patch-d4xfn         0/1     Completed   1          3h37m
ingress-nginx-controller-7799c6795f-7qgsr   1/1     Running     0          3h37m

Here are the logs of nginx 503:

192.168.49.1 - - [29/Aug/2023:01:11:43 +0000] "GET / HTTP/1.1" 503 190 "-" "curl/8.2.1" 79 0.000 [default-example-80] [] - - - - e03c2a5e71db02f27f1afca0905c6c36

If anyone can help me, it'll be greatly appreciated.


Solution

  • @Jenia Ivanov

    targetPort is incorrect in your example service

    selector in example service doesnot match the label of your pod in your deployment yaml

    Could you update targetPort and selector in your service as shown below and verify?

    apiVersion: v1
    kind: Service
    metadata:
      name: example
    spec:
      ports:
        - name: web
          port: 80
          targetPort: 80
      selector:
        app: example