一、方案:以daemonSet方式部署ingress-nginx-controller在k8s各节点上,并基于主机网络。
二、部署
参考:
https://kubernetes.github.io/ingress-nginx/deploy/
https://github.com/kubernetes/ingress-nginx/tree/main
ingress-nginx版本对比K8S版本
1、下载部署文件
wget https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.3.1/deploy/static/provider/cloud/deploy.yaml
2、修改部署文件
注释externalTrafficPolicy: Local
Deployment修改为DaemonSet,添加hostNetwork: true
3、执行部署文件
kubectl apply -f deploy.yaml
三、验证
1、创建nginx deployment和service
nginx.yaml
apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment spec: selector: matchLabels: app: nginx replicas: 1 template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:1.14.2 ports: - containerPort: 80 --- apiVersion: v1 kind: Service metadata: name: nginx-svc labels: app: nginx-svc spec: type: ClusterIP selector: app: nginx ports: - port: 80 targetPort: 80
kubectl apply -f nginx.yaml
2、创建nginx ingress
ingress-nginx.yaml
apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: nginx-ingress spec: ingressClassName: nginx rules: - host: "test.nginx.com" http: paths: - path: / pathType: Prefix backend: service: name: nginx-svc port: number: 80
kubectl apply -f ingress-nginx.yaml
3、本机添加hosts
192.168.152.10 test.nginx.com
4、浏览器访问test.nginx.com
标签:ingress,name,yaml,网络,nginx,80,k8s,com From: https://www.cnblogs.com/chenlin2022/p/16741778.html