0

I have pod:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello-app
  namespace: dev
spec:
  selector:
    matchLabels:
      app: hello
  replicas: 3
  template:
    metadata:
      labels:
        app: hello
    spec:
      containers:
      - name: hello
        image: "gcr.io/google-samples/hello-app:2.0"

Make service:

---
apiVersion: v1
kind: Service
metadata:
  name: hello-service
  namespace: dev
  labels:
    app: hello
spec:
  type: ClusterIP
  selector:
    app: hello
  ports:
  - port: 80
    targetPort: 8080
    protocol: TCP

Check it:

---
apiVersion: v1
kind: Service
metadata:
  name: hello-node-service
  namespace: dev
spec:
  type: NodePort
  selector:
    app: hello
  ports:
    - port: 80
      targetPort: 8080

$ kubectl get svc -n dev

NAME                 TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE
hello-node-service   NodePort    10.233.3.50     <none>        80:31263/TCP   9h
hello-service        ClusterIP   10.233.45.159   <none>        80/TCP         44h

$ curl -I http://cluster.local:31263

HTTP/1.1 200 OK
Date: Sat, 11 Sep 2021 07:31:28 GMT
Content-Length: 66
Content-Type: text/plain; charset=utf-8

I have verified that the service is working.

Install ingress with NodeIP (https://kubernetes.github.io/ingress-nginx/deploy/):

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.0.0/deploy/static/provider/baremetal/deploy.yaml

$ kubectl get pods -n ingress-nginx -l app.kubernetes.io/name=ingress-nginx --watch

NAME                                       READY   STATUS      RESTARTS   AGE
ingress-nginx-admission-create-7gsft       0/1     Completed   0          10h
ingress-nginx-admission-patch-qj57b        0/1     Completed   1          10h
ingress-nginx-controller-8cf5559f8-mh6fr   1/1     Running     0          10h

$ kubectl get svc -n ingress-nginx

NAME                                 TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)                      AGE
ingress-nginx-controller             NodePort    10.233.52.118   <none>        80:30377/TCP,443:31682/TCP   10h
ingress-nginx-controller-admission   ClusterIP   10.233.51.175   <none>        443/TCP                      10h

Check it:

$ curl -I http://cluster.local:30377/healthz

HTTP/1.1 200 OK
Date: Sat, 11 Sep 2021 07:39:04 GMT
Content-Type: text/html
Content-Length: 0
Connection: keep-alive

Make ingress:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
   name: ingress-hello
   namespace: dev
spec:
  rules:
  - host: cluster.local
    http:
      paths:
      - backend:
          service:
            name: hello-service
            port:
              number: 80
        path: "/hello"
        pathType: Prefix

Check It:

$ curl -I http://cluster.local:30377/hello
HTTP/1.1 404 Not Found
Date: Sat, 11 Sep 2021 07:40:43 GMT
Content-Type: text/html
Content-Length: 146
Connection: keep-alive

It's doesn't work. I spend few days, tried add ExternalIP to ingress controller.

Can you please tell me who had the experience of setting up ingress, what am I doing wrong? =(((

INFO about cluster: $ kubectl get ingress -n dev

NAME            CLASS    HOSTS           ADDRESS   PORTS   AGE
ingress-hello   <none>   cluster.local             80      10h

$ kubectl get nodes

NAME               STATUS   ROLES                  AGE   VERSION
kuber-ingress-01   Ready    worker                 10d   v1.21.3
kuber-master1      Ready    control-plane,master   10d   v1.21.3
kuber-master2      Ready    control-plane,master   10d   v1.21.3
kuber-master3      Ready    control-plane,master   10d   v1.21.3
kuber-node-01      Ready    worker                 10d   v1.21.3
kuber-node-02      Ready    worker                 10d   v1.21.3
kuber-node-03      Ready    worker                 10d   v1.21.3

Inventory:

kuber-master1 10.0.57.31
kuber-master2 10.0.57.32
kuber-master3 10.0.57.33
kuber-node-01 10.0.57.34
kuber-node-02 10.0.57.35
kuber-node-03 10.0.57.36
kuber-ingress-01 10.0.57.30

$ ping cluster.local

PING cluster.local (10.0.57.30) 56(84) bytes of data.
64 bytes from ingress.example.com (10.0.57.30): icmp_seq=1 ttl=62 time=0.603 ms
Andrew Kaa
  • 117
  • 9
  • 1
    Did you try to remove `host: cluster.local` in the ingress definition (and then use *) ? It may be because `cluster.local:30377` is not `cluster.local` – mpromonet Sep 11 '21 at 08:05
  • Good afternoon, thanks for the tip. Yes, that seems to be the case. But I haven't found a way to put an asterisk at the end of the address. Probably I need an external proxy server that will redirect from 80 (cluster.local) to NodeIP (cluster.local:30377). – Andrew Kaa Sep 11 '21 at 09:05
  • 1
    removing host attribute will remove host filter of the ingress, it may helps till you don't need host filter – mpromonet Sep 11 '21 at 09:44
  • Unfortunately, it did not help, I also added externalIP: $ curl -I http://cluster.local/healthz HTTP/1.1 200 OK $ curl -I http://cluster.local//hello HTTP/1.1 404 Not Found – Andrew Kaa Sep 11 '21 at 22:22
  • It feels like the ingress controller can't see the ingress rules. – Andrew Kaa Sep 11 '21 at 22:27
  • I did not find it in the documentation if I set the name in / etc / hosts .. maybe I still need to do something with core-dns. And the example from Documentation for minikube works. And there is doesn't wokr in the cluster k8s , I have already raised 3 different clusters with different configurations. – Andrew Kaa Sep 11 '21 at 22:27

1 Answers1

0

The solution is to add the following content to the ingress - annotation. Then the ingress controller starts to see the DNS addresses.

  annotations:
      kubernetes.io/ingress.class: nginx
      nginx.ingress.kubernetes.io/ssl-redirect: "false"
      nginx.ingress.kubernetes.io/use-regex: "true"
      nginx.ingress.kubernetes.io/rewrite-target: /$1

Also, for convenience, changed path: / to a regular expression:

            - path: /v1(/|$)(.*)
Andrew Kaa
  • 117
  • 9