Kubernetes 简明教程
Kubernetes - Deployments
部署被升级,并且复制控制器的版本更高。它们管理副本集的部署,副本集也是复制控制器的升级版本。它们具有更新副本集的能力,并且还能够回滚到之前的版本。
Deployments are upgraded and higher version of replication controller. They manage the deployment of replica sets which is also an upgraded version of the replication controller. They have the capability to update the replica set and are also capable of rolling back to the previous version.
它们提供了 matchLabels 和 selectors 的许多更新功能。我们已经在 Kubernetes master 中获得了一个名为部署控制器的新的控制器,它使之成为现实。它具有在中间更改部署的能力。
They provide many updated features of matchLabels and selectors. We have got a new controller in the Kubernetes master called the deployment controller which makes it happen. It has the capability to change the deployment midway.
Changing the Deployment
Updating − 用户可以在完成之前更新正在进行的部署。在此当中,现有部署将被结算,将创建新部署。
Updating − The user can update the ongoing deployment before it is completed. In this, the existing deployment will be settled and new deployment will be created.
Deleting − 用户可以在完成之前通过删除部署暂停/取消部署。重新创建相同的部署将重新开始它。
Deleting − The user can pause/cancel the deployment by deleting it before it is completed. Recreating the same deployment will resume it.
Rollback − 我们可以回滚部署或正在进行的部署。用户可以通过使用 DeploymentSpec.PodTemplateSpec = oldRC.PodTemplateSpec. 创建或更新部署。
Rollback − We can roll back the deployment or the deployment in progress. The user can create or update the deployment by using DeploymentSpec.PodTemplateSpec = oldRC.PodTemplateSpec.
Deployment Strategies
部署策略帮助定义了新的 RC 应该如何替换现有的 RC。
Deployment strategies help in defining how the new RC should replace the existing RC.
Recreate − 此功能将终止所有现有 RC,然后启动新 RC。这可实现快速部署,但当旧容器关闭而新容器尚未启动时,将导致停机。
Recreate − This feature will kill all the existing RC and then bring up the new ones. This results in quick deployment however it will result in downtime when the old pods are down and the new pods have not come up.
Rolling Update − 此功能会逐渐关闭旧 RC 并启动新 RC。这将导致部署速度变慢,但不会导致停机。在此过程中,始终有几个旧容器和几个新容器可用。
Rolling Update − This feature gradually brings down the old RC and brings up the new one. This results in slow deployment, however there is no deployment. At all times, few old pods and few new pods are available in this process.
部署配置文件如下所示。
The configuration file of Deployment looks like this.
apiVersion: extensions/v1beta1 --------------------->1
kind: Deployment --------------------------> 2
metadata:
name: Tomcat-ReplicaSet
spec:
replicas: 3
template:
metadata:
lables:
app: Tomcat-ReplicaSet
tier: Backend
spec:
containers:
- name: Tomcatimage:
tomcat: 8.0
ports:
- containerPort: 7474
在上述代码中,与副本集不同的唯一之处在于,我们将 kind 定义为 deployment。
In the above code, the only thing which is different from the replica set is we have defined the kind as deployment.
Create Deployment
$ kubectl create –f Deployment.yaml -–record
deployment "Deployment" created Successfully.