kubernetes搭建 十、deployment和service的yaml配置文件示例
1、输出json格式的配置文件,比较乱,所以推荐使用yaml格式的配置文件[root@k8s-master-101 ~]# kubectl get pod busybox-5fb9cd66d6-flf6r -o json2、输出yaml格式的配置文件kubectl get pod busybox-5fb9cd66d6-flf6r -o yaml3、deployment配置文件示例m...
·
1、输出json格式的配置文件,比较乱,所以推荐使用yaml格式的配置文件
[root@k8s-master-101 ~]# kubectl get pod busybox-5fb9cd66d6-flf6r -o json
2、输出yaml格式的配置文件
kubectl get pod busybox-5fb9cd66d6-flf6r -o yaml
3、deployment配置文件示例
mkdir yaml_test
cd yaml_test/
[root@k8s-master-101 yaml_test]# cat nginx-deployment.yaml
apiVersion: apps/v1beta2
kind: Deployment
metadata:
name: nginx-deployment
namespace: default
labels:
web: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.10
ports:
- containerPort: 80
4、labels标签 放在metadata里,selector选择器中匹配的标签要和template模板中的标签一致,后面创建的service中选择器匹配的也是这个标签
创建deployment
[root@k8s-master-101 yaml_test]# kubectl create -f nginx-deployment.yaml
deployment.apps/nginx-deployment created
#生成的pod
[root@k8s-master-101 yaml_test]# kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE
busybox-5fb9cd66d6-flf6r 1/1 Running 0 89m 172.17.71.7 10.0.0.103 <none>
nginx-deployment-67dccb759c-4jdtj 1/1 Running 0 35s 172.17.50.2 10.0.0.102 <none>
nginx-deployment-67dccb759c-h9mdd 1/1 Running 0 35s 172.17.71.6 10.0.0.103 <none>
nginx-deployment-67dccb759c-jjs6q 1/1 Running 0 35s 172.17.71.5 10.0.0.103 <none>
#可以看到生成的标签为app=nginx
[root@k8s-master-101 yaml_test]# kubectl get pod --show-labels
NAME READY STATUS RESTARTS AGE LABELS
busybox-5fb9cd66d6-flf6r 1/1 Running 0 92m pod-template-hash=5fb9cd66d6,run=busybox
nginx-deployment-67dccb759c-4jdtj 1/1 Running 0 3m36s app=nginx,pod-template-hash=67dccb759c
nginx-deployment-67dccb759c-h9mdd 1/1 Running 0 3m36s app=nginx,pod-template-hash=67dccb759c
nginx-deployment-67dccb759c-jjs6q 1/1 Running 0 3m36s app=nginx,pod-template-hash=67dccb759c
5、service的配置文件示例
这里的selector标签选择器选择的标签为上面depoyment中pod的选择器标签app: nginx
[root@k8s-master-101 yaml_test]# cat nginx-service.yaml
apiVersion: v1
kind: Service
metadata:
name: nginx-service
labels:
app: nginx
spec:
ports:
- port: 88
targetPort: 80
selector:
app: nginx
6、创建service
kubectl create -f nginx-service.yaml
7、查看状态
[root@k8s-master-101 yaml_test]# kubectl get all
NAME READY STATUS RESTARTS AGE
pod/busybox-5fb9cd66d6-flf6r 1/1 Running 0 95m
pod/nginx-deployment-67dccb759c-4jdtj 1/1 Running 0 6m42s
pod/nginx-deployment-67dccb759c-h9mdd 1/1 Running 0 6m42s
pod/nginx-deployment-67dccb759c-jjs6q 1/1 Running 0 6m42s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 10.10.10.1 <none> 443/TCP 19d
service/nginx-service ClusterIP 10.10.10.229 <none> 88/TCP 3s
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
deployment.apps/busybox 1 1 1 1 95m
deployment.apps/nginx-deployment 3 3 3 3 6m42s
NAME DESIRED CURRENT READY AGE
replicaset.apps/busybox-5fb9cd66d6 1 1 1 95m
replicaset.apps/nginx-deployment-67dccb759c 3 3 3 6m42s
更多推荐
已为社区贡献9条内容
所有评论(0)