一、Ingress 安装部署
官方网站地址:
https://kubernetes.io/zh/docs/concepts/services-networking/ingress-controllers/
https://kubernetes.github.io/ingress-nginx/deploy/
1、下载镜像
sudo wget https://raw.githubusercontent.com/kubernetes/ingress-nginx/nginx-0.30.0/deploy/static/mandatory.yaml
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/nginx-0.30.0/deploy/static/mandatory.yaml
docker pull quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.30.0 #拉取镜像到本地
kubectl apply -f mandatory.yaml
kubectl get pod -n ingress-nginx #查看
2、查看日志,发现service缺少
sudo wget https://raw.githubusercontent.com/kubernetes/ingress-nginx/nginx-0.30.0/deploy/static/provider/baremetal/service-nodeport.yaml
[wjjk8s@server1 manifest]$ kubectl apply -f service-nodeport.yaml
[wjjk8s@server1 manifest]$ kubectl -n ingress-nginx describe svc ingress-nginx
3、编写单服务ingress文件
[wjjk8s@server1 manifest]$ kubectl delete -f service.yaml
[wjjk8s@server1 manifest]$ kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 12d
myservice ClusterIP 10.97.108.71 <none> 80/TCP 4s
4、创建ingress
[wjjk8s@server1 manifest]$ kubectl apply -f ingress.yaml
[wjjk8s@server1 manifest]$ kubectl get ingress
NAME CLASS HOSTS ADDRESS PORTS AGE
ingress-demo <none> * 80 9s
[wjjk8s@server1 manifest]$ kubectl -n ingress-nginx get svc #查看端口,使用ip:端口号网页查询
5、创建域名解析
[wjjk8s@server1 manifest]$ vim ingress.yaml
[wjjk8s@server1 manifest]$ kubectl apply -f ingress.yaml
[wjjk8s@server1 manifest]$ kubectl get ingress
NAME CLASS HOSTS ADDRESS PORTS AGE
ingress-demo <none> www1.westos.org 80 9m44s
[wjjk8s@server1 manifest]$ kubectl describe ingress ingress-demo
vim /etc/hosts #外部将域名做解析
6、发现实现负载均衡,两个域名一个两个服务,访问不同域名不同服务
www1.westos.org - myservice
www2.westos.org - mynginx
[wjjk8s@server1 manifest]$ cp deployment.yaml ingress2.yaml
[wjjk8s@server1 manifest]$ cat service.yaml >> ingress2.yaml
[wjjk8s@server1 manifest]$ cat ingress.yaml >> ingress2.yaml
[wjjk8s@server1 manifest]$ kubectl apply -f ingress2.yaml
[wjjk8s@server1 manifest]$ kubectl get ingress
[wjjk8s@server1 manifest]$ kubectl describe ingress ingress-demo2
7、测试访问同一域名,不同的路径时,调度到不同的后端