K8s之traefik(ingess)发布服务-实战

网友投稿 377 2022-09-08

K8s之traefik(ingess)发布服务-实战

K8s之traefik(ingess)发布服务实战

上篇描述了基于k8s集群安装部署traefik作为ingress服务,简单演示了一下发布服务,本篇将细节讲述如果结合traefik发布业务服务。

安装部署参考:

​​create -f create -f 端口即可看到traefik的管理页面。

实战开始

编写一个业务yaml文件

如果对yaml不太熟悉,看这边:​​traefik]# kubectl get svc -o wideNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTORsvcpttest ClusterIP 10.245.148.114 80/TCP 2m12s app=pttest <==lable#查看container[root@kubm-02 traefik]# kubectl get pods -o wideNAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATESdm-pttest-6f6cd797f5-cdjk5 1/1 Running 0 63s 10.244.3.115 kubnode-01 dm-pttest-6f6cd797f5-tqh54 1/1 Running 0 63s 10.244.4.135 kubnode-02 #ingress 信息[root@kubm-02 traefik]# kubectl get ingress NAME HOSTS ADDRESS PORTS AGEmyapp-traefik-ingress pttest.pt.com 80 23s#deployment[root@kubm-02 traefik]# kubectl get deployNAME READY UP-TO-DATE AVAILABLE AGEdm-pttest 2/2 2 2 12m

验证访问:

请求pttest.pt.com, 服务svcpttest会把请求负载给后端的pod。

#请求两次分别返回两个[root@kubm-02 traefik]# curl -H "HOST:pttest.pt.com" traefik]# curl -H "HOST:pttest.pt.com" edit deployment dm-pttest

apiVersion: extensions/v1beta1kind: Deploymentmetadata: annotations: deployment.kubernetes.io/revision: "1" creationTimestamp: "2019-08-16T10:13:49Z" generation: 1 labels: app: pttest name: dm-pttest namespace: default resourceVersion: "3871589" selfLink: /apis/extensions/v1beta1/namespaces/default/deployments/dm-pttest uid: 153a60fb-66df-4884-aa9a-49ac47cebd2cspec: progressDeadlineSeconds: 2147483647 replicas: 5 《=====pod数量,有默认2个,调整到5个保存退出,k8s集群会自动执行;

验证

kubectl get pods

[root@kubm-02 traefik]# kubectl get podsNAME READY STATUS RESTARTS AGEdm-pttest-6f6cd797f5-cdjk5 1/1 Running 0 17mdm-pttest-6f6cd797f5-qd4cl 1/1 Running 0 99sdm-pttest-6f6cd797f5-r25dc 1/1 Running 0 99sdm-pttest-6f6cd797f5-tbfmh 1/1 Running 0 99sdm-pttest-6f6cd797f5-tqh54 1/1 Running 0 17m#请求[root@kubm-02 traefik]# curl -H "HOST:pttest.pt.com" traefik]# curl -H "HOST:pttest.pt.com" traefik]# curl -H "HOST:pttest.pt.com" traefik]# curl -H "HOST:pttest.pt.com" traefik]# curl -H "HOST:pttest.pt.com" traefik]# curl -H "HOST:pttest.pt.com" traefik]# curl -H "HOST:pttest.pt.com" scale deployment dm-pttest --replicas=1调整pod数量为2;kubectl scale deployment dm-pttest --replicas=2

参考文档

​​https://kubernetes.io/zh/docs/concepts/services-networking/connect-applications-service/​

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:kubernetes Ingress 之 Traefik 各种姿势
下一篇:三巨头扎堆上半区,今年法网签表足够硬核!
相关文章

 发表评论

暂时没有评论,来抢沙发吧~