当前位置:网站首页>Cloud native essay solicitation progress case practice
Cloud native essay solicitation progress case practice
2022-06-24 13:29:00 【51CTO】
Ingress Case actual combat
One 、 Basic configuration
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: itlanson-ingress
namespace: default
spec:
rules:
- host: itlanson.com
http:
paths:
- path: /
pathType: Prefix
backend: ## Specify the back-end service that needs to respond
service:
name: my-nginx-svc ## kubernetes Clustered svc name
port:
number: 80 ## service Port number
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- pathType detailed :
-
Prefix
: Based on/
separated URL Path prefix matching . Matching is case sensitive , And complete the elements in the path one by one . The path element refers to the path element created by/
List of labels in the path separated by the separator . If each p All request paths p Element prefix of , Then request and path p matching . -
Exact
: Exactly match URL route , And case sensitive . -
ImplementationSpecific
: For this path type , The matching method depends on IngressClass. The specific implementation can regard it as a separatepathType
Dealing with or relating toPrefix
orExact
The type is treated the same .
ingress The rules will take effect to all in accordance with IngressController Of a machine nginx To configure .
Two 、 Default backend
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: itlanson-ingress
namespace: default
spec:
defaultBackend: ## Specify all unmatched default backend
service:
name: php-apache
port:
number: 80
rules:
- host: itlanson.com
http:
paths:
- path: /abc
pathType: Prefix
backend:
service:
name: my-nginx-svc
port:
number: 80
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
effect
- itlanson.com Under the Not /abc All requests at the beginning , All will be here defaultBackend
- Not itlanson.com All requests under the domain name , It's going to be defaultBackend
nginx Global configuration for
Edit configuration plus On
data:
Configuration item : Configuration values
All configuration item references
https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/configmap Based on the environment variable
3、 ... and 、 The path to rewrite
Rewrite - NGINX Ingress Controller
Rewrite function , It is often used in scenes with front and back separation
- The front end sends a message to the server / Request mapping front-end address .
- The back end sends a message to the server /api The request comes to the corresponding service . But back-end services don't /api Start path of , So we need to ingress-controller Automatic string cutting
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations: ## Write well annotion
#https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/
nginx.ingress.kubernetes.io/rewrite-target: /$2 ### Which part only
name: rewrite-ingress-02
namespace: default
spec:
rules: ## Write the rules
- host: itlanson.com
http:
paths:
- backend:
service:
name: php-apache
port:
number: 80
path: /api(/|$)(.*)
pathType: Prefix
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
Four 、 To configure SSL
TLS/HTTPS - NGINX Ingress Controller
Generate Certificate :( You can also go to Qingyun to apply for a free certificate for configuration )
$ openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout ${KEY_FILE:tls.key} -out ${CERT_FILE:tls.cert} -subj "/CN= ${HOST:itlanson.com} /O= ${HOST:itlanson.com} "
kubectl create secret tls ${CERT_NAME:itlanson-tls} --key ${KEY_FILE:tls.key} --cert ${CERT_FILE:tls.cert}
## The example command is as follows
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout tls.key -out tls.cert -subj "/CN=it666.com/O=it666.com"
kubectl create secret tls it666-tls --key tls.key --cert tls.cert
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
apiVersion: v1
data:
tls.crt: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURJekNDQWd1Z0F3SUJBZ0lKQVB6YXVMQ1ZjdlVKTUEwR0NTcUdTSWIzRFFFQkN3VUFNQ2d4RWpBUUJnTlYKQkFNTUNXbDBOalkyTG1OdmJURVNNQkFHQTFVRUNnd0phWFEyTmpZdVkyOXRNQjRYRFRJeE1EVXhNREV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jMmVCZHRCb0orClNqSy9xWXRTeEhRb3FlNmh6ZU5oRkN2Nnc3Q0F2WXEvUG1pdnZ2eWhsd0dvc3I1RHpxRFJUd091cFJ2cXE0aUsKWU9ObnVGU0RNRVlBOHNQSzhEcWxpeHRocGNYNVFnOHI4UkhSVWswQ2dZQlF3WFdQU3FGRElrUWQvdFg3dk1mTwp3WDdWTVFMK1NUVFA4UXNRSFo2djdpRlFOL3g3Vk1XT3BMOEp6TDdIaGdJV3JzdkxlV1pubDh5N1J3WnZIbm9zCkY3dkliUm00L1Y1YzZHeFFQZXk5RXVmWUw4ejRGMWhSeUc2ZjJnWU1jV25NSWpnaUh2dTA3cStuajFORkh4YVkKa2ZSSERia01YaUcybU42REtyL3RtQT09Ci0tLS0tRU5EIFBSSVZBVEUgS0VZLS0tLS0K
kind: Secret
metadata:
creationTimestamp: "2022-06-10T12:06:22Z"
name: it666-tls
namespace: default
resourceVersion: "2264722"
uid: 16f8a4b6-1600-4ded-8458-b0480ce075ba
type: kubernetes.io/tls
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
Configure domain name usage certificate
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: itlanson-ingress
namespace: default
spec:
tls:
- hosts:
- itlanson.com
secretName: itlanson-tls
rules:
- host: itlanson.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: my-nginx-svc
port:
number: 80
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
Configure the certificate , Access to the domain name , Will default to https
5、 ... and 、 The speed limit
Annotations - NGINX Ingress Controller
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-222333
namespace: default
annotations: ## annotation
nginx.ingress.kubernetes.io/limit-rps: "1" ### Current limiting configuration
spec:
defaultBackend: ## As long as the mapping path is not specified
service:
name: php-apache
port:
number: 80
rules:
- host: it666.com
http:
paths:
- path: /bbbbb
pathType: Prefix
backend:
service:
name: cluster-service-222
port:
number: 80
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
6、 ... and 、 Grayscale Publishing -Canary
Used to be able to use k8s Of Service coordination Deployment Deploy canaries . The principle is as follows
shortcoming :
- Cannot customize grayscale logic , For example, specify the user to perform grayscale analysis
Now you can use Ingress Go gray . The principle is as follows
## Use the following file to deploy two service edition .v1 Version returns nginx Default page ,v2 Version returns 11111
apiVersion: v1
kind: Service
metadata:
name: v1-service
namespace: default
spec:
selector:
app: v1-pod
type: ClusterIP
ports:
- name: http
port: 80
targetPort: 80
protocol: TCP
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: v1-deploy
namespace: default
labels:
app: v1-deploy
spec:
selector:
matchLabels:
app: v1-pod
replicas: 1
template:
metadata:
labels:
app: v1-pod
spec:
containers:
- name: nginx
image: nginx
---
apiVersion: v1
kind: Service
metadata:
name: canary-v2-service
namespace: default
spec:
selector:
app: canary-v2-pod
type: ClusterIP
ports:
- name: http
port: 80
targetPort: 80
protocol: TCP
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: canary-v2-deploy
namespace: default
labels:
app: canary-v2-deploy
spec:
selector:
matchLabels:
app: canary-v2-pod
replicas: 1
template:
metadata:
labels:
app: canary-v2-pod
spec:
containers:
- name: nginx
image: registry.cn-hangzhou.aliyuncs.com/lanson_k8s_images/nginx-test:env-msg
- 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.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
- 54.
- 55.
- 56.
- 57.
- 58.
- 59.
- 60.
- 61.
- 62.
- 63.
- 64.
- 65.
- 66.
- 67.
- 68.
- 69.
- 70.
- 71.
- 72.
7、 ... and 、 Conversation retention -Session Affinity
https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#session-affinityhttps://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#session-affinity First visit ,ingress-nginx It will return to the browser Cookie, In the future, the browser will take this Cookie, Make sure the visit is always before arrival Pod;
## Deploy one or three Pod Of Deployment And set up Service
apiVersion: v1
kind: Service
metadata:
name: session-affinity
namespace: default
spec:
selector:
app: session-affinity
type: ClusterIP
ports:
- name: session-affinity
port: 80
targetPort: 80
protocol: TCP
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: session-affinity
namespace: default
labels:
app: session-affinity
spec:
selector:
matchLabels:
app: session-affinity
replicas: 3
template:
metadata:
labels:
app: session-affinity
spec:
containers:
- name: session-affinity
image: nginx
- 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.
Write a session friendly ingress
### Use each request to carry the same cookie, To identify whether it is the same session
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: session-test
namespace: default
annotations:
nginx.ingress.kubernetes.io/affinity: "cookie"
nginx.ingress.kubernetes.io/session-cookie-name: "itlanson-session"
spec:
rules:
- host: it666.com
http:
paths:
- path: / ### If the same function of this path under this domain name has been configured before , Take effect for the last time
pathType: Prefix
backend:
service:
name: session-affinity ###
port:
number: 80
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
【 This article is participating in the cloud native prize essay solicitation activity 】, Activity Links :https://ost.51cto.com/posts/12598
边栏推荐
- 关于被黑数据库那些事
- 开发者调查:Rust/PostgreSQL 最受喜爱,PHP 薪水偏低
- Cohere、OpenAI、AI21联合发布部署模型的最佳实践准则
- Sqlserver 2000 has long-lasting vitality
- Attack Science: ARP attack
- 初中级开发如何有效减少自身的工作量?
- 1、贪吃蛇游戏设计
- #yyds干货盘点# 解决剑指offer:调整数组顺序使奇数位于偶数前面(二)
- [one picture series] one picture to understand Tencent Qianfan apaas
- Nifi from introduction to practice (nanny level tutorial) - environment
猜你喜欢
Getting started with the go Cobra command line tool
不用Home Assistant,智汀也开源接入HomeKit、绿米设备?
CVPR 2022 | 美團技術團隊精選論文解讀
Main steps of system test
Teach you how to use airtestide to connect your mobile phone wirelessly!
Preparation and operation & Maintenance Guide for 'high concurrency & high performance & high availability service program'
‘高并发&高性能&高可用服务程序’编写及运维指南
The data value reported by DTU cannot be filled into Tencent cloud database through Tencent cloud rule engine
Creation and use of unified links in Huawei applinking
go Cobra命令行工具入门
随机推荐
CVPR 2022 | 美团技术团队精选论文解读
On the difference between process and thread
Resolve symbol conflicts for dynamic libraries
SYSTEMd common component description
YOLOv6:又快又准的目标检测框架开源啦
Use abp Zero builds a third-party login module (I): Principles
强化学习之父Richard Sutton论文:追寻智能决策者的通用模型
Integrate API interface parameter Dictionary of accounts of multiple local distribution companies - Express 100
Memory introduction
Detailed explanation of abstractqueuedsynchronizer, the cornerstone of thread synchronization
快速了解常用的消息摘要算法,再也不用担心面试官的刨根问底
Summary of the process of restoring damaged data in MySQL database
[log service CLS] Tencent cloud log service CLS accesses CDN
Cohere、OpenAI、AI21联合发布部署模型的最佳实践准则
I enlighten a friend and my personal understanding of the six patriarchs' Tan Jing
Process basic properties
1、贪吃蛇游戏设计
我開導一個朋友的一些話以及我個人對《六祖壇經》的一點感悟
39 - read XML node and attribute values
Party, Google's autoregressive Wensheng graph model