helm是用于ingress nginx controller部署的一个客户端工具,有专用的服务站点和资源仓库。
helm官方网站链接
一、仓库添加:
1 )Add Repository (stable)
$ helm repo add nginx-stable https://helm.nginx.com/stable
$ helm repo update
Add Repository (experimental)
$ helm repo add nginx-edge https://helm.nginx.com/edge
$ helm repo update
2 )Install Packages (stable)
$ helm install my-release nginx-stable/nginx-ingress [--version 0.4.1]
Install Packages (experimental)
$ helm install my-release nginx-edge/nginx-ingress --devel
二、清理old
1 删除namespace:
root@k8s-master:~# kubectl delete ns ingress-nginx
2 删除类:
root@k8s-master:~# kubectl get ingressClass
NAME CONTROLLER PARAMETERS AGE
nginx k8s.io/ingress-nginx <none> 33h
root@k8s-master:~# kubectl delete ingressClass nginx
ingressclass.networking.k8s.io "nginx" deleted
root@k8s-master:~# kubectl get ingressClass
No resources found
root@k8s-master:~#
三、安装ingress nginx controller
1 查看仓库列表:
root@k8s-master:~/work/ing# helm repo list
NAME URL
nginx-stable https://helm.nginx.com/stable
root@k8s-master:~/work/ing#
2 安装ingress-nginx-controller:
root@k8s-master:~/work/ing# helm upgrade --install ingress-nginx nginx-stable/nginx-ingress --namespace ingress-nginx --create-namespace --set controller.service.type=NodePort --set controller.admissionWebhooks.enabled=false
Release "ingress-nginx" does not exist. Installing it now.
NAME: ingress-nginx
LAST DEPLOYED: Mon Feb 7 15:15:20 2022
NAMESPACE: ingress-nginx
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
The NGINX Ingress Controller has been installed.
root@k8s-master:~/work/ing#
3 查看创建好的ingress nginx controller资源:
root@k8s-master:~/work/ing# kubectl get ns
NAME STATUS AGE
default Active 4d1h
ingress-nginx Active 50s
kube-node-lease Active 4d1h
kube-public Active 4d1h
kube-system Active 4d1h
root@k8s-master:~/work/ing# kubectl get pods -n ingress-nginx
NAME READY STATUS RESTARTS AGE
ingress-nginx-nginx-ingress-5bb65cf4c5-5xvrg 1/1 Running 0 62s
root@k8s-master:~/work/ing#
root@k8s-master:~/work/ing#
root@k8s-master:~/work/ing# kubectl get deploy -n ingress-nginx
NAME READY UP-TO-DATE AVAILABLE AGE
ingress-nginx-nginx-ingress 1/1 1 1 68s
root@k8s-master:~/work/ing#
root@k8s-master:~/work/ing#
root@k8s-master:~/work/ing# kubectl get svc -n ingress-nginx
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
ingress-nginx-nginx-ingress NodePort 10.10.247.243 <none> 80:32185/TCP,443:32507/TCP 73s
root@k8s-master:~/work/ing#
4 查看ingress nginx controller的版本:
root@k8s-master:~/work/ing# kubectl exec -it ingress-nginx-nginx-ingress-5bb65cf4c5-5xvrg -n ingress-nginx /bin/bash
kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead.
nginx@ingress-nginx-nginx-ingress-5bb65cf4c5-5xvrg:/$
nginx@ingress-nginx-nginx-ingress-5bb65cf4c5-5xvrg:/$ ./nginx-ingress --version
Version=2.1.0 GitCommit=2665e338252db9a183aed31ad230c2665ce1ffb1 Date=2022-01-06T16:46:37Z
nginx@ingress-nginx-nginx-ingress-5bb65cf4c5-5xvrg:/$
5 修改pod副本数量:
root@k8s-master:~/work/ing# kubectl get deploy -n ingress-nginx
NAME READY UP-TO-DATE AVAILABLE AGE
ingress-nginx-nginx-ingress 1/1 1 1 17m
root@k8s-master:~/work/ing#
root@k8s-master:~/work/ing# kubectl edit deploy ingress-nginx-nginx-ingress -n ingress-nginx
修改pods共享host node 的网络:
查看ingress nginx controller pod 暴露的访问节点:
查看ingress nginx controller 暴露的访问端口:
四、测试ingress
1 部署deploy、service、ingress
root@k8s-master:~/work/ing# kubectl apply -f delopy1.yaml
deployment.apps/deployment1 created
service/svc-1 created
root@k8s-master:~/work/ing# kubectl apply -f delopy2.yaml
deployment.apps/deployment2 created
service/svc-2 created
root@k8s-master:~/work/ing#
root@k8s-master:~/work/ing# kubectl apply -f ingress-rule.yaml
ingress.networking.k8s.io/ingress1 created
ingress.networking.k8s.io/ingress2 created
root@k8s-master:~/work/ing#
2 通过service访问pod:
root@k8s-master:~/work/ing# kubectl get svc -o wide
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
kubernetes ClusterIP 10.10.0.1 <none> 443/TCP 4d2h <none>
svc-1 NodePort 10.10.197.22 <none> 80:31416/TCP,443:32649/TCP 98s app=nginx-1
svc-2 NodePort 10.10.69.243 <none> 80:32713/TCP,443:30281/TCP 95s app=nginx-2
root@k8s-master:~/work/ing#
root@k8s-master:~/work/ing#
root@k8s-master:~/work/ing# curl 10.10.197.22
Hello MyApp | Version: v1 | <a href="hostname.html">Pod Name</a>
root@k8s-master:~/work/ing# curl 10.10.197.22
Hello MyApp | Version: v1 | <a href="hostname.html">Pod Name</a>
root@k8s-master:~/work/ing#
root@k8s-master:~/work/ing#
root@k8s-master:~/work/ing# curl 10.10.69.243
Hello MyApp | Version: v2 | <a href="hostname.html">Pod Name</a>
root@k8s-master:~/work/ing# curl 10.10.69.243
Hello MyApp | Version: v2 | <a href="hostname.html">Pod Name</a>
root@k8s-master:~/work/ing#
3 通过ingress访问pod:
vim /etc/hosts添加以下内容:
192.168.1.101 k8s-master
192.168.1.102 k8s-node1
192.168.1.103 k8s-node2
192.168.1.103 www1.atguigu.com
192.168.1.103 www2.atguigu.com
192.168.1.102 www1.atguigu.com
192.168.1.102 www2.atguigu.com
snap 安装k8s组件:
snap remove kubelet
snap remove kubeadm
snap remove kubectl
snap remove kube-proxy
exit
snap install kubelet --channel=1.23/stable --classic
snap install kubeadm --channel=1.23/stable --classic
snap install kubectl --channel=1.23/stable --classic
snap install kube-proxy --channel=1.23/stable --classic