Container service kubernetes Deployment implements batch release

Introduction: 1. Preface The batch release provided by the official website of Container Service is based on StatefulSet development. The stateful replica set deployment POD is released and restarted one by one in order, which takes a long time, and the console is not satisfactory, there are inconsistencies Less pit. StatefulSet batch release does not support the release of any number of batches. In practice, it is often necessary to release an online service for grayscale, and then gradually enlarge it. Therefore, the deployment object of the stateless replica set is deployed in batches and pointed to by the same labels.

1 【kubernetes Deployment implements batch release】Introduction


The batch release provided by the official website of Container Service is based on StatefulSet development. The stateful replica set deployment POD is released and restarted one by one in sequence, which takes a long time, and the console is not satisfactory, and there are many pits.
StatefulSet batch release does not support the release of any number of batches. In practice, it is often necessary to release an online service for grayscale, and then gradually enlarge it.
Therefore, stateless replica set Deployment objects are deployed in batches, and the same labels point to a unified Service exposed to visitors, which is the most suitable batch release in large applications.

2. 【kubernetes Deployment implements batch release】Configuration process


1. First create an initial grayscale Deployment with a replica number of 1. The yaml is as follows:
apiVersion: apps/v1beta2
kind: Deployment
metadata:
# service select label
labels:
app: {app_name}-aone
name: {app_name}-aone -1
namespace: {app_name}
spec:
progressDeadlineSeconds: 600
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
app: {app_name}-aone
template:
metadata:
labels:
app: {app_name}-aone
spec:
containers:
- image: >-
registry-vpc.cn-north -2 -gov -1.aliyuncs.com/app-cloud/{app_name }: 20190101191052
imagePullPolicy: Always
# Call the graceful offline script before the application stops to remove the hsf and lwp services
lifecycle:
preStop:
exec :
command:
-sudo
- '-u'
- admin
- /home/admin/appconf/bin/appctl.sh
- {app_name}
- stop
# Readiness check and liveness check
livenessProbe:
failureThreshold: 10
initialDelaySeconds: 30
periodSeconds: 10
successThreshold: 1
tcpSocket:
port: 508
timeoutSeconds: 1
name: {app_name}-aone
readinessProbe:
failureThreshold: 10
initialDelaySeconds: 30
periodSeconds: 10
successThreshold: 1
tcpSocket:
port: 508
timeoutSeconds: 1
resources:
limits:
cpu: '4'
memory: 8196 Mi
requests:
cpu: '4'
memory: 8196 Mi
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /home/admin/logs
name: volume -1553680362129
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
# Log uniformly written to the mapped host data disk log directory
volumes:
- hostPath:
path: /var/lib/docker/logs/{app_name}
type: ''
name: volume -1553680362129
2. For the second batch, for example, it is set to 16 units, and released in 4 times, each time 25%, just copy the above script, write the name of the yaml as {app_name}-aone-2, pay attention to keep the labels consistent, and ensure that the pods are the same A Service configuration provides services, and the number of copies is modified to 16, and the update strategy configuration is added. Similarly, the third batch, the fourth batch... .
metadata:
# service select label
labels:
app: {app_name}-aone
name: {app_name}-aone- 2
namespace: {app_name}
spec:
progressDeadlineSeconds: 600
replicas: 16
revisionHistoryLimit: 10
selector:
matchLabels:
app: {app_name}-aone
strategy:
rollingUpdate:
maxSurge: 25 %
maxUnavailable: 25 %
type: RollingUpdate
3. Create a Service service, point to each batch of Deployments above through the labels label mapping, use NodePort combined with SLB method, decouple the relationship between SLB load balancing and k8s service, and the cloud controller manager of the house deletes Service and SLB load balancing synchronously.
apiVersion: v1
kind: Service
metadata:
name: {app_name}-http
namespace: {app_name}
spec:
clusterIP: 133.33.33.33
externalTrafficPolicy: Cluster
ports:
- nodePort: 32168
port: 80
protocol: TCP
targetPort: 7001
selector:
app: {app_name}-aone
sessionAffinity: None
type: NodePort
status:
loadBalancer: {}
After the configuration is complete, you can click the service name in the Service console of the container service, and you can see that the service corresponds to the above four batches of deployments (Deployment).
At this point, the batch release using multiple Deployment configurations is completed.
3. Advantages and disadvantages of using multiple Deployments to release in batches
•advantage:
•The stateless deployment speed is fast, the rollback and restart speed are also very fast, and you can control how many machines to restart each batch;
•Stateless deployment has good controllability, and the container service console has few operation pits in this type.
•shortcoming:
•Cloud monitoring is grouped according to Deployment, and monitoring information becomes viewed in multiple groups;
•Cloud effect and EDAS do not support this batch release mode, which requires its own secondary development, operation and maintenance release.



Copyright statement: The content of this article is contributed by Alibaba Cloud real-name registered users. The copyright belongs to the original author. The Alibaba Cloud developer community does not own the copyright and does not assume the corresponding legal responsibility. For specific rules, please refer to the " Alibaba Cloud Developer Community User Service Agreement " and " Alibaba Cloud Developer Community Intellectual Property Protection Guidelines ". If you find any content suspected of plagiarism in this community, fill out the infringement complaint form to report it. Once verified, this community will delete the allegedly infringing content immediately.

Related Articles

Explore More Special Offers

  1. Short Message Service(SMS) & Mail Service

    50,000 email package starts as low as USD 1.99, 120 short messages start at only USD 1.00