# K8S Ingress/Ingress Controller


# 介紹


# Ingress

定義規則

Ingress 是 K8s 所提供的工具,用在定義應用程式如何公開服務


# Ingress Controller

實現規則與分流

Ingress Controller 負責監聽 Ingress 管理路由 Nginx 等,Ingress Controller 會根據 Ingress Controler 分配流量到應用程式


# 實作


# 建立 Ingress

手上有三個 service

  1. efk-elasticsearch-client
  2. efk-kibana
  3. hl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress
annotations:
kubernetes.io/ingress.class: "traefik"
traefik.ingress.kubernetes.io/frontend-entry-points: http,https
#traefik.ingress.kubernetes.io/redirect-entry-point: https
#traefik.ingress.kubernetes.io/redirect-permanent: "true"
spec:
ingressClassName: traefik
rules:
- http:
paths:
- path: /es
pathType: Prefix
backend:
service:
name: efk-elasticsearch-client
port:
number: 9200
- path: /kb
pathType: Prefix
backend:
service:
name: efk-kibana
port:
number: 443
- path: /
pathType: Exact
backend:
service:
name: hl
port:
number: 8080



# 建立 Ingress Controller

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

一旦更新或刪除 Ingress 資源,Nginx Ingress Controller 會自動響應並相應地更新或刪除相關的路由規則。


# 參考資料

更新於