资源下载
IngressController
IngressYAML文章来源地址https://www.toymoban.com/news/detail-731918.html
Ingress安装部署
#1.将下载的ingress.tar.gz通过docker的方式导入harbor仓库
[root@master ingress]# docker load -i ingress.tar.xz
[root@master ingress]# docker images|while read i t _;do
[[ "${t}" == "TAG" ]] && continue
[[ "${i}" =~ ^"harbor:443/".+ ]] && continue
docker tag ${i}:${t} harbor:443/plugins/${i##*/}:${t}
docker push harbor:443/plugins/${i##*/}:${t}
docker rmi ${i}:${t} harbor:443/plugins/${i##*/}:${t}
done
#2.修改YAML文件,YAML文件中的仓库根据自己仓库地址修改
[root@master ingress]# sed -ri 's,^(\s*image: )(.*/)?(.+)@.*,\1harbor:443/plugins/\3,' deploy.yaml
458: image: harbor:443/plugins/controller:v1.5.1
565: image: harbor:443/plugins/kube-webhook-certgen:v20220916-gd32f8c343
614: image: harbor:443/plugins/kube-webhook-certgen:v20220916-gd32f8c343
#3.应用yaml文件
[root@master ingress]# kubectl apply -f deploy.yaml
# 通过标签指定在那台机器上发布应用
[root@master ingress]# kubectl label nodes node-0001 ingress-ready="true"
node/node-0001 labeled
#4.验证后端服务
[root@master ingress]# kubectl -n ingress-nginx get pods
NAME READY STATUS RESTARTS
ingress-nginx-admission-create--1-lm52c 0/1 Completed 0
ingress-nginx-admission-patch--1-sj2lz 0/1 Completed 0
ingress-nginx-controller-5664857866-tql24 1/1 Running 0
[root@master ~]# kubectl get pods,services
NAME READY STATUS RESTARTS AGE
pod/web1 1/1 Running 0 35m
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S)
service/kubernetes ClusterIP 10.245.0.1 <none> 443/TCP
service/mysvc ClusterIP 10.245.1.80 <none> 80/TCP
service/mysvc1 NodePort 10.245.1.88 <none> 80:30080/TCP
[root@master ~]# curl http://10.245.1.80
Welcome to The Apache.
# 5.对外发布服务
[root@master ~]# kubectl get ingressclasses.networking.k8s.io
NAME CONTROLLER PARAMETERS AGE
nginx k8s.io/ingress-nginx <none> 5m7s
# 资源对象模板
[root@master ~]# kubectl create ingress mying --class=nginx --rule=nsd.tedu.cn/*=mysvc:80 --dry-run=client -o yaml
[root@master ~]# vim mying.yaml
---
kind: Ingress
apiVersion: networking.k8s.io/v1
metadata:
name: mying
spec:
ingressClassName: nginx
rules:
- host: nsd.tedu.cn
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: mysvc
port:
number: 80
[root@master ~]# kubectl apply -f mying.yaml
ingress.networking.k8s.io/mying created
[root@master ~]# kubectl get ingress
NAME CLASS HOSTS ADDRESS PORTS
mying nginx nsd.tedu.cn 192.168.1.51 80
[root@master ~]# curl -H "Host: nsd.tedu.cn" http://192.168.1.51
Welcome to The Apache.
文章来源:https://www.toymoban.com/news/detail-731918.html
到了这里,关于Linux学习-kubernetes之Ingress的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!