[TOC] # Ingress :::info [Ingress | Kubernetes](https://kubernetes.io/docs/concepts/services-networking/ingress/) ::: ## Why we need Ingress? - Each LoadBalancer service requires its own load balancer with its own public IP address - Ingresses operate at the application layer of the network stack (HTTP) and can provide features such as cookie-based session affinity and the like, which services can’t. ## Install an Ingress Controller on Your Cluster - [Ingress-Nginx Controller](https://kubernetes.github.io/ingress-nginx/deploy/) ```bash= kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.8.1/deploy/static/provider/cloud/deploy.yaml ``` ![](https://hackmd.io/_uploads/H1ADdgzRn.png) - You can confirm if the Ingress controller is running: ```bash= kc get po --namespace=ingress-nginx ``` ![](https://hackmd.io/_uploads/BkXtYeG02.png) ## Example: YAML Definition of Ingress Resources ```yaml= apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: phoe-nginx-ingress spec: rules: - host: phoebe.nginx.com http: paths: - path: / pathType: Prefix backend: service: name: phoe-nginx-nodeport port: number: 8080 ``` ### Exposing multiple services through the same Ingress #### MAPPING DIFFERENT SERVICES TO DIFFERENT PATHS OF THE SAME HOST ![](https://hackmd.io/_uploads/H1tFpZMC3.png) #### MAPPING DIFFERENT SERVICES TO DIFFERENT HOSTS ![](https://hackmd.io/_uploads/HJXnpZG02.png) ## Readiness Probes - 在設定 container 相關腳本時,我們可以給予特定的指令,要求 K8s 透過該指令檢查 Pod 是否正確運行。 - 這些指令必須成功執行後 Pod 才會提供服務。 ## Example: YAML Definition of Readiness Probes in Pods' YAML ```yaml= apiVersion: v1 kind: Pod metadata: name: phoe-nginx-pod labels: app: nginx spec: containers: - name: phoe-nginx image: nginx:latest ports: - containerPort: 80 readinessProbe: exec: command: - ls - /var/ready ``` ```bash= kubectl exec phoe-nginx-pod -- touch /var/ready ``` - The readiness probe is checked periodically—every **10 seconds** by default. :::warning kubectl exec 指令中 namespace 欄位必須移到 -- command 前面才能成功執行 原本是 kubectl exec phoe-probe-pod -- touch /var/ready -n=phoebe-namespace 要改為 kubectl exec phoe-probe-pod -n=phoebe-namespace -- touch /var/ready :::