编写Service.yml文件
[root@master ~]# cat nginx.yml
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
spec:
replicas: 2
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
volumes:
- name: webstorage
hostPath:
path: /var/www/html
containers:
- name: web
image: nginx
imagePullPolicy: IfNotPresent
volumeMounts:
- name: webstorage
mountPath: /usr/share/nginx/html
...
---
apiVersion: v1
kind: Service
metadata:
name: web
spec:
type: NodePort
ports:
- port: 80
targetPort: 80
protocol: TCP
nodePort: 30000
selector:
app: nginx
执行
[root@master ~]# kubectl apply -f nginx.yml
deployment.apps/web created
service/web created
查看
[root@master ~]# kubectl get pod
NAME READY STATUS RESTARTS AGE
web-6cfcd88d4-4rh75 1/1 Running 0 5s
web-6cfcd88d4-ql4k6 1/1 Running 0 5s
[root@master ~

本文介绍了如何通过编写Service.yml文件在Kubernetes集群中创建Service,并利用另一台主机上的Nginx进行负载均衡配置,包括修改Nginx配置、重启Nginx以及进行访问测试。
最低0.47元/天 解锁文章
1424

被折叠的 条评论
为什么被折叠?



