参考文档

1
https://github.com/kubernetes/ingress-nginx/blob/main/docs/deploy/index.md

因为官方提供的yaml文件中有部分内容国内访问不到,需要使用国内镜像,先将yaml文件下载至本地

1
2
3
4
5
# 官方命令
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.1.1/deploy/static/provider/baremetal/deploy.yaml

# 下载至本地
wget https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.1.1/deploy/static/provider/baremetal/deploy.yaml

在国外服务器上pull对应的镜像并将其pushhub.docker.com

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 查询deploy.yaml中使用到的镜像
[dev_user@master ~]$ grep image deploy.yaml
image: k8s.gcr.io/ingress-nginx/controller:v1.1.1@sha256:0bc88eb15f9e7f84e8e56c14fa5735aaa488b840983f87bd79b1054190e660de
imagePullPolicy: IfNotPresent
image: k8s.gcr.io/ingress-nginx/kube-webhook-certgen:v1.1.1@sha256:64d8c73dca984af206adf9d6d7e46aa550362b1d7a01f3a0a91b20cc67868660
imagePullPolicy: IfNotPresent
image: k8s.gcr.io/ingress-nginx/kube-webhook-certgen:v1.1.1@sha256:64d8c73dca984af206adf9d6d7e46aa550362b1d7a01f3a0a91b20cc67868660
imagePullPolicy: IfNotPresent

# 在国外服务器上pull
[root@host1 ~]# docker pull k8s.gcr.io/ingress-nginx/controller:v1.1.1
[root@host1 ~]# docker pull k8s.gcr.io/ingress-nginx/kube-webhook-certgen:v1.1.1
# 给镜像打标签
[root@host1 ~]# docker tag k8s.gcr.io/ingress-nginx/controller:v1.1.1 nasus/ingress-nginx-controller:v1.1.1
[root@host1 ~]# docker tag k8s.gcr.io/ingress-nginx/kube-webhook-certgen:v1.1.1 nasus/ingress-nginx-kube-webhook-certgen:v1.1.1
[root@host1 ~]# docker push nasus/ingress-nginx-controller:v1.1.1
[root@host1 ~]# docker push nasus/ingress-nginx-kube-webhook-certgen:v1.1.1

修改deploy.yml中对应的镜像并在Deployment中添加hostNetwork,增加nodeSelector的标签kubernetes.io/hostname: master

1
2
3
4
5
6
spec:
hostNetwork: true

nodeSelector:
kubernetes.io/os: linux
kubernetes.io/hostname: master