美文网首页
使用Deployment创建无状态应用

使用Deployment创建无状态应用

作者: AEGQ | 来源:发表于2018-04-17 14:57 被阅读9次

    第一步: 创建 Deployment

    # cat deployment.yml
    
    apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
    kind: Deployment
    metadata:
      name: nginx-deployment
    spec:
      selector:
        matchLabels:
          app: nginx
      replicas: 2 # tells deployment to run 2 pods matching the template
      template: # create pods using pod definition in this template
        metadata:
          # unlike pod-nginx.yaml, the name is not included in the meta data as a unique name is
          # generated from the deployment name
          labels:
            app: nginx
        spec:
          containers:
          - name: nginx
            image: nginx:1.7.9
            ports:
            - containerPort: 80
    
    
    $ kubectl apply -f  ./deployment.yml  
    

    第二步: 更新Deployment

    # cat deployment.yml
    
    apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
    kind: Deployment
    metadata:
      name: nginx-deployment
    spec:
      selector:
        matchLabels:
          app: nginx
      replicas: 2
      template:
        metadata:
          labels:
            app: nginx
        spec:
          containers:
          - name: nginx
            image: nginx:1.8 # Update the version of nginx from 1.7.9 to 1.8
            ports:
            - containerPort: 80
    
    $ kubectl apply -f ./deployment.yml
    

    第三步: 增加副本数扩展服务

    # cat deployment.yml
    
    apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
    kind: Deployment
    metadata:
      name: nginx-deployment
    spec:
      selector:
        matchLabels:
          app: nginx
      replicas: 4 # Update the replicas from 2 to 4
      template:
        metadata:
          labels:
            app: nginx
        spec:
          containers:
          - name: nginx
            image: nginx:1.8
            ports:
            - containerPort: 80
    
    $ kubectl apply -f ./deployment.yml
    

    第四步: 删除Deployment

    kubectl delete deployment nginx-deployment
    

    相关文章

      网友评论

          本文标题:使用Deployment创建无状态应用

          本文链接:https://www.haomeiwen.com/subject/aqzukftx.html