Ingress文档地址:Ingress文档
1.安装helm
官网地址:helm官网安装
wget https://get.helm.sh/helm-v3.2.3-linux.amd64.tar.gz
tar -zxvf helm-v3.2.3-linux-amd64.tar.gz
cp linux-amd64/helm /usr/local/bin/
root@master01:~# helm version
version.BuildInfo{Version:"v3.2.3", GitCommit:"8f832046e258e2cb800894579b1b3b50c2d83492", GitTreeState:"clean", GoVersion:"go1.13.12"}
2.安装Ingress控制器
Ingress安装地址:Ingress安装
# 添加仓库
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
# 查看仓库列表
helm repo list
# 搜索ingress-nginx
helm search repo ingress-nginx
# 下载安装包(下载的ingress-nginx版本要与k8s的版本所匹配)
helm pull ingress-nginx/ingress-nginx --version=4.4.2
mv ingress-nginx-4.4.2.tgz helm/
tar -zxvf helm/ingress-nginx-4.4.2.tgz
3.配置Ingress-nginx
cd ingress-nginx
# 修改values.yaml
# 镜像地址:修改为国内镜像
registry: registry.cn-hangzhou.aliyuncs.com
image: google_containers/nginx-ingress-controller
# 修改kube-webhook字段
registry: registry.cn-hangzhou.aliyuncs.com
image: google_containers/kube-webhook-certgen
# 修改部署配置的kind:DaemonSet (按需修改!!!!)
nodeSelector:
ingress: "true" # 增加选择器,如果node上有ingress=true就部署
# 修改为如下内容(按需修改!!!!)
# 使用本机网络
hostNetwork:true
# 这个值是 ClusterFirst 的一个特殊变体,仅在Pod具有 hostNetwork: true 设置时有效。当Pod设置为使用宿主机网络(即 hostNetwork 设置为 true)时,Pod中的容器将直接使用宿主机的网络命名空间,这意味着它们不会使用Kubernetes的DNS服务。在这种情况下,dnsPolicy: ClusterFirstWithHostNet 确保Pod中的容器能够使用宿主机的DNS设置。
dnsPolicy: ClusterFirstWithHostNet
# 将admissionWebhooks.enabled 修改为false
# 将service中的type由LoadBalancer修改为ClusterIP,如果服务器是云平台才用LoadBalancer
type: ClusterIP
# 创建ns
kubectl create ns ingress-nginx
# 为需要部署ingress的节点加上标签
kubectl label node node2 ingress=true
# 查看标签
kubectl get nodes --show-labels
# 安装ingress-nginx
helm install ingress-nginx -n ingress-nginx .
# 卸载
helm uninstall ingress-nginx -n ingress-nginx
# 查看
root@master01:~# kubectl get pod -n ingress-nginx
NAME READY STATUS RESTARTS AGE
ingress-nginx-controller-7npl8 1/1 Running 0 31m
root@master01:~# kubectl get po -n ingress-nginx -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
ingress-nginx-controller-7npl8 1/1 Running 0 32m 192.168.91.152 node02 <none> <none>