编写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 ~