[root@master nginx]# ll
total 16
-rw-r–r-- 1 root root 465 Apr 9 10:12 nginx_deployment.yaml
-rw-r–r-- 1 root root 198 Apr 9 08:04 nginx_pod.yaml
-rw-r–r-- 1 root root 316 Apr 9 09:18 nginx_rc.yaml
-rw-r–r-- 1 root root 174 Apr 9 09:25 nginx_svc.yaml

这是nginx_deployment.yaml文件

[root@master nginx]# cat nginx_deployment.yaml 
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginxdep
  #strategy:   
  #  rollingUpdate:
  #    maxSurge: 1  
  #    maxUnavailable: 1 
  #  type: RollingUpdate
  minReadySeconds: 30
  template:
    metadata:
      labels:
        app: nginxdep
    spec:
      containers:
      - name: nginxdep
        image: 192.168.200.20/library/nginx:1.14
        ports:
        - containerPort: 80

这是nginx_pod.yaml 文件

[root@master nginx]# cat nginx_pod.yaml 
apiVersion: v1
kind: Pod
metadata:
  name: nginx
  labels:
    app: web
spec:
  containers:
    - name: nginx
      image: 192.168.200.10/library/nginx:1.14
      ports:
        - containerPort: 80

这是nginx_rc.yaml

[root@master nginx]# cat nginx_rc.yaml 
apiVersion: v1
kind: ReplicationController
metadata:
  name: nginxrc
spec:
  replicas: 2
  selector:
    app: myweb
  template:
    metadata:
      labels:
        app: myweb
    spec:
      containers:
      - name: myweb
        image: 192.168.200.20/library/nginx:1.7.6
        ports:
        - containerPort: 80

这是nginx_svc.yaml

[root@master nginx]# cat nginx_svc.yaml 
apiVersion: v1
kind: Service
metadata:
  name: nginxrc
spec:
  type: NodePort
  ports:
    - port: 80
      nodePort: 31000
      targetPort: 80
  selector:
    app: nginxrc

启动所有服务

[root@master nginx]#kubectl apply -k ./	#启动所有
Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐