自建kubernetes中安装ingress

avatar 2023年3月13日18:28:09 评论 290 次浏览

ingress的主要目的是为了控制用户请求pod的一个入口,当然了,如果使用nodeport的方式更简单点,但是我需要给很多个服务设置端口,这种请求方式不太能接受,而且如果我使用nginx通过代理的方式转发到ingress上,然后在ingress中配置域名解析,我就可以把nginx的代理层当成我的LoadBalancer,后期我只需要配置域名解析就可以了。好了,理想很丰满,现实点看是操作吧。因为我是从官方下载的。

 [wolf@wulaoer.org 🔥🔥🔥🔥 ]$ wget -cO ingress.yml https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.1.0/deploy/static/provider/cloud/deploy.yaml

下载后先别急着apply,因为文件中的镜像服务器是国外是,直接在的kubernets环境中是拉不下镜像的,所以我们需要现在自己机器上通过翻墙拉取镜像后,然后在push到自己的仓库中,最后把文件中镜像明替换一下即可。

 [wolf@wulaoer.org 🔥🔥🔥🔥 ]$ cat ingress.yml | grep image
           image: k8s.gcr.io/ingress-nginx/controller:v1.1.0@sha256:f766669fdcf3dc26347ed273a55e754b427eb4411ee075a53f30718b4499076a
           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
 

这里其实是两个镜像,分别是kube-webhook和controller,然后在传到自己的仓库中即可。我这里下载后就传到自己的hub仓库了,有需要的可以自行下载即可。

 [wolf@wulaoer.org 🔥🔥🔥🔥 ]$ docker images
 REPOSITORY                                               TAG                                                     IMAGE ID       CREATED         SIZE
 wolf27w/ingress-nginx/controllerv1.1.0                   latest                                                  ae1a7201ec95   15 months ago   285MB
 k8s.gcr.io/ingress-nginx/controller                      <none>                                                  ae1a7201ec95   15 months ago   285MB
 wolf27w/ingress-nginx/kube-webhook-certgen               v1.1.1                                                  c41e9fcadf5a   17 months ago   47.7MB
 k8s.gcr.io/ingress-nginx/kube-webhook-certgen            <none>                                                  c41e9fcadf5a   17 months ago   47.7MB

给镜像打个tag,然后传到我自己的仓库中。

 [wolf@wulaoer.org 🔥🔥🔥🔥 ]$ docker tag ae1a7201ec95 wolf27w/ingress-controller:v1.1.0 
 [wolf@wulaoer.org 🔥🔥🔥🔥 ]$ docker push wolf27w/ingress-controller:v1.1.0
 The push refers to repository [docker.io/wolf27w/ingress-controller]
 1da3c77c05ac: Pushed 
 1442cff66b8e: Pushed 
 2fc9eef73951: Pushed 
 d36a04670af2: Pushed 
 b94180ef4d62: Pushed 
 986ee27cd832: Pushed 
 7ce1915c5c10: Pushed 
 a933df9f49bb: Pushed 
 8f757e3fe5e4: Pushed 
 0d5022138006: Pushed 
 ad20729656ef: Pushed 
 ab1476f3fdd9: Pushed 
 e2eb06d8af82: Pushed 
 v1.1.0: digest: sha256:4f5df867e9367f76acfc39a0f85487dc63526e27735fa82fc57d6a652bafbbf6 size: 3050
 [wolf@wulaoer.org 🔥🔥🔥🔥 ]$ docker tag c41e9fcadf5a  wolf27w/ingress-web:v1.1.1
 [wolf@wulaoer.org 🔥🔥🔥🔥 ]$ docker push wolf27w/ingress-web:v1.1.1
 The push refers to repository [docker.io/wolf27w/ingress-web]
 ce7a3c1169b6: Layer already exists 
 c0d270ab7e0d: Layer already exists 
 v1.1.1: digest: sha256:78351fc9d9b5f835e0809921c029208faeb7fbb6dc2d3b0d1db0a6584195cfed size: 739

然后就在ingress.yml 文件中修改镜像地址即可,修改后,就可以安装了。在可以连接集群的节点上执行即可。

 [wolf@wulaoer.org 🔥🔥🔥🔥 ]$ kubectl apply -f ingress.yml
 [wolf@wulaoer.org 🔥🔥🔥🔥 ]$ kubectl get pod -n ingress-nginx
 NAME                                       READY   STATUS    RESTARTS      AGE
 ingress-nginx-controller-67bf74dbb-m2cbd   1/1     Running   1 (13h ago)   16h

默认会安装在ingress-nginx命名空间下,有需要修改的直接在yml文件修改即可,下个章节看一下如何让nginx反向代理到ingress上。

avatar

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: