安装 ingress-nginx

偏向技术
/ 0 评论 / 176 阅读 / 正在检测是否收录...
温馨提示:
本文最后更新于2022年08月10日,已超过834天没有更新,若内容或图片失效,请留言反馈。

ingress-nginx 是 Kubernetes 的入口控制器,使用 NGINX 作为反向代理和负载均衡器。

K3S 替换 traefik

bash
vi /etc/systemd/system/k3s.service
# 将 --disable traefik 添加到 ExecStart 下,重启 k3s
systemctl daemon-reload && systemctl restart k3s
123

卸载相关资源

bash
kubectl delete -f /var/lib/rancher/k3s/server/manifests/traefik.yaml
1

安装

官方文档

bash
# helm 安装
helm upgrade --install ingress-nginx ingress-nginx \
  --repo https://kubernetes.github.io/ingress-nginx \
  --namespace ingress-nginx --create-namespace

# kubectl 安装
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.3.0/deploy/static/provider/cloud/deploy.yaml
1234567

国内由于无法访问registry.k8s.io,会导致拉取镜像失败,这里使用阿里云镜像来安装registry.aliyuncs.com,具体的需要登录阿里云账号访问,通过deploy.yaml,可以知道主要有以下两个镜像

registry.k8s.io registry.aliyuncs.com
ingress-nginx/controller google_containers/nginx-ingress-controller
ingress-nginx/kube-webhook-certgen google_containers/kube-webhook-certgen

如果通过手动拉取,会因为sha256的值不一样而导致失败,所以这里通过修改deploy.yaml文件来安装,既然registry.k8s.io,那么同理,github 可能也无法访问,这就需要使用代理来实现,这里提供两个代理,raw.fastgit.orgraw.llll.host,如果两个都无法使用,建议部署私有化代理

bash
# 如果此前已经安装,且安装不成功,需要先卸载相关资源
kubectl delete -f https://raw.llll.host/kubernetes/ingress-nginx/controller-v1.3.0/deploy/static/provider/cloud/deploy.yaml

# 如果无法拉取,可将 raw.llll.host 替换为 raw.fastgit.org 试试
wget https://raw.llll.host/kubernetes/ingress-nginx/controller-v1.3.0/deploy/static/provider/cloud/deploy.yaml
# 替换 ingress-nginx/controller 为 google_containers/nginx-ingress-controller
sed -i "s/image: registry\.k8s\.io\/ingress-nginx\/controller\(.*\)@sha256.*/image: registry\.aliyuncs\.com\/google_containers\/nginx-ingress-controller\1/g" deploy.yaml
# 替换 ingress-nginx/kube-webhook-certgen 为 google_containers/kube-webhook-certgen
cat deploy.yaml | sed -i "s/image: registry\.k8s\.io\/ingress-nginx\(.*\)@sha256.*/image: registry\.aliyuncs\.com\/google_containers\1/g" deploy.yaml
# 确认都已替换
cat deploy.yaml | grep "image:"
# 输出如下
# image: registry.aliyuncs.com/google_containers/nginx-ingress-controller:v1.3.0
# image: registry.aliyuncs.com/google_containers/kube-webhook-certgen:v1.1.1
# image: registry.aliyuncs.com/google_containers/kube-webhook-certgen:v1.1.1
# 安装
kubectl apply -f deploy.yaml

# 如果使用过程中出现 x509: certificate signed by unknown authority,执行以下命令
# kubectl delete -A ValidatingWebhookConfiguration ingress-nginx-admission
1234567891011121314151617181920
0

评论 (0)

取消