luksa / kubernetes-in-action-2nd-edition

Code from the Kubernetes in Action 2nd Edition book
652 stars 305 forks source link

Chaper 12.2.1 Problems when exposing Services through Ingress #15

Closed Bonjaski closed 2 years ago

Bonjaski commented 2 years ago

Environments

[Ingress Controller] kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.1.1/deploy/static/provider/baremetal/deploy.yaml

[Pods, Services] https://github.com/luksa/kubernetes-in-action-2nd-edition/tree/master/Chapter12/SETUP

YAML FILE

[Service]

apiVersion: v1
kind: Service
metadata:
  name: kiada
spec:
  type: ClusterIP
  selector:
    app: kiada
  ports:
  - name: http
    port: 80
    targetPort: 8080
  - name: https
    port: 443
    targetPort: 8443

[Ingress]

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: kiada-example-com
spec:
  rules:
  - host: kiada.example.com
    http:
      paths:
      - path: /        
        pathType: Prefix
        backend:
          service:    
            name: kiada
            port:
              number: 80

Problem

When I tried to create ingress objects as following up on chapter 12, However I could not progress to the next step because the kiada service failed to find endpoints.

To Reproduce

Description about Resource

kiada service

root@k8s-m:~# kubectl describe svc kiada
Name:              kiada
Namespace:         default
Labels:            <none>
Annotations:       <none>
Selector:          app=kiada
Type:              ClusterIP
IP Family Policy:  SingleStack
IP Families:       IPv4
IP:                10.111.148.71
IPs:               10.111.148.71
Port:              http  80/TCP
TargetPort:        8080/TCP
Endpoints:         <none>
Port:              https  443/TCP
TargetPort:        8443/TCP
Endpoints:         <none>
Session Affinity:  None
Events:            <none>

kiada Ingress

Name:             kiada-example-com
Namespace:        default
Address:          
Default backend:  default-http-backend:80 (<error: endpoints "default-http-backend" not found>)
Rules:
  Host               Path  Backends
  ----               ----  --------
  kiada.example.com  
                     /   kiada:80 (<error: endpoints "kiada" not found>)
Annotations:         <none>
Events:              <none>

Please give me any suggestions to proceed Ingress chapter.

luksa commented 2 years ago

What does kubectl get ep return? What about kubectl get po -l app=kiada?

Bonjaski commented 2 years ago

What does kubectl get ep return? What about kubectl get po -l app=kiada?

[Endpoint]

root@k8s-m:~# kubectl get ep
NAME         ENDPOINTS                                            AGE
kubernetes   192.168.100.10:6443                                  72d
quote        172.16.197.18:80,172.16.228.102:80,172.16.46.20:80   15h

[Pod which has kiada label]

root@k8s-m:~# kubectl get pod --show-labels -l app=kiada
NAME        READY   STATUS    RESTARTS   AGE   LABELS
kiada-001   2/2     Running   0          15h   app=kiada,rel=stable
kiada-002   2/2     Running   0          15h   app=kiada,rel=stable
kiada-003   2/2     Running   0          15h   app=kiada,rel=stable

[Information about Noes & All Resources From Chapter12]

root@k8s-m:~# kubectl get nodes -o wide
NAME     STATUS   ROLES                  AGE    VERSION   INTERNAL-IP       EXTERNAL-IP   OS-IMAGE             KERNEL-VERSION     CONTAINER-RUNTIME
k8s-m    Ready    control-plane,master   111d   v1.22.6   192.168.100.10    <none>        Ubuntu 20.04.3 LTS   5.4.0-91-generic   docker://20.10.9
k8s-w1   Ready    <none>                 111d   v1.22.6   192.168.100.101   <none>        Ubuntu 20.04.3 LTS   5.4.0-91-generic   docker://20.10.9
k8s-w2   Ready    <none>                 111d   v1.22.6   192.168.100.102   <none>        Ubuntu 20.04.3 LTS   5.4.0-91-generic   docker://20.10.9
k8s-w3   Ready    <none>                 111d   v1.22.6   192.168.100.103   <none>        Ubuntu 20.04.3 LTS   5.4.0-90-generic   docker://20.10.9
root@k8s-m:~# kubectl get all
NAME            READY   STATUS             RESTARTS      AGE
pod/kiada-001   2/2     Running            0             15h
pod/kiada-002   2/2     Running            0             15h
pod/kiada-003   2/2     Running            0             15h
pod/quiz        0/2     CrashLoopBackOff   7 (48s ago)   2m27s
pod/quote-001   2/2     Running            0             15h
pod/quote-002   2/2     Running            0             15h
pod/quote-003   2/2     Running            0             15h

NAME                 TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
service/kiada        ClusterIP   10.111.148.71    <none>        80/TCP,443/TCP   3h50m
service/kubernetes   ClusterIP   10.96.0.1        <none>        443/TCP          72d
service/quiz         ClusterIP   10.108.219.122   <none>        80/TCP           2m27s
service/quote        ClusterIP   10.104.3.198     <none>        80/TCP           15h
luksa commented 2 years ago

The kiada endpoints objects is indeed missing. No idea why, as it should have been created when you created the service. I suggest deleting the service and recreating it. If that doesn't work, try recreating the quote service and check if the endpoints object is created for it.

Bonjaski commented 2 years ago

The kiada endpoints objects is indeed missing. No idea why, as it should have been created when you created the service. I suggest deleting the service and recreating it. If that doesn't work, try recreating the quote service and check if the endpoints object is created for it.

Problem

Endpoint problem was because of unhealthy status of the scheduler and controller-manager. Even though fixing unhealthy issue, I am still facing an error that backend endpoint are not mapping with an Ingress.

I've googled about this issue and tried my best, but could not solve it.

Description

[Ingress Information]

root@k8s-m:~# kubectl describe ingress
Name:             kiada-example-com
Namespace:        default
Address:          
Default backend:  default-http-backend:80 (<error: endpoints "default-http-backend" not found>)
Rules:
  Host               Path  Backends
  ----               ----  --------
  kiada.example.com  
                     /   kiada:80 (172.16.197.23:8080,172.16.46.22:8080,172.16.46.23:8080)

[Endpoint]

root@k8s-m:~# kubectl get ep
NAME         ENDPOINTS                                                            AGE
kiada        172.16.197.23:8443,172.16.46.22:8443,172.16.46.23:8443 + 3 more...   42m
kubernetes   192.168.100.10:6443                                                  74d
quiz                                                                              42m
quote        172.16.197.22:80,172.16.228.103:80,172.16.46.24:80                   42m

[Service Info]

root@k8s-m:~# kubectl describe svc kiada 
Name:              kiada
Namespace:         default
Labels:            <none>
Annotations:       <none>
Selector:          app=kiada
Type:              ClusterIP
IP Family Policy:  SingleStack
IP Families:       IPv4
IP:                10.109.75.183
IPs:               10.109.75.183
Port:              http  80/TCP
TargetPort:        8080/TCP
Endpoints:         172.16.197.23:8080,172.16.46.22:8080,172.16.46.23:8080
Port:              https  443/TCP
TargetPort:        8443/TCP
Endpoints:         172.16.197.23:8443,172.16.46.22:8443,172.16.46.23:8443
Session Affinity:  None
Events:            <none>

[Resources]

root@k8s-m:~# kubectl get all --show-labels
NAME            READY   STATUS             RESTARTS       AGE   LABELS
pod/kiada-001   2/2     Running            0              53m   app=kiada,rel=stable
pod/kiada-002   2/2     Running            0              53m   app=kiada,rel=stable
pod/kiada-003   2/2     Running            0              53m   app=kiada,rel=stable
pod/quiz        0/2     CrashLoopBackOff   27 (92s ago)   50m   app=quiz,rel=stable
pod/quote-001   2/2     Running            0              53m   app=quote,rel=stable
pod/quote-002   2/2     Running            0              53m   app=quote,rel=stable
pod/quote-003   2/2     Running            0              53m   app=quote,rel=stable

NAME                 TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE   LABELS
service/kiada        ClusterIP   10.109.75.183   <none>        80/TCP,443/TCP   53m   <none>
service/kubernetes   ClusterIP   10.96.0.1       <none>        443/TCP          74d   component=apiserver,provider=kubernetes
service/quiz         ClusterIP   10.110.54.62    <none>        80/TCP           53m   <none>
service/quote        ClusterIP   10.111.94.97    <none>        80/TCP           53m   <none>
luksa commented 2 years ago

You can safely ignore the error endpoints "default-http-backend" not found. I believe I explain this in the chapter somewhere. If you create the default-http-backend service, the message will disappear.

luksa commented 2 years ago

Hmm, I can't find the reference to the default-http-backend in the manuscript. Looks like I removed it by mistake. I'll make sure it gets into the next MEAP update.

Anyway, as I mentioned, you can ignore the error. If the default backend is missing, then requests that match no Ingress rules simply won't get forwarded to any backend. If you create a service called default-http-backend, requests will get forwarded to it. You can also specify the default backend service in the Ingress object. This part is explained in section 12.2.4.