nginx-ingress-controller operator方式部署
文章目录
前言
最近要求使用operator方式自定义部署nginx-ingress-controller,网上没有案例,这里对自己部署步骤做个记录
一、环境介绍
系统环境:Centos7.9
nginx-ingress-operator:nginx-ingress-helm-operator:v1.2.0
ingress-controller:2.4.1-ubi
nginx-ingress-controller官网:https://docs.nginx.com/nginx-ingress-controller/installation/installation-with-operator/
项目地址:https://github.com/nginxinc/nginx-ingress-helm-operator
对应关系如下:
二、部署步骤
1.使用官方文档部署operator
git clone https://github.com/nginxinc/nginx-ingress-helm-operator/
cd nginx-ingress-helm-operator/
git checkout v1.2.0
make deploy IMG=nginx/nginx-ingress-operator:1.2.0
查看部署结果:
kubectl get deployments -n nginx-ingress-operator-system
NAME READY UP-TO-DATE AVAILABLE AGE
nginx-ingress-operator-controller-manager 1/1 1 1 15s
2.使用自定义资源部署controller
官方资源地址:https://github.com/nginxinc/nginx-ingress-helm-operator/blob/v1.2.0/docs/nginx-ingress-controller.md
可根据官方资源文档自定义需要的配置,我的配置如下(根据官方地址自己添加并修改配置,不配置的默认为默认值)
前提:提前创建namespace和secret(operater目录下都有:nginx-ingress-helm-operator/examples)
apiVersion: charts.nginx.org/v1alpha1
kind: NginxIngress
metadata:name: nginxingress-controllernamespace: nginx-ingress
spec:controller:defaultTLS:secret: nginx-ingress/default-server-secretimage:pullPolicy: IfNotPresentrepository: nginx/nginx-ingresstag: 2.4.1-ubiingressClass: nginxkind: daemonset #修改为daemonsetnginxplus: falsehostNetwork: true #新增机器hostnetworknodeSelector:isIngress: "true" #node标签,自己根据实际情况打标签kubernetes.io/os: linuxnginxStatus: #hostnetwork使用本机ip端口,nginx-controller8080端口和node-local-dns的端口冲突,这里修改端口为8089allowCidrs: 127.0.0.1enable: trueport: 8089service: #这里使用了nodeport,根据实际情况决定,type: NodePortserviceAccount:imagePullSecretName: ""
查看部署结果:(kube-rbac-proxy有可能pull错误,可以使用bitnami/kube-rbac-proxy:1.13.0)
3.实现nginx-ingress-controller高可用(通过nginx实现)
前提:找一台nginx主机,nginx的高可用可以通过keepalive实现,这里先用一个nginx测试
修改nginx配置如下,(我这边用k8s部署了tomcat做测试,ingress规则自己创建如图)
ingress规则
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:name: tomcat-ingress
spec:ingressClassName: nginxrules:- host: k8s1.dawang.comhttp:paths:- backend:service:name: tomcat-httpport:number: 8080path: /pathType: Prefix
访问结果:139为nginx所在机器地址
总结
遇到的问题:nginx-controller启动报错,查看发现是hostnetwork模式下nginx-ingress-controller使用了本地8080端口,node-local-dns也使用了8080端口,查看官方文档nginx-controller默认就是8080端口,可以自行修改,将修改值写入资源就行;
标签:
相关文章
-
无相关信息