使用yaml配置文件管理资源

[root@k8s-master ~]# vim nginx-deployment.yaml

 

apiVersion: apps/v1beta2

kind: Deployment

metadata:

  name: nginx-deployment

spec:

  replicas: 3

  selector:

    matchLabels:

     app: nginx

  template:

    metadata:

     labels:

      app: nginx

    spec:

      containers:

      - name: nginx

        image: nginx:1.10

        ports:

        - containerPort: 80

[root@k8s-master ~]# kubectl create -f nginx-deployment.yaml

[root@k8s-master ~]# kubectl get pod

NAME                                READY     STATUS    RESTARTS   AGE

busybox-5d4f595646-dzjv4            1/1       Running   0          2d

nginx-deployment-58d6d6ccb8-6br4c   1/1       Running   0          1m

nginx-deployment-58d6d6ccb8-6v7m9   1/1       Running   0          1m

nginx-deployment-58d6d6ccb8-8cp7s   1/1       Running   0          1m

 

[root@k8s-master ~]# vim nginx-service.yaml

apiVersion: v1

kind: Service

metadata:

  name: nginx-service

  labels:

    app: nginx

spec:

  ports:

  - port: 88

    targetPort: 80

  selector:

    app: nginx

 

[root@k8s-master ~]# kubectl create -f nginx-service.yaml

[root@k8s-master ~]# kubectl get svc

NAME            TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)   AGE

kubernetes      ClusterIP   10.10.10.1    <none>        443/TCP   4d

nginx-service   ClusterIP   10.10.10.85   <none>        88/TCP    40s

[root@k8s-node1 ~]# curl 10.10.10.85:88

<!DOCTYPE html>

<html>

<head>

<title>Welcome to nginx!</title>

 

[root@k8s-node2 ~]# curl 10.10.10.85:88

<!DOCTYPE html>

<html>

<head>

<title>Welcome to nginx!</title>

 

posted @ 2019-07-08 15:38  #赵程#  阅读(614)  评论(0编辑  收藏  举报