您好,登錄后才能下訂單哦!
這篇文章主要講解了“Kubernetes怎么部署ReplicationController多副本負載均衡”,文中的講解內容簡單清晰,易于學習與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學習“Kubernetes怎么部署ReplicationController多副本負載均衡”吧!
java基礎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文件, 創建了2個friend的pod,設置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. 創建Service## svc.yaml文件, 監聽本地物理機的 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; } }
設置worker數量為10,并且把30000端口添加到防火墻例外。 訪問 http://192.168.1.221:30000端口即可。
##5. 測試## 可以看到有兩個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
發送4個請求。其實我發送了上千個請求,怕這里寫不下了。
[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個Pod分別2個Response,多副本的RR負載均衡工作的很棒。
# 第一個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 # 和第二個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多副本負載均衡”的內容了,經過本文的學習后,相信大家對Kubernetes怎么部署ReplicationController多副本負載均衡這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是億速云,小編將為大家推送更多相關知識點的文章,歡迎關注!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。