博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
K8S控制器Deployment
阅读量:2337 次
发布时间:2019-05-10

本文共 4981 字,大约阅读时间需要 16 分钟。

简述

Deployment为Pod和ReplicaSet提供了一个声明式定义(declarative)方法,用来替代以前的ReplicationController来方便的管理应用。典型的应用场景包括:

  • 定义Deployment来创建Pod和ReplicaSet
  • 滚动升级和回滚应用
  • 扩容和缩容
  • 暂停和继续Deployment

 

replication controller与deployment的区别

replication controller

  • Replication Controller为Kubernetes的一个核心内容,应用托管到Kubernetes之后,需要保证应用能够持续的运行,Replication Controller就是这个保证的key,主要的功能如下:
  • 确保pod数量:它会确保Kubernetes中有指定数量的Pod在运行。如果少于指定数量的pod,Replication Controller会创建新的,反之则会删除掉多余的以保证Pod数量不变。
  • 确保pod健康:当pod不健康,运行出错或者无法提供服务时,Replication Controller也会杀死不健康的pod,重新创建新的。
  • 弹性伸缩 :在业务高峰或者低峰期的时候,可以通过Replication Controller动态的调整pod的数量来提高资源的利用率。同时,配置相应的监控功能(Hroizontal Pod Autoscaler),会定时自动从监控平台获取Replication Controller关联pod的整体资源使用情况,做到自动伸缩。
  • 滚动升级:滚动升级为一种平滑的升级方式,通过逐步替换的策略,保证整体系统的稳定,在初始化升级的时候就可以及时发现和解决问题,避免问题不断扩大。

Deployment

Deployment同样为Kubernetes的一个核心内容,主要职责同样是为了保证pod的数量和健康,90%的功能与Replication Controller完全一样,可以看做新一代的Replication Controller。但是,它又具备了Replication Controller之外的新特性:
Replication Controller全部功能:Deployment继承了上面描述的Replication Controller全部功能。

  • 事件和状态查看:可以查看Deployment的升级详细进度和状态。
  • 回滚:当升级pod镜像或者相关参数的时候发现问题,可以使用回滚操作回滚到上一个稳定的版本或者指定的版本。
  • 版本记录: 每一次对Deployment的操作,都能保存下来,给予后续可能的回滚使用。
  • 暂停和启动:对于每一次升级,都能够随时暂停和启动。
  • 多种升级方案:Recreate:删除所有已存在的pod,重新创建新的; RollingUpdate:滚动升级,逐步替换的策略,同时滚动升级时,支持更多的附加参数,例如设置最大不可用pod数量,最小升级间隔时间等等。

 

导入镜像

docker load < kubernetes-dashboard-amd64-v1.5.1.tar

docker load < pause-amd64-3.0.tar

 

测试一个nginx-deployment.yaml

kind: DeploymentapiVersion: extensions/v1beta1metadata:  name: nginx-deploymentspec:  replicas: 3  template:    metadata:      labels:        app: nginx    spec:      containers:      - name: nginx        image: nginx:latest        ports:        - containerPort: 80

执行nginx-deployment.yaml

kubectl create -f nginx-deployment.yaml

 

检查状态

kubectl get pod

查看容器IP

kubectl get pods -o yaml -l app=nginx | grep podIP

 

deployment滚动升级

kubectl set image deployment/nginx-deployment nginx=192.168.2.51:5000/k8images/nginx:v1

注:

  • deployment/nginx-deployment  :  deployment  + metadata name
  • nginx=192.168.2.51:5000  :   containers name + 私有仓库中镜像名称

nginx-deployment 回滚

kubectl rollout undo deployment/nginx

实现自动pod伸缩

kubectl autoscale deployment nginx-deployment --min=2 --max=6 --cpu-percent=80

注:当容器cpu使用了达到80%的时候 自动伸缩, 分片数量最小2个 最大6个

查看horizontalpodautoscalers

kubectl get horizontalpodautoscalers 

在线修改horizontalpodautoscalers配置

kubectl edit horizontalpodautoscalers nginx

 

创建nginx-service

因为pod的IP是不固定的所以创建一个service,他的IP是固定的

apiVersion: v1kind: Servicemetadata:  name: nginx-demo  labels:    app: nginxspec:  ports:  - port: 80    protocol: TCP  selector:    app: nginx

注:app: nginx       =  deployment配置文件中  labels标签下app名称

 

查看状态

kubectl get service

 

创建kubernetes-dashboard

# Copyright 2015 Google Inc. All Rights Reserved.## Licensed under the Apache License, Version 2.0 (the "License");# you may not use this file except in compliance with the License.# You may obtain a copy of the License at##     http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing, software# distributed under the License is distributed on an "AS IS" BASIS,# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the License.# Configuration to deploy release version of the Dashboard UI.## Example usage: kubectl create -f 
kind: DeploymentapiVersion: extensions/v1beta1metadata: labels: app: kubernetes-dashboard name: kubernetes-dashboard namespace: kube-systemspec: replicas: 1 selector: matchLabels: app: kubernetes-dashboard template: metadata: labels: app: kubernetes-dashboard # Comment the following annotation if Dashboard must not be deployed on master annotations: scheduler.alpha.kubernetes.io/tolerations: | [ { "key": "dedicated", "operator": "Equal", "value": "master", "effect": "NoSchedule" } ] spec: containers: - name: kubernetes-dashboard image: gcr.io/google_containers/kubernetes-dashboard-amd64:v1.5.1 ports: - containerPort: 9090 protocol: TCP args: # Uncomment the following line to manually specify Kubernetes API server Host # If not specified, Dashboard will attempt to auto discover the API server and connect # to it. Uncomment only if the default does not work. - --apiserver-host=http://192.168.56.11:8080 livenessProbe: httpGet: path: / port: 9090 initialDelaySeconds: 30 timeoutSeconds: 30---kind: ServiceapiVersion: v1metadata: labels: app: kubernetes-dashboard name: kubernetes-dashboard namespace: kube-systemspec: type: NodePort ports: - port: 80 targetPort: 9090 selector: app: kubernetes-dashboard

 

kubectl create -f kubernetes-dashboard.yaml

 

查看deployment运行

kubectl get deployment --namespace=kube-system

查看pod

kubectl get pod --namespace=kube-system

查看service

浏览器访问

 

 

 

 

 

 

 

 

转载地址:http://emepb.baihongyu.com/

你可能感兴趣的文章
大数运算-模拟
查看>>
腾讯2017暑假实习笔试题-字符串编码
查看>>
腾讯2017暑假笔试题-查找二叉树的根
查看>>
迭代器概念及traits编程技法.md
查看>>
Linux安装cmake
查看>>
SRS源码分析-协程相关类
查看>>
为何我看好社群直播
查看>>
为何我看好电商直播
查看>>
为何我看好老幼监控直播市场
查看>>
我为什么看好在线视频行业
查看>>
Xeon E3-1500 v5 GPU
查看>>
skylake AVC性能
查看>>
RTSP 协议分析 (一)
查看>>
RTSP协议分析(二)
查看>>
IPTV的前世今生与发展
查看>>
x264中的汇编x86inc.asm
查看>>
X264中的sad-a.asm
查看>>
x264中的cpu-a.asm
查看>>
x264中的DCT变换 dct-a.asm
查看>>
X264的时耗分析
查看>>