這篇文章主要講解了“Kubernetes怎么部署ReplicationController多副本負(fù)載均衡”,文中的講解內(nèi)容簡單清晰,易于學(xué)習(xí)與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“Kubernetes怎么部署ReplicationController多副本負(fù)載均衡”吧!
紅古網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián),紅古網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為紅古上千余家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\外貿(mào)網(wǎng)站建設(shè)要多少錢,請找那個(gè)售后服務(wù)好的紅古做網(wǎng)站的公司定做!
java基礎(chǔ)image:
FROM dockerimages.yinnut.com:15043/centos:7 MAINTAINER xuelun-infra morgan.wu@yinnnut.com ADD jdk-8u60-linux-x64.tar.gz /usr/local/ ENV JAVA_HOME /usr/local/jdk1.8.0_60 ENV PATH $JAVA_HOME/bin:$PATH
Friend-Service鏡像:
FROM dockerimages.yinnut.com:15043/yinnut-java:0.1 MAINTAINER xuelun-infra morgan.wu@yinnnut.com ADD FriendService.war / ADD jetty-runner.jar / WORKDIR / VOLUME ["/var/log"]
rc.yaml文件, 創(chuàng)建了2個(gè)friend的pod,設(shè)置replicas為2
apiVersion: v1 kind: ReplicationController metadata: name: friend-service spec: replicas: 2 template: metadata: labels: yinnut-svc: "friend" version: "0.1" spec: containers: - name: friend-service image: dockerimages.yinnut.com:15043/friend-service:0.1 ports: - containerPort: 9999 protocol: TCP command: ["java"] args: ["-jar","jetty-runner.jar","--port","9999","--log","jetty.log","FriendService.war"]
##3. 創(chuàng)建Service## svc.yaml文件, 監(jiān)聽本地物理機(jī)的 127.0.0.1:30001端口
apiVersion: v1 kind: Service metadata: name: friendsvc labels: yinnut-svc: friend spec: type: NodePort ports: - port: 9999 protocol: TCP targetPort: 9999 name: http nodePort: 30001 selector: yinnut-svc: friend
##4. 搭建Nginx反向代理## 安裝:
yum install -y http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm yum install nginx -y
配置 /etc/nginx/conf.d/default.conf
server { listen 30000; server_name localhost; location / { port_in_redirect on; proxy_pass http://127.0.0.1:30001; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }
設(shè)置worker數(shù)量為10,并且把30000端口添加到防火墻例外。 訪問 http://192.168.1.221:30000端口即可。
##5. 測試## 可以看到有兩個(gè)Friend的Pod
[root@centos7-node-221 ~]$ kubectl get po NAME READY STATUS RESTARTS AGE busybox 1/1 Running 296 12d friend-service-38riq 1/1 Running 0 6h friend-service-nn0qt 1/1 Running 0 11m
發(fā)送4個(gè)請求。其實(shí)我發(fā)送了上千個(gè)請求,怕這里寫不下了。
[root@centos7-node-221 ~]$ for i in {1..4}; do time curl http://192.168.1.221:30000/user/1/friend; done {"rc":0,"val":[{"friendUserId":2,"friendUserName":"who","close":false}]} real 0m0.029s user 0m0.004s sys 0m0.003s {"rc":0,"val":[{"friendUserId":2,"friendUserName":"who","close":false}]} real 0m0.039s user 0m0.001s sys 0m0.004s {"rc":0,"val":[{"friendUserId":2,"friendUserName":"who","close":false}]} real 0m0.028s user 0m0.002s sys 0m0.004s {"rc":0,"val":[{"friendUserId":2,"friendUserName":"who","close":false}]} real 0m0.035s user 0m0.003s sys 0m0.002s
2個(gè)Pod分別2個(gè)Response,多副本的RR負(fù)載均衡工作的很棒。
# 第一個(gè)Pod 172.16.91.0 - - [11/Oct/2015:12:33:51 +0000] "GET //192.168.1.221/user/1/friend HTTP/1.0" 200 72 172.16.91.0 - - [11/Oct/2015:12:33:51 +0000] "GET //192.168.1.221/user/1/friend HTTP/1.0" 200 72 # 和第二個(gè)Pod 172.16.91.1 - - [11/Oct/2015:12:33:51 +0000] "GET //192.168.1.221/user/1/friend HTTP/1.0" 200 72 172.16.91.1 - - [11/Oct/2015:12:33:51 +0000] "GET //192.168.1.221/user/1/friend HTTP/1.0" 200 72
感謝各位的閱讀,以上就是“Kubernetes怎么部署ReplicationController多副本負(fù)載均衡”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對Kubernetes怎么部署ReplicationController多副本負(fù)載均衡這一問題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是創(chuàng)新互聯(lián),小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!
本文題目:Kubernetes怎么部署ReplicationController多副本負(fù)載均衡
網(wǎng)站地址:http://jinyejixie.com/article8/peoeop.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信小程序、網(wǎng)站建設(shè)、響應(yīng)式網(wǎng)站、網(wǎng)站排名、企業(yè)網(wǎng)站制作、全網(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)