写点什么

安装 Ingress-Nginx

作者:tiandizhiguai
  • 2023-07-18
    浙江
  • 本文字数:2088 字

    阅读完需:约 7 分钟

目前,DHorse(https://gitee.com/i512team/dhorse)只支持 Ingress-nginx 的 Ingress 实现,下面介绍 Ingress-nginx 的安装过程。

下载安装文件

首先,需要匹配 Ingress-nginx 版本和 kubernetes 版本。在https://github.com/kubernetes/ingress-nginx可以找到,如下图所示:



笔者用的 k8s 版本是 v1.21.2,需要安装 Ingress-nginx 的 v1.3.1 版本,下载如下文件:


wget https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.3.1/deploy/static/provider/cloud/deploy.yaml
复制代码

替换镜像地址

查看该文件用到了哪些镜像:


[root@centos05 deployment]# cat deploy.yaml | grep image        image: registry.k8s.io/ingress-nginx/controller:v1.3.1@sha256:54f7fe2c6c5a9db9a0ebf1131797109bb7a4d91f56b9b362bde2abd237dd1974        imagePullPolicy: IfNotPresent        image: registry.k8s.io/ingress-nginx/kube-webhook-certgen:v1.3.0@sha256:549e71a6ca248c5abd51cdb73dbc3083df62cf92ed5e6147c780e30f7e007a47        imagePullPolicy: IfNotPresent        image: registry.k8s.io/ingress-nginx/kube-webhook-certgen:v1.3.0@sha256:549e71a6ca248c5abd51cdb73dbc3083df62cf92ed5e6147c780e30f7e007a47        imagePullPolicy: IfNotPresent
复制代码


可以看出,所用到的镜像不在 docker hub 中,在 registry.k8s.io 中,由于国内的网络问题,拉取不到该仓库的镜像。幸好https://dockerproxy.com/docs提供了镜像代理,按照文档的说明,我们需要把 registry.k8s.io 地址改为 k8s.dockerproxy.com 即可,替换以后的内容为:


registry.k8s.io/ingress-nginx/controller:v1.3.1@sha256:54f7fe2c6c5a9db9a0ebf1131797109bb7a4d91f56b9b362bde2abd237dd1974 ->k8s.dockerproxy.com/ingress-nginx/controller:v1.3.1@sha256:54f7fe2c6c5a9db9a0ebf1131797109bb7a4d91f56b9b362bde2abd237dd1974
复制代码


registry.k8s.io/ingress-nginx/kube-webhook-certgen:v1.3.0@sha256:549e71a6ca248c5abd51cdb73dbc3083df62cf92ed5e6147c780e30f7e007a47 ->k8s.dockerproxy.com/ingress-nginx/kube-webhook-certgen:v1.3.0@sha256:549e71a6ca248c5abd51cdb73dbc3083df62cf92ed5e6147c780e30f7e007a47
复制代码

安装

保存以后,部署 ingress-nginx:


[root@centos05 deployment]# kubectl apply -f deploy.yaml namespace/ingress-nginx createdserviceaccount/ingress-nginx createdserviceaccount/ingress-nginx-admission createdrole.rbac.authorization.k8s.io/ingress-nginx createdrole.rbac.authorization.k8s.io/ingress-nginx-admission createdclusterrole.rbac.authorization.k8s.io/ingress-nginx createdclusterrole.rbac.authorization.k8s.io/ingress-nginx-admission createdrolebinding.rbac.authorization.k8s.io/ingress-nginx createdrolebinding.rbac.authorization.k8s.io/ingress-nginx-admission createdclusterrolebinding.rbac.authorization.k8s.io/ingress-nginx createdclusterrolebinding.rbac.authorization.k8s.io/ingress-nginx-admission createdconfigmap/ingress-nginx-controller createdservice/ingress-nginx-controller createdservice/ingress-nginx-controller-admission createddeployment.apps/ingress-nginx-controller createdjob.batch/ingress-nginx-admission-create createdjob.batch/ingress-nginx-admission-patch createdingressclass.networking.k8s.io/nginx createdvalidatingwebhookconfiguration.admissionregistration.k8s.io/ingress-nginx-admission created
复制代码


查看结果:


[root@centos05 deployment]# kubectl get pods -n ingress-nginx -o wideNAME                                        READY   STATUS      RESTARTS   AGE   IP           NODE       NOMINATED NODE   READINESS GATESingress-nginx-admission-create-fq2kq        0/1     Completed   0          11s   10.32.1.89   centos06   <none>           <none>ingress-nginx-admission-patch-fkphb         0/1     Completed   1          11s   10.32.1.90   centos06   <none>           <none>ingress-nginx-controller-5c79d9494c-rh5rn   0/1     Running     0          11s   10.32.1.91   centos06   <none>           <none>
复制代码


访问 ingress-nginx-controller 的 ip,如下:


[root@centos05 deployment]# curl http://10.32.1.91<html><head><title>404 Not Found</title></head><body><center><h1>404 Not Found</h1></center><hr><center>nginx</center></body></html>
复制代码

验证 Ingress

假如,我们有一个名为 hello-gradle 的应用,并且有一个/hello 的服务接口,并且绑定了名为 www.hello-gradle.com 的域名,如下图所示:


部署完该应用以后,在集群的任意节点配置 host 如下:


[root@centos06 deployment]# vim /etc/hosts10.244.0.13 www.hello-gradle.com
复制代码


然后通过域名访问/hello 服务,如下:


[root@centos05 deployment]# curl http://www.hello-gradle.com/helloHello!
复制代码


用户头像

tiandizhiguai

关注

我笑世人看不穿 2018-11-08 加入

还未添加个人简介

评论

发布
暂无评论
安装Ingress-Nginx_云原生_tiandizhiguai_InfoQ写作社区