Get to Know Kubernetes | Application Orchestration and Management

1) Need

Background

  • How to ensure the number of available pods in a cluster? In other words, how to ensure the number of available pods when a host encounters a fault or network faults occur on the four pods of application A?
  • How to update the image version for all pods? Is it necessary to update the version of a pod?
  • How to ensure service availability during the update?
  • How to roll back a pod to the previous version if a problem occurs during the update?

Deployment Management Controller for Deployment and Release

2) Use Cases

Deployment Syntax

  • One is the metadata of the expected pods, including labels that match selector.matchLabels.
  • The other is Pod.spec. In the template, Pod.spec is used by Deployment to create pods. Here, container.nginx is defined, with the image version Nginx:1.7.9.
  • Replicas indicate the number of expected pods or the final number of pods in Deployment.
  • Templates indicate pod-related templates.

View the Deployment Status

  • DESIRED: The number of expected pods, which is 3.
  • CURRENT: The number of the current pods, which is 3.
  • UP-TO-DATE: The number of pods with the latest expected version.
  • AVAILABLE: The number of pods available in the running process. Actually, AVAILABLE also includes the number of pods that have exceeded their availability period.
  • AGE: The duration of a created Deployment. In the preceding figure, the Deployment has been running for 80 minutes.

View Pods

Update Images

  • In the command, “kubectl” is always followed by “set image”, indicating that this command is run to set images.
  • The following “set image” is deployment.v1.apps, indicating the type of the resource to be operated on. This part is fixed, where "deployment" indicates the resource name, "v1" indicates the resource version, and "apps" indicates the resource group. Use "deployment" or deployment.apps to replace deployment.v1.apps. For example, while using "deployment" to replace deployment.v1.apps, the v1 version of apps will be used by default.
  • The third part is “nginx-deployment”, indicating the name of the deployment with the image to be updated. “nginx” following the name indicates a template, which is the container.name of a pod. A pod may contain multiple containers and the container.name specified here, Nginx is the container name of the image to be updated.
  • The last part is nginx:1.9.1, indicating the expected image version of the container. Running this command shows that template.spec of the Deployment is updated to nginx: 1.9.1.

Quick Rollback

DeploymentStatus

3) Demonstration

Deployment Creation and Status

Deployment Structure

Pod Status

Upgrade

RevisionHistoryLimit

Rollback

4) Architecture Design

Management Mode

Deployment Controller

ReplicaSet Controller

Scale-up and Scale-down Simulation

Release Simulation

Rollback Simulation

Spec Fields

  • MinReadySeconds: The Deployment determines that a pod is available when it is ready. However, after setting MinReadySeconds to, for example, 30s, the Deployment determines that the pod is available only after it has been in the ready state for more than 30s. An available pod must be a ready pod, but a ready pod is not necessarily available. The ready pod is available only after the time specified by MinReadySeconds.
  • RevisionHistoryLimit: The number of old ReplicaSets that can be retained. The default value is 10. Set this parameter to 1 or 2. If rollback is highly probable, set it to a value greater than 10.
  • Paused: A label indicating that the Deployment is paused and only maintains the quantity, without any new releases. This field may be used in debugging scenarios.
  • ProgressDeadlineSeconds: When the Deployment is in the Scaling or Releasing state, its condition is Processing. A timeout interval is set for the Processing state. If the state is still Processing after the timeout interval, the controller considers the pod to have entered the Failed state.

Upgrade Policy Fields

  • MaxUnavailable: The maximum number of unavailable pods during the update.
  • MaxSurge: The maximum number of pods that are scheduled above the expected number of replicas during the update.

Summary

  • A Deployment is a common workload in Kubernetes, which supports the deployment and management of pods of multiple versions.
  • The Deployment creates a ReplicaSet for the template of each version, and then the ReplicaSet maintains a certain number of pod replicas. The Deployment only needs to specify the number of pods in ReplicaSets of each version.
  • In short, a Deployment adjusts the final number of replicas in ReplicaSets to upgrade and roll back pods of different versions.

Original Source:

--

--

Follow me to keep abreast with the latest technology news, industry insights, and developer trends. Alibaba Cloud website:https://www.alibabacloud.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alibaba Cloud

Follow me to keep abreast with the latest technology news, industry insights, and developer trends. Alibaba Cloud website:https://www.alibabacloud.com