`
m635674608
  • 浏览: 5028069 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论

Deployment vs ReplicationController in Kubernetes

 
阅读更多

腾讯云容器服务是基于Kubernetes打造的。在Kubernetes中,创建和管理容器都是以controller来实现,例如:Replication Controller,Deployment,PetSet等。使用controller来管理容器,可以使用户方便的对容器数量做扩缩容,升级容器等操作。此文主要选择了两个最常用的controller,从各自功能,优缺点方面进行对比,方便大家在后续自己直接使用原生的Kubernetes功能时做参考。

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的整体资源使用情况,做到自动伸缩。

  • 滚动升级:滚动升级为一种平滑的升级方式,通过逐步替换的策略,保证整体系统的稳定,在初始化升级的时候就可以及时发现和解决问题,避免问题不断扩大。

最后,来看一下官方的解释: A replication controller ensures that a specified number of pod “replicas” are running at any one time. In other words, a replication controller makes sure that a pod or homogeneous set of pods are always up and available. If there are too many pods, it will kill some. If there are too few, the replication controller will start more. Unlike manually created pods, the pods maintained by a replication controller are automatically replaced if they fail, get deleted, or are terminated. For example, your pods get re-created on a node after disruptive maintenance such as a kernel upgrade. For this reason, we recommend that you use a replication controller even if your application requires only a single pod. You can think of a replication controller as something similar to a process supervisor, but rather than individual processes on a single node, the replication controller supervises multiple pods across multiple nodes.

Deployment

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

  • Replication Controller全部功能:Deployment继承了上面描述的Replication Controller全部功能。

  • 事件和状态查看:可以查看Deployment的升级详细进度和状态。

  • 回滚:当升级pod镜像或者相关参数的时候发现问题,可以使用回滚操作回滚到上一个稳定的版本或者指定的版本。

  • 版本记录: 每一次对Deployment的操作,都能保存下来,给予后续可能的回滚使用。

  • 暂停和启动:对于每一次升级,都能够随时暂停和启动。

  • 多种升级方案:Recreate----删除所有已存在的pod,重新创建新的; RollingUpdate----滚动升级,逐步替换的策略,同时滚动升级时,支持更多的附加参数,例如设置最大不可用pod数量,最小升级间隔时间等等。

下面同样是官方的解释: A Deployment provides declarative updates for Pods and Replica Sets (the next-generation Replication Controller). You only need to describe the desired state in a Deployment object, and the Deployment controller will change the actual state to the desired state at a controlled rate for you. You can define Deployments to create new resources, or replace existing ones by new ones.

Replication Controller vs Deployment

Deployment做为新一代的Replication Controller,好处不言而喻,不仅在功能上更为丰富,同时官方的文档中,也都推荐使用Deployment来管理pod,在google容器服务中,集群的系统pod,例如kube-dns,kube-proxy也都使用deployment来管理的,所以当大家需要选择的时候,也推荐使用Deployment在来管理pod。

Rolling updates Between Replication Controller and Deployment

Replication Controller

Replication Controller是使用kubectl rolling-update 来进行升级

$ kubectl rolling-update NAME \
    ([NEW_NAME] --image=IMAGE | -f FILE)

首先 我们定义一个nginx-v1.yaml的文件,副本数量为2:

apiVersion: v1
kind: ReplicationController
metadata:
  name: nginx-v1
spec:
  replicas: 2
  selector:
  app: nginx
  template:
  metadata:
  name: nginx
  labels:
  app: nginx
  spec:
  containers:
  - name: nginx
  image: nginx:1.8
  ports:
  - containerPort: 80

创建rc

$ kubectl create -f nginx-v1.yaml

然后是用kubeclt查看创建的rc

$ kubectl get rc/nginx-v1

现在需要将nginx的版本进行升级,从1.8升级到1.9,我们在定义一个1.9版本的Replication Controller的yaml文件:

apiVersion: v1
kind: ReplicationController
metadata:
  name: nginx-v2
spec:
replicas: 2
selector:
app: nginx
template:
metadata:
name: nginx
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.9
ports:
- containerPort: 80

开始滚动升级,update-period为更新间隔,这里设置的是10s:

$ kubectl rolling-update nginx-v1 -f nginx-v2.yaml --update-period=10s
Scaling up nginx-v2 from 0 to 2.scaling down nginx-v1 from 2 to 0
Scaling nginx-v2 up to 1
Scaling nginx-v1 down to 1
Scaling nginx-v2 up to 2
Scaling nginx-v1 down to 0
Update successed.Delete nginx-v1
replicationcontroller "nginx-v1" rolling updated to "nginx-v2"

Deployment

Deployment直接使用kubectl edit deployment/deploymentName 或者kubectl set方法就可以直接升级:

首先 我们同样定义一个nginx-deploy-v1.yaml的文件,副本数量为2:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: nginx-deployment2
spec:
replicas: 3
template:
metadata:
labels:
test: nginx
spec:
containers:
- name: nginx
image: nginx:1.8
ports:
 - containerPort: 80

创建deployment

$ kubectl create -f nginx-deploy-v1.yaml

然后是用kubeclt查看创建的rc

$ kubectl get deployment/nginx-deployment2

现在需要将nginx的版本进行升级,从1.8升级到1.9,有两种方法可以使用: 直接set镜像:

$ kubectl set image deployment/nginx-deployment2 nginx=nginx:1.9
deployment "nginx-deployment2" image updated

或者直接edit:

$ kubectl edit deployment/nginx-deployment
deployment "nginx-deployment2" edited

最后,查看详细信息来确定升级进度:

$ kubectl describe deployments

同时介绍一下附加的一些操作,暂停和继续,回滚升级:

$ kubectl rollout pause deployment/nginx-deployment2
$ kubectl rollout resume deployment/nginx-deployment2
$ kubectl rollout undo deployment/nginx-deployment2

总结:在腾讯云容器服务中,我们创建的无状态服务都是以Deployment来管理的容器,因为Deployment功能更多,并且也是官方推荐的,下一代的Replication Controller。

 

http://blog.csdn.net/yjk13703623757/article/details/53746273

https://www.qcloud.com/community/article/695320001482723928

分享到:
评论

相关推荐

    linux-基于Fabric8模拟Kubernetes的Deployment实现一个CRD

    在这个特定的案例中,"linux-基于Fabric8模拟Kubernetes的Deployment实现一个CRD"意味着我们要使用Fabric8来模仿Kubernetes的Deployment行为,并创建一个自定义资源类型。 CRD是Kubernetes的一个强大特性,它允许...

    Key concepts in Kubernetes

    在 Kubernetes 中,Deployment 的每个版本都有一个 revision,revision 用于记录Deployment的历史版本。通过 rollout 和 rollback,可以在不同的版本之间切换,从而实现应用程序的回退和更新。 Kubernetes ...

    Kubernetes Deployment & Security Patterns

    Kubernetes is one of the largest open source projects in the world, according to data from GitHub. It’s so big that the tools to manage the development and deployment of Kubernetes are constantly ...

    Kubernetes in Action中英文

    在《Kubernetes in Action》这本书中,作者详细讲解了Kubernetes的基础概念,包括Pod(最小部署单元)、Service(服务发现和负载均衡)、Deployment(应用的声明式更新)、StatefulSet(有状态应用的管理)等核心...

    Kubernetes实战(套装共2册)PDF

    核心概念如Pod、Replication Controller、Service和Deployment是Kubernetes中的基础元素。Pod是Kubernetes中最小的部署单位,它封装了容器和存储资源。Replication Controller负责保证Pod的数量始终符合用户指定的...

    Mastering Kubernetes [Gigi Sayfan]

    Kubernetes is an open source system to automate the deployment, scaling, and management of containerized applications. If you are running more than just a few containers or want automated management ...

    04-kubernetes笔记.pdf

    本文将深入探讨ReplicationController(RC)、ReplicaSet(RS)、Deployment、selector以及Horizontal Pod Autoscaler(HPA)等关键概念。 1. **ReplicationController(RC)**: - RC是K8s早期用于维护Pod副本...

    kubernetes容器编排

    Container Orchestration Ecosystem Configuration Management Service Discovery Deploy Kubernetes Cluster POD Management ...Replication Controller/Deployment Persistent Storage Kubernetes Security

    【经典教材】Kubernetes in Action

    《Kubernetes in Action》是Manning出版社发布的一本专业书籍,专注于讲解Kubernetes这一现代容器编排系统的实战应用。Kubernetes(简称K8s)是由Google开源的项目,旨在自动化容器化应用程序的部署、扩展和管理,现...

    Mastering Kubernetes

    Kubernetes is an open source system to automate the deployment, scaling, and management of containerized applications. If you are running more than just a few containers or want automated management ...

    kubernetes-learning.pdf

    Replication Controller 与 Replica Set Deployment HPA Job/CronJob Service ConfigMap Secret RBAC 部署Wordpress示例 DaemonSet 和 StatefulSet 持久化存储: PV PVC StorageClass 服务发现 kubedns ingress 安装...

    Kubernetes.in.Action.en.pdf 实战

    《Kubernetes in Action》是一本深入探讨 Kubernetes 的实战指南,英文版提供了全面的文字内容,适合对容器编排和云原生应用部署有兴趣的读者。Kubernetes 是一个强大的开源系统,用于自动化容器化应用程序的部署、...

Global site tag (gtag.js) - Google Analytics