K8s之traefik(ingess)發(fā)布服務(wù)實(shí)戰(zhàn)
成都創(chuàng)新互聯(lián)公司服務(wù)項(xiàng)目包括前郭網(wǎng)站建設(shè)、前郭網(wǎng)站制作、前郭網(wǎng)頁制作以及前郭網(wǎng)絡(luò)營銷策劃等。多年來,我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢、行業(yè)經(jīng)驗(yàn)、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機(jī)構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,前郭網(wǎng)站推廣取得了明顯的社會(huì)效益與經(jīng)濟(jì)效益。目前,我們服務(wù)的客戶以成都為中心已經(jīng)輻射到前郭省份的部分城市,未來相信會(huì)繼續(xù)擴(kuò)大服務(wù)區(qū)域并繼續(xù)獲得客戶的支持與信任!上篇描述了基于k8s集群安裝部署traefik作為ingress服務(wù),簡單演示了一下發(fā)布服務(wù),本篇將細(xì)節(jié)講述如果結(jié)合traefik發(fā)布業(yè)務(wù)服務(wù)。
https://blog.51cto.com/michaelkang/2429929
traefik:v1.7
k8s:v1.15.1
如果你的k8s集群已經(jīng)部署完成,想快速部署traefik,執(zhí)行命令如下:
kubectl create -f https://raw.githubusercontent.com/containous/traefik/v1.7/examples/k8s/traefik-rbac.yaml
kubectl create -f https://raw.githubusercontent.com/containous/traefik/v1.7/examples/k8s/traefik-ds.yaml
執(zhí)行成功,在瀏覽器數(shù)據(jù)一個(gè)node節(jié)點(diǎn)的IP地址:8080 端口即可看到traefik的管理頁面。
如果對yaml不太熟悉,看這邊:https://blog.51cto.com/michaelkang/2429745
---
#配置deployment
kind: Deployment
apiVersion: extensions/v1beta1
metadata:
#設(shè)置dm名稱
name: dm-pttest
#添加標(biāo)簽 pttest
labels:
app: pttest
spec:
# 通過replicas聲明pod個(gè)數(shù)是2
replicas: 2
# 通過標(biāo)簽選擇被控制的pod
selector:
matchLabels:
app: pttest
# 在template中定義pod
template:
metadata:
# 給pod打上標(biāo)簽app=pttest
labels:
app: pttest
spec:
containers:
# 聲明容器名稱,注意不是pod名稱,pod名稱應(yīng)該定義在metadata中
- name: myapp
image: ikubernetes/myapp:v1
ports:
- containerPort: 80
---
#服務(wù)配置
apiVersion: v1
# 聲明一個(gè)Service資源對象
kind: Service
metadata:
#pod 名稱
name: svcpttest
labels:
app: pttest
annotations:
#檢查后端服務(wù)返回錯(cuò)誤率,大于%50,踢出集群
traefik.backend.circuitbreaker: "NetworkErrorRatio() > 0.5"
spec:
ports:
- name: http
port: 80
selector:
app: pttest
---
#配置ingress
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: myapp-traefik-ingress
annotations:
kubernetes.io/ingress.class: traefik
spec:
rules:
- host: pttest.pt.com
http:
paths:
- path: /
#指定后端服務(wù)
backend:
serviceName: svcpttest
servicePort: 80
#查看服務(wù)
[root@kubm-02 traefik]# kubectl get svc -o wide
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
svcpttest ClusterIP 10.245.148.114 <none> 80/TCP 2m12s app=pttest <==lable
#查看container
[root@kubm-02 traefik]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
dm-pttest-6f6cd797f5-cdjk5 1/1 Running 0 63s 10.244.3.115 kubnode-01 <none> <none>
dm-pttest-6f6cd797f5-tqh64 1/1 Running 0 63s 10.244.4.135 kubnode-02 <none> <none>
#ingress 信息
[root@kubm-02 traefik]# kubectl get ingress
NAME HOSTS ADDRESS PORTS AGE
myapp-traefik-ingress pttest.pt.com 80 23s
#deployment
[root@kubm-02 traefik]# kubectl get deploy
NAME READY UP-TO-DATE AVAILABLE AGE
dm-pttest 2/2 2 2 12m
請求pttest.pt.com,?服務(wù)svcpttest會(huì)把請求負(fù)載給后端的pod。
#請求兩次分別返回兩個(gè)
[root@kubm-02 traefik]# curl -H "HOST:pttest.pt.com" http://172.20.101.166/hostname.html
dm-pttest-6f6cd797f5-cdjk5
[root@kubm-02 traefik]# curl -H "HOST:pttest.pt.com" http://172.20.101.166/hostname.html
dm-pttest-6f6cd797f5-tqh64
kubectl edit deployment dm-pttest
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
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-49ac47cebd2c
spec:
progressDeadlineSeconds: 2147483647
replicas: 5 《=====pod數(shù)量,有默認(rèn)2個(gè),調(diào)整到5個(gè)
保存退出,k8s集群會(huì)自動(dòng)執(zhí)行;
kubectl get pods
[root@kubm-02 traefik]# kubectl get pods
NAME READY STATUS RESTARTS AGE
dm-pttest-6f6cd797f5-cdjk5 1/1 Running 0 17m
dm-pttest-6f6cd797f5-qd4cl 1/1 Running 0 99s
dm-pttest-6f6cd797f5-r25dc 1/1 Running 0 99s
dm-pttest-6f6cd797f5-tbfmh 1/1 Running 0 99s
dm-pttest-6f6cd797f5-tqh64 1/1 Running 0 17m
#請求
[root@kubm-02 traefik]# curl -H "HOST:pttest.pt.com" http://172.20.101.166/hostname.html
dm-pttest-6f6cd797f5-r25dc
[root@kubm-02 traefik]# curl -H "HOST:pttest.pt.com" http://172.20.101.166/hostname.html
dm-pttest-6f6cd797f5-tbfmh
[root@kubm-02 traefik]# curl -H "HOST:pttest.pt.com" http://172.20.101.166/hostname.html
dm-pttest-6f6cd797f5-tqh64
[root@kubm-02 traefik]# curl -H "HOST:pttest.pt.com" http://172.20.101.166/hostname.html
dm-pttest-6f6cd797f5-cdjk5
[root@kubm-02 traefik]# curl -H "HOST:pttest.pt.com" http://172.20.101.166/hostname.html
dm-pttest-6f6cd797f5-qd4cl
[root@kubm-02 traefik]# curl -H "HOST:pttest.pt.com" http://172.20.101.166/hostname.html
dm-pttest-6f6cd797f5-r25dc
[root@kubm-02 traefik]# curl -H "HOST:pttest.pt.com" http://172.20.101.166/hostname.html
dm-pttest-6f6cd797f5-tbfmh
調(diào)整pod數(shù)量為1;
kubectl scale deployment dm-pttest --replicas=1
調(diào)整pod數(shù)量為2;
kubectl scale deployment dm-pttest --replicas=2
https://kubernetes.io/zh/docs/concepts/services-networking/connect-applications-service/
https://blog.csdn.net/u010606397/article/details/90752262
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。
網(wǎng)站欄目:K8s之traefik(ingess)發(fā)布服務(wù)-實(shí)戰(zhàn)-創(chuàng)新互聯(lián)
標(biāo)題URL:http://www.rwnh.cn/article18/dcidgp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供搜索引擎優(yōu)化、靜態(tài)網(wǎng)站、手機(jī)網(wǎng)站建設(shè)、網(wǎng)站維護(hù)、網(wǎng)站設(shè)計(jì)、網(wǎng)站策劃
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容