将"游戏镜像部署到K8S集群",使用任意3个游戏镜像即可,要求使用不同的svc暴露服务,并使用负载均衡实现基于80端访问所有的游戏;
nginx 配置:
[root@web03 /etc/nginx/conf.d]#cat lbporxy.conf
server {
listen 80;
server_name game01.baimei.com;
location / {
proxy_pass http://10.0.0.233:40001;
include proxy_params;
}
}
server {
listen 80;
server_name game02.baimei.com;
location / {
proxy_pass http://10.0.0.233:40002;
include proxy_params;
}
}
server {
listen 80;
server_name game03.baimei.com;
location / {
proxy_pass http://10.0.0.233:40003;
include proxy_params;
}
}
[root@web03 /etc/nginx]#cat proxy_params
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 30;
proxy_send_timeout 60;
proxy_read_timeout 60;
proxy_buffering on;
proxy_buffer_size 32k;
proxy_buffers 4 128k;
资源清单:
[root@master231 /manifests/classroomExercises/loadbalance]#cat 1pod-game.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: deploy-nginx-v1-1
labels:
apps: myweb
spec:
replicas: 1
selector:
matchExpressions:
- key: apps
values:
- "v1"
- "v2"
operator: NotIn
template:
metadata:
labels:
# apps: v1
school: baimei
spec:
containers:
- name: v1
image: harbor.baimei.com/baimei-games/games:v0.5
#image: harbor.baimei.com/baimei-apps/apps:v2
---
apiVersion: v1
kind: Service
metadata:
name: deploy-v1-1
spec:
type: NodePort
selector:
# apps: v1
school: baimei
ports:
- port: 8888
targetPort: 80
nodePort: 40001
[root@master231 /manifests/classroomExercises/loadbalance]#cat 2pod-game.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: deploy-nginx-v1-2
labels:
apps: myweb
spec:
replicas: 1
selector:
matchExpressions:
- key: apps
values:
- "v1"
- "v2"
operator: NotIn
template:
metadata:
labels:
# apps: v1
school: baimei
spec:
containers:
- name: v1
image: harbor.baimei.com/baimei-games/games:v0.5
#image: harbor.baimei.com/baimei-apps/apps:v2
---
apiVersion: v1
kind: Service
metadata:
name: deploy-v1-2
spec:
type: NodePort
selector:
# apps: v1
school: baimei
ports:
- port: 8888
targetPort: 80
nodePort: 40002
[root@master231 /manifests/classroomExercises/loadbalance]#cat 3pod-game.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: deploy-nginx-v1-3
labels:
apps: myweb
spec:
replicas: 1
selector:
matchExpressions:
- key: apps
values:
- "v1"
- "v2"
operator: NotIn
template:
metadata:
labels:
# apps: v1
school: baimei
spec:
containers:
- name: v1
image: harbor.baimei.com/baimei-games/games:v0.5
#image: harbor.baimei.com/baimei-apps/apps:v2
---
apiVersion: v1
kind: Service
metadata:
name: deploy-v3
spec:
type: NodePort
selector:
# apps: v1
school: baimei
ports:
- port: 8888
targetPort: 80
nodePort: 40003