部署node节点
1.安装准备
配置文件地址:
https://github.com/kubernetes/ingress-nginx/tree/master/deploy/static
总共4个文件:
1、namespace.yaml #命名空间,也可以部署在kube-system命名空间(以下部署在kube-system)
kubectl apply -f namespace.yaml
2、rbac.yaml -rbac #用于集群角色授权
kubectl apply -f rbac.yaml
3、configmap.yaml #configmap用于为nginx从外部注入配置
kubectl apply -f configmap.yaml
4、mandatory.yaml #主配置文件
主配置文件修改了几处:
(1)pod数量
(2)使得ingress-nginx-controller运行在node1(双pod node2也运行,),并用hostPort暴露80 443端口:
spec:
hostNetwork: true #修改
# wait up to five minutes for the drain of connections
terminationGracePeriodSeconds: 300
serviceAccountName: nginx-ingress-serviceaccount
...
nodeSelector:
#kubernetes.io/os: linux
node: ingress-nginx-controler-node #修改
...
ports:
- name: http
containerPort: 80
hostPort: 80 #修改
#protocol: TCP
- name: https
containerPort: 443
#protocol: TCP
hostPort: 443 #修改
给node打标签,使得ingress-nginx-controller运行在node1(双pod node2也运行)
kubectl label nodes node1 node=ingress-nginx-controler-node
kubectl label nodes node2 node=ingress-nginx-controler-node
kubectl apply -f mandatory.yaml
kubectl label nodes node2 node- 删除lable
kubectl get node -l "node=ingress-nginx-controler-node"
5、添加别名,方便访问;
vim ~/.bashrc
添加 kk='kubectl -n kube-system'
source ~/.bashrc
6、查看部署的ingress:
kk get rs,pod,svc -o wide | grep ingress
ingress-nginx部署完成。
由于ingress-nginx分别部署在两个node节点中。需要在nginx上做负载均衡
cd /etc/nginx/conf.d/
upstream k8s_ingress {
server 172.17.240.75;
server 172.17.240.76;
}
server {
listen 80;
server_name *.txt-we.com;
access_log /var/log/nginx/txt-we.com.log json;
location / {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://k8s_ingress;
}
}
nginx -t
nginx -s reload