Ingress
Links
Ingress Controller
ΠΠ±ΡΠ΅ΠΊΡ ΡΠ»ΡΠΆΠΈΡ Π² ΡΠΎΠ»ΠΈ ΠΏΡΠΎΠΊΡΠΈ ΠΈ Π±Π°Π»Π°Π½ΡΠΈΡΠΎΠ²ΡΠΈΠΊΠ° L7.
Π‘ΠΎΠ·Π΄Π°Π½ΠΈΠ΅ ΠΌΠΈΠ½ΠΈΠΌΠ°Π»ΡΠ½ΠΎΠ³ΠΎ ingress:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: minimal-ingress-controller
spec:
replicas: 1
selector:
matchLabels:
name: nginx-ingress
template:
metadata:
labels:
name: nginx-ingress
spec:
containers:
- name: nginx-ingress-controller
image: quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.21.0
args:
- /nginx-ingress-controller
- --configmap=$ (POD_NAMESPACE)/nginx_configuraruin
env: # nginx ΡΡΠ΅Π±ΡΠ΅Ρ 2 ΠΏΠ΅ΡΠ΅ΠΌΠ΅Π½Π½ΡΠ΅ Π΄Π»Ρ ΠΊΠΎΠ½ΡΠΈΠ³ΡΡΠ°ΡΠΈΠΈ
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
ports:
- name: http
containerPort: 80
- name: https
containerPort: 443
ΠΠ»Ρ ΠΊΠΎΠ½ΡΠΈΠ³ΡΡΠ°ΡΠΈΠΈ ingress Π½Π° nginx ΡΠ°ΠΊΠΆΠ΅ Π½ΡΠΆΠ΅Π½ ConfigMap. Π Π½Π΅Π³ΠΎ Π·Π°ΠΊΠ»Π°Π΄ΡΠ²Π°Π΅ΡΡΡ ΠΊΠΎΠ½ΡΠΈΠ³ΡΡΠ°ΡΠΈΡ nginx, ΠΊΠΎΡΠΎΡΠ°Ρ Π² ΠΎΠ±ΡΡΠ½ΠΎΠΌ Π²Π°ΡΠΈΠ°Π½ΡΠ΅ nginx ΠΊΠ°ΠΊ reverse-proxy Π²ΠΏΠΈΡΡΠ²Π°Π»Π°ΡΡ Π² config ΡΠ°ΠΌΠΎΠ³ΠΎ nginx:
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-configuration
Π’Π°ΠΊΠΆΠ΅ Π½Π΅ΠΎΠ±Ρ ΠΎΠ΄ΠΈΠΌΠΎ ΡΠΎΠ·Π΄Π°ΡΡ Service, ΠΊΠΎΡΠΎΡΡΠΉ ΠΏΡΠ±Π»ΠΈΠΊΡΠ΅Ρ ingress Π²ΠΎΠ²Π½Π΅:
apiVersion: v1
kind: Service
metadata:
name: nginx-ingress
spec:
type: NodePort
ports:
- port: 80
targetPort: 80
protocol: TCP
name: http
- port: 443
targetPort: 443
protocol: TCP
name: https
selector:
name: nginx-ingress
Π Π½ΡΠΆΠ΅Π½ Service Account Π΄Π»Ρ Π°ΡΡΠ΅Π½ΡΠΈΡΠΈΠΊΠ°ΡΠΈΠΈ:
apiVersion: v1
kind: ServiceAccount
metadata:
name: nginx-ingress-serviceaccounts
Ingress Resource
ΠΠ°Π±ΠΎΡ ΠΏΡΠ°Π²ΠΈΠ» ingress Π½Π°Π·ΡΠ²Π°ΡΡΡΡ Ingress Resource.
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ingress-rules
spec:
backend:
serviceName: app-service
servicePort: 80
ΠΠΏΡΠ΅Π΄Π΅Π»Π΅Π½ΠΈΠ΅ Π½Π°Ρ ΠΎΠΆΠ΄Π΅Π½ΠΈΡ ΠΏΡΠ°Π²ΠΈΠ» ingress resource:
kubectl get ingress -A # Π½Π°ΠΉΡΠΈ Ingress Resource ΡΡΠ΅Π΄ΠΈ Namespaces
Π Π΅Π΄Π°ΠΊΡΠΈΡΠΎΠ²Π°Π½ΠΈΠ΅ ΠΏΡΠ°Π²ΠΈΠ» ingress resource:
kubectl edit ingress <ΠΈΠΌΡ ingress resource> -n <namespace>
Nginx rewrite rules
ΠΠ°ΡΡΡΠΎΠΉΠΊΠ° rewrite-target
Π½ΡΠΆΠ½Π°, ΡΡΠΎΠ±Ρ ΠΏΡΠ°Π²ΠΈΠ»ΡΠ½ΠΎ ΡΡΠ°Π½ΡΠ»ΠΈΡΠΎΠ²Π°ΡΡ ΡΠ΅ΡΠ΅Π²ΠΎΠΉ ΠΏΡΡΡ.
# ΠΠ΅Π· rewrite-target:
http://<ingress-service>:<ingress-port>/watch --> http://<watch-service>:<port>/path
# Π‘ rewrite-target ΡΠΈΠΏΠ° replace("/path","/"):
http://<ingress-service>:<ingress-port>/watch --> http://<watch-service>:<port>/
ΠΠ»Ρ Π²ΠΊΠ»ΡΡΠ΅Π½ΠΈΡ ΠΏΡΠ°Π²ΠΈΠ» rewrite, Π½ΡΠΆΠ½ΠΎ Π΄ΠΎΠ±Π°Π²ΠΈΡΡ Π² ΠΌΠ°Π½ΠΈΡΠ΅ΡΡ annotations:
1. apiVersion: extensions/v1beta1
2. kind: Ingress
3. metadata:
4. name: test-ingress
5. namespace: critical-space
6. annotations: # ΠΏΡΠΈΠΌΠ΅Π½Π΅Π½ΠΈΠ΅ rewrite ΠΏΡΠ°Π²ΠΈΠ»
7. nginx.ingress.kubernetes.io/rewrite-target: /
8. spec:
9. rules:
10. - http:
11. paths:
12. - path: /pay
13. backend:
14. serviceName: pay-service
15. servicePort: 8282