kubernetes安装Ingress-Nginx

kubernetes安装Ingress-Nginx

Ingress-Nginx简介

Ingress-Nginx是一个在Kubernetes集群中管理和配置Ingress资源的开源项目。Ingress是一种Kubernetes API对象,用于管理对集群内部服务的外部访问。Ingress-Nginx通过使用Nginx作为反向代理服务器来实现这一功能。
当我们使用Kubernetes来管理容器化的应用程序时,我们需要一种方式来让外部用户可以访问这些应用程序。这就是Ingress-Nginx的作用。想象一下,应用程序是一个收件箱,而Ingress-Nginx是一个邮递员,负责将外部用户送到正确的收件箱。它在集群内部创建了一个入口点,允许外部用户通过域名或路径访问不同的应用程序。
Ingress-Nginx有几个重要的功能:
路由:Ingress-Nginx能够根据请求的规则和路径将流量发送到相应的应用程序。这就像是邮递员按照地址将邮件送到正确的收件箱。
负载均衡:当有多个副本(Pod)运行相同的应用程序时,Ingress-Nginx可以平衡流量,确保每个副本都能处理请求。这就像是邮递员在快递站中分发包裹,以便每个邮递员都有负担适当的工作量。
安全性:Ingress-Nginx支持加密(SSL/TLS)传输,并可以配置证书,确保在网络上传输的数据是安全的。
虚拟主机:就像一台服务器可以托管多个网站,Ingress-Nginx可以使用域名或虚拟主机来托管多个应用程序。这就像是一台服务器上有多个收件箱。

安装

下载yaml文件,通过yaml安装ingress-nginx

wget https://gitcode.net/mirrors/kubernetes/ingress-nginx/-/blob/master/deploy/static/provider/baremetal/deploy.yaml

修改yaml文件中提供的两个docker镜像地址

apiVersion: apps/v1 kind: Deployment metadata: labels:
app.kubernetes.io/component: controller
app.kubernetes.io/instance: ingress-nginx
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/part-of: ingress-nginx
app.kubernetes.io/version: 1.8.1 name: ingress-nginx-controller namespace: ingress-nginx spec: replicas: 2 minReadySeconds: 0
revisionHistoryLimit: 10 selector:
matchLabels:
app.kubernetes.io/component: controller
app.kubernetes.io/instance: ingress-nginx
app.kubernetes.io/name: ingress-nginx template:
metadata:
labels:
app.kubernetes.io/component: controller
app.kubernetes.io/instance: ingress-nginx
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/part-of: ingress-nginx
app.kubernetes.io/version: 1.8.1
spec:
containers:
- args:
- /nginx-ingress-controller
- --election-id=ingress-nginx-leader
- --controller-class=k8s.io/ingress-nginx
- --ingress-class=nginx
- --configmap=$(POD_NAMESPACE)/ingress-nginx-controller
- --validating-webhook=:8443
- --validating-webhook-certificate=/usr/local/certificates/cert
- --validating-webhook-key=/usr/local/certificates/key
env:
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: LD_PRELOAD
value: /usr/local/lib/libmimalloc.so
image: registry.cn-hangzhou.aliyuncs.com/google_containers/nginx-ingress-controller:v1.8.1 #修改镜像地址
imagePullPolicy: IfNotPresent
lifecycle:

apiVersion: batch/v1 kind: Job metadata: labels:
app.kubernetes.io/component: admission-webhook
app.kubernetes.io/instance: ingress-nginx
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/part-of: ingress-nginx
app.kubernetes.io/version: 1.8.1 name: ingress-nginx-admission-create namespace: ingress-nginx spec:
template:
metadata:
labels:
app.kubernetes.io/component: admission-webhook
app.kubernetes.io/instance: ingress-nginx
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/part-of: ingress-nginx
app.kubernetes.io/version: 1.8.1
name: ingress-nginx-admission-create
spec:
containers:
- args:
- create
- - --host=ingress-nginx-controller-admission,ingress-nginx-controller-admission. ( P O D N A M E S P A C E ) . s v c − − − n a m e s p a c e = (POD_NAMESPACE).svc - --namespace= (PODNAMESPACE).svcnamespace=(POD_NAMESPACE)
- --secret-name=ingress-nginx-admission
env:
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
image: registry.cn-hangzhou.aliyuncs.com/google_containers/kube-webhook-certgen:v20230407 #修改镜像地址
imagePullPolicy: IfNotPresent

执行安装

kubectl apply -f deploy.ymal

你可能感兴趣的:(k8s,kubernetes,nginx,容器,Ingress-Nginx,云原生)