部署nginx服务
# 部署nginx服务
这是Hello World级别的教程笔记, 大神勿喷..
# 部署Pod
nginx-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
默认部署在default namespace
kubectl apply -f nginx-deployment.yaml
1
查看deployment
kubectl get deployment
1
查看部署的pod
kubectl get pod
1
# 部署service
nginx-service.yaml
apiVersion: v1
kind: Service
metadata:
name: nginx-service
labels:
app: nginx
spec:
ports:
- port: 12580
targetPort: 80
selector:
app: nginx
type: NodePort
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
发布服务
kubectl create -f nginx-service.yaml
1
查看已发布的服务
ubuntu@master:~$ kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 3h22m
nginx-service NodePort 10.111.51.126 <none> 12580:30297/TCP 7m19s
1
2
3
4
2
3
4
可以看到外部端口为30297
上次更新: 2020/06/11, 18:06:00