当前位置:网站首页>Several schemes of traffic exposure in kubernetes cluster
Several schemes of traffic exposure in kubernetes cluster
2022-06-24 16:48:00 【KaliArch】
Kubernetes Several schemes of traffic exposure in cluster
One background
Use... In business Kubernetes When editing management , Access to the north-south traffic of the service , stay Kuberentes There are usually several schemes in , This paper briefly introduces the access scheme .
Two Traffic access scheme
Kuberentes The community has adopted the scheme of adding entry points to the cluster , Solve the management of external traffic .
2.1 adopt kube-proxy Acting as agent
Usually in the simplest test or personal development environment , Can pass kubectl port-forward
To start a kube-proxy The internal service of the process agent to the host node where the command is executed , If the host has a public network IP, And the forwarding listening port is 0.0.0.0
You can access the service through the public network , This method can represent a single pod, perhaps deployment, perhaps servcie.
$ kubectl port-forward -h
Forward one or more local ports to a pod. This command requires the node to have 'socat' installed.
Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted.
If there are multiple pods matching the criteria, a pod will be selected automatically. The forwarding session ends
when the selected pod terminates, and rerun of the command is needed to resume forwarding.
Examples:
# Listen on ports 5000 and 6000 locally, forwarding data to/from ports 5000 and 6000 in the pod
kubectl port-forward pod/mypod 5000 6000
# Listen on ports 5000 and 6000 locally, forwarding data to/from ports 5000 and 6000 in a pod selected by the
deployment
kubectl port-forward deployment/mydeployment 5000 6000
# Listen on port 8443 locally, forwarding to the targetPort of the service's port named "https" in a pod selected by
the service
kubectl port-forward service/myservice 8443:https
# Listen on port 8888 locally, forwarding to 5000 in the pod
kubectl port-forward pod/mypod 8888:5000
# Listen on port 8888 on all addresses, forwarding to 5000 in the pod
kubectl port-forward --address 0.0.0.0 pod/mypod 8888:5000
# Listen on port 8888 on localhost and selected IP, forwarding to 5000 in the pod
kubectl port-forward --address localhost,10.19.21.23 pod/mypod 8888:5000
# Listen on a random port locally, forwarding to 5000 in the pod
kubectl port-forward pod/mypod :5000
2.1 NodePort The way
The second most commonly used is NodePort The way , take K8s in service The type of is changed to NodePort The way , You will get a port range of 30000-32767 Host port within the port range , The same host has a public network IP Service exposure can be realized , however NodePort It will occupy the host port , One service Corresponding to one NodePort, This method has only four layers , It can't be done SSL Uninstallation of certificate , If the service is forwarded to a single Node Node NodePort High availability is not possible , It's usually needed in NodePort Add multiple back ends with load balancing before NodePort High availability has been achieved .
2.2 LoadBalance
2.2.1 four layers
Layer 4 traffic forwarding one LB The port of can only correspond to one Service,Servcie Of Type by NodePort, For example, see the figure below ,LoadBalancer Upper 88 The port is forwarded to the back end NodePort Of 32111 port , Corresponding to servcieA;LB Upper 8080 The port is forwarded to the back end NodePort32001 port ; This scheme can be implemented by adding multiple NodePort To achieve high availability , But because of the four layers, it is impossible to realize SSL The uninstall , Corresponding NodePort Need to be in LB Occupy one port .
2.2.2 Seven layers
The seventh floor can be achieved by LB Domain name forwarding , One domain name port corresponds to multiple ports service, As shown in the figure, it can be according to path route ,/cmp Corresponding NodePort Of 32111,/gateway Corresponding NodePort Of 32000 port , Not only can you achieve high availability , And seven layers can realize SSL uninstall .
Currently, the general public cloud LB Levels have four and seven levels of functionality , When used together, flexible business traffic exposure can be achieved .
2.3 Ingress
stay K8s in , There are Ingress Resources to forward a single domain name to according to different paths or other configuration rules K8s Different within the cluster service, But user requests require access ingress Realize the controller's NodePort for example Ingress-nginx Of controller Of service Of NodePort, For specific business domain names, there is generally no port , Therefore, it usually needs a layer in front 80/443 Port forwarding .
commonly Ingress Of controller There are many solutions in the industry , For example, the more famous Ingress—nginx/Ingress-traefik etc. .
2.4 LoadBalancer + Ingress
As shown in the figure below, there is a four layer at the front LB Implement port 80/443 Forward to ingress-provider Of service Of NodePort,K8s There are multiple configurations in the cluster service.
3、 ... and Ingress-nginx Detailed explanation
In the above schemes , Are useful to Ingress,Nginx-ingress by nginx Officially provided implementation K8s ingress Resource plan , meanwhile Kubernetes Based on Nginx Realized Ingress programme .
Nginx Ingress By the resource object Ingress、Ingress controller 、Nginx Three parts ,Ingress The goal of the controller is to build and complete a configuration file (nginx.conf), It mainly detects that the configuration file is overloaded after being changed NGINX Realization , But not just in upstream Overload on change Nginx( Modify when deploying the application Endpoints), Use lua-nginx-module Realization .
According to the figure below, we can better understand Ingress-nginx Usage scenarios of .
The following information is shown in the figure :
- One K8s colony
- Cluster user management 、 user A And the user B, They use Kubernetes API Using clusters .
- client A And the client B, They connect to the application deployed by the corresponding user A and B.
- IC, from Admin Deploy in namespace nginx-ingress Medium pod in , And pass ConfigMap nginx-ingress To configure .Admin Typically, at least two... Are deployed POD To achieve redundancy .IC Use Kubernetes API Get the latest entry resources created in the cluster , And then allocate according to these resources NGINX.
- Applications A By the user A In namespace A Two pods are deployed in the middle . In order to pass through the host A.example.com To their clients ( The client A) Expose applications , user A Create an entry A.
- user B In namespace B There's one in the middle pod Applications for B. In order to pass through the host B.example.com To their clients ( The client B) Expose applications , user B establish VirtualServer B.
- Public endpoint , It is located in IC In front of the pod . This is usually a TCP Load Balancer ( cloud 、 Software or hardware ), Or this load balancer and NodePort Combination of services . client A and B Connect to their applications through public endpoints .
Yellow and purple arrows indicate connections related to client traffic , The black arrow indicates that Kubernetes API The interview of .
For simplicity , There are not many necessary Kubernetes resources , Such as deployment and service , Administrators and users also need to create these resources .
Four other
stay K8s in , Usually cloud vendors LB General cloud vendors provide adaptation CNI, Will be creating K8s Cluster will be created automatically LB Type of servcie, Like Ali's ACK, Tencent's TKE, Huawei's CCE etc. , But in our self built or personal test scenarios , Open source Metallb It's a good choice , Its function is through k8s The original way to provide LB Type of Service Support , Open the box , Of course, there is Qingyun technology KubeSphere The team's open source load balancer plug-in OpenELB, For physical machines (Bare-metal)、 edge (Edge) And a load balancer plug-in designed for a privatized environment , Can be used as Kubernetes、K3s、KubeSphere Of LB The plug-in is exposed outside the cluster “LoadBalancer” Type of service . stay 21 year 11 Month entered CNCF The sandbox (Sandbox) trusteeship , It also solves the problem that users will Kubernetes The cluster is deployed on bare metal , Or privatize the environment, especially the physical machine or edge cluster ,Kubernetes It does not provide LoadBalancer The pain points , Provide the same user experience as cloud based load balancers .
边栏推荐
- API documents are simple and beautiful. It only needs three steps to open
- AI video structured intelligent security platform easycvr intelligent security monitoring scheme for protecting community residents
- A set of very good H3C and Tianrongxin Internet cutover scheme templates, with word document download
- [web] what happens after entering the URL from the address bar?
- Kubernetes 1.20.5 setting up Sentinel
- Coding's first closed door meeting on financial technology exchange was successfully held
- Industrial security experts talk about how to guarantee the safety of data elements in the rapid development of digital economy?
- [idea] dynamic planning (DP)
- [the activity is over, and the list of winners is announced] in March, techo youth university open class demo practice
- How to customize the log output format of zap?
猜你喜欢
Daily algorithm & interview questions, 28 days of special training in large factories - the 15th day (string)
Problems encountered in the work of product manager
Applet - use of template
MySQL learning -- table structure of SQL test questions
Cognition and difference of service number, subscription number, applet and enterprise number (enterprise wechat)
[go] concurrent programming channel
A survey on model compression for natural language processing (NLP model compression overview)
Applet wxss
[leetcode108] convert an ordered array into a binary search tree (medium order traversal)
Ps\ai and other design software pondering notes
随机推荐
How Tencent cloud es achieves cross cluster data copy & lt through reindex; Lower & gt;
Nonholonomic constrained robot
Factory mode
Ramda 鲜为人知的一面
Greenplum role-based fine-grained permission control
During JMeter pressure measurement, time_ The number of requests does not go up due to many waits. The problem is solved
[tke] whether to configure SNAT when the container accesses services outside the node
Markdown syntax -- Formula
The RTSP video structured intelligent analysis platform easynvr stops calling the PTZ interface through the onvif protocol to troubleshoot the pending status
Clickhouse high performance column storage core principle
[tke] troubleshooting tips for container problems
zblog系统实现前台调用当天发布文章数量的教程
How to pop up an alarm through the national standard gb28181 protocol video platform easygbs for mobile detection / perimeter intrusion detection video recording
About with admin option and with grant option
How does the easynvr/easygbs live video platform use Wireshark to capture and analyze data locally?
If only 2 people are recruited, can the enterprise do a good job in content risk control?
跟着Vam一起学习Typescript(第一期)
ClassNotFoundException v/s NoClassDefFoundError
Talk about some good ways to participate in the project
Saying "Dharma" Today: the little "secret" of paramter and localparam