这篇文章主要讲解了“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进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。