[!NOTE]
下载的Nginx Controller helm chart版本必须跟当前k8s版本兼容
官方参考地址:https://github.com/kubernetes/ingress-nginx/
Supported Versions table
Supported | Ingress-NGINX version | k8s supported version | Alpine Version | Nginx Version | Helm Chart Version |
---|---|---|---|---|---|
🔄 | v1.12.0 | 1.32, 1.31, 1.30, 1.29, 1.28 | 3.21.0 | 1.25.5 | 4.12.0 |
🔄 | v1.12.0-beta.0 | 1.32, 1.31, 1.30, 1.29, 1.28 | 3.20.3 | 1.25.5 | 4.12.0-beta.0 |
🔄 | v1.11.4 | 1.30, 1.29, 1.28, 1.27, 1.26 | 3.21.0 | 1.25.5 | 4.11.4 |
🔄 | v1.11.3 | 1.30, 1.29, 1.28, 1.27, 1.26 | 3.20.3 | 1.25.5 | 4.11.3 |
🔄 | v1.11.2 | 1.30, 1.29, 1.28, 1.27, 1.26 | 3.20.0 | 1.25.5 | 4.11.2 |
🔄 | v1.11.1 | 1.30, 1.29, 1.28, 1.27, 1.26 | 3.20.0 | 1.25.5 | 4.11.1 |
🔄 | v1.11.0 | 1.30, 1.29, 1.28, 1.27, 1.26 | 3.20.0 | 1.25.5 | 4.11.0 |
v1.10.6 | 1.30, 1.29, 1.28, 1.27, 1.26 | 3.21.0 | 1.25.5 | 4.10.6 | |
v1.10.5 | 1.30, 1.29, 1.28, 1.27, 1.26 | 3.20.3 | 1.25.5 | 4.10.5 | |
v1.10.4 | 1.30, 1.29, 1.28, 1.27, 1.26 | 3.20.0 | 1.25.5 | 4.10.4 | |
v1.10.3 | 1.30, 1.29, 1.28, 1.27, 1.26 | 3.20.0 | 1.25.5 | 4.10.3 | |
v1.10.2 | 1.30, 1.29, 1.28, 1.27, 1.26 | 3.20.0 | 1.25.5 | 4.10.2 | |
v1.10.1 | 1.30, 1.29, 1.28, 1.27, 1.26 | 3.19.1 | 1.25.3 | 4.10.1 | |
v1.10.0 | 1.29, 1.28, 1.27, 1.26 | 3.19.1 | 1.25.3 | 4.10.0 | |
v1.9.6 | 1.29, 1.28, 1.27, 1.26, 1.25 | 3.19.0 | 1.21.6 | 4.9.1 | |
v1.9.5 | 1.28, 1.27, 1.26, 1.25 | 3.18.4 | 1.21.6 | 4.9.0 | |
v1.9.4 | 1.28, 1.27, 1.26, 1.25 | 3.18.4 | 1.21.6 | 4.8.3 | |
v1.9.3 | 1.28, 1.27, 1.26, 1.25 | 3.18.4 | 1.21.6 | 4.8.* | |
v1.9.1 | 1.28, 1.27, 1.26, 1.25 | 3.18.4 | 1.21.6 | 4.8.* | |
v1.9.0 | 1.28, 1.27, 1.26, 1.25 | 3.18.2 | 1.21.6 | 4.8.* | |
v1.8.4 | 1.27, 1.26, 1.25, 1.24 | 3.18.2 | 1.21.6 | 4.7.* | |
v1.7.1 | 1.27, 1.26, 1.25, 1.24 | 3.17.2 | 1.21.6 | 4.6.* | |
v1.6.4 | 1.26, 1.25, 1.24, 1.23 | 3.17.0 | 1.21.6 | 4.5.* | |
v1.5.1 | 1.25, 1.24, 1.23 | 3.16.2 | 1.21.6 | 4.4.* | |
v1.4.0 | 1.25, 1.24, 1.23, 1.22 | 3.16.2 | 1.19.10† | 4.3.0 | |
v1.3.1 | 1.24, 1.23, 1.22, 1.21, 1.20 | 3.16.2 | 1.19.10† | 4.2.5 |
我使用的是k8s是1.20.15版本,所以选择 4.2.5 安装
Ingress Nginx Controller 安装
首先安装 Helm
wget https://get.helm.sh/helm-v3.6.3-linux-amd64.tar.gz
tar -zxvf helm-v3.6.3-linux-amd64.tar.gz
mv linux-amd64/helm /usr/local/bin/helm
helm version
将ingress的仓库添加到helm
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
helm repo update
helm repo list
指定Helm chart版本,下载ingress nginx controller安装包
helm pull ingress-nginx/ingress-nginx --version 4.2.5
tar zvxf ingress-nginx-4.2.5.tgz
解压并更改对应的配置
tar zvxf ingress-nginx-4.2.5.tgz
cd ingress-nginx
vim values.yaml
需要修改values.yaml相关配置
a) 修改Controller 和 admissionWebhook 的镜像地址为国内地址
推荐一个国内镜像网站:渡渡鸟镜像同步站
#用我的也可以
registry.cn-hangzhou.aliyuncs.com/docker_yusir/ingress:v1.3.0
registry.cn-hangzhou.aliyuncs.com/docker_yusir/kube-webhook-certgen:v1.3.0
b) 镜像的 digest 值注释
c) hostNetwork 设置为 true
d) dnsPolicy 设置为 ClusterFirstWithHostNet
e) nodeSelector 添加 ingress: "true"部署至指定节点
f) 类型更改为 kind: DaemonSet
g) ingress nginx 设置为默认的 ingressClass
部署 ingress ,给需要部署 ingress 的节点上打标签
kubectl label node k8s-node02 ingress=true
kubectl create ns ingress-nginx
helm install ingress-nginx -n ingress-nginx .
#安装错误,重新更新/卸载
helm upgrade ingress-nginx -n ingress-nginx
helm uninstall ingress-nginx -n ingress-nginx
检查是否安装成功
helm list -n ingress-nginx
kubectl get svc -n ingress-nginx
kubectl get daemonset -n ingress-nginx
kubectl get po -n ingress-nginx
#部署ingress的node节点执行
netstat -lntup |grep "80"
ps -ef|grep nginx
Ingress Nginx 入门使用
创建一个用于学习 Ingress 的 Namespace,之后所有的操作都在此 Namespace 进行:
kubectl create ns study-ingress
创建一个简单的 Nginx 模拟 Web 服务:
kubectl create deploy nginx --image=registry.cn-hangzhou.aliyuncs.com/docker_yusir/nginx:alpine -n study-ingress
然后创建该 Web 容器的 Service:
kubectl expose deploy nginx --port 80 -n study-ingress
之后创建 Ingress 指向上面创建的 Service:
vim web-ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:name: nginx-ingressnamespace: study-ingress
spec:rules:- host: nginx.test.comhttp:paths:- backend:service:name: nginxport:number: 80path: /pathType: ImplementationSpecific
创建并验证 Ingress:
kubectl create -f web-ingress.yaml
curl -H "Host:nginx.test.com" 10.0.0.205 #使用本地host配置浏览器访问也可