Workload management

Last updated: 2020-02-19 19:34:35

PDF

Operation scene

This article describes how to choose a variety of workload forms to run your service in an elastic cluster.

If you need to create and manage your elastic container workload through YAML, be sure to read Elastic TKE Annotation description .

prerequisite

  • An elastic cluster with a status of "running" has been created. For more information, see This API creates a Cluster .
  • The cluster has an appropriate namespace that is in the state of Active.

Introduction to workload types

Deployment

A Deployment describes the template of a Pod and the policy that controls how the Pod runs, which is well suited for deploying stateless applications.. You can specify the number of Pod copies running in the Deployment, the policy of scheduling and update the policy as needed.

StatefulSet

A StatefulSet is primarily used to manage stateful applications, and a created Pod has a persistent identifier for creation according to the specification. The identifier will remain after the Pod is migrated, terminated, or restarted. When you need persistent storage, you can match the storage volumes one to one based on the identifier. If your application does not require a persistent identifier, you are recommended to use a Deployment to deploy the application.

Job

The Job controller creates 1-N Pod, which run according to the operating rules until the end of the run. Job can be used in scenarios such as BatchCompute and data analysis to meet business requirements by setting repeated execution times, parallelism, restart policy and other settings.
After the Job execution is complete, the new Pod, will not be created or the existing Pod, will not be deleted. You can view the log of the completed Pod in the Log. Deleting a Job will clean up the Pods it created as well as the logs of those Pods.

CronJob

A CronJob object is similar to a line in a crontab (cron table) file. It periodically runs a Job according to the specified schedule. For more information about the format, see cron's documentation.
The cron format is as follows:

# File Format Description
#  ——Minute(0 - 59)
# |  ——Hour(0 - 23)
# | |  ——Day(1 - 31)
# | | |  ——Month(1 - 12)
# | | | |  ——Week(0 - 6)
# | | | | |
# * * * * *

Operation step

  1. Log in to the TKE console and select [in Left sidebar] Elastic cluster ].
  2. On the "Elastic clusters" list page, click the cluster ID, for which you want to create the workload to enter the cluster "Deployment" page. as shown below:
  1. Click [Create] to go to the "Create Workload" page.
  2. Enter workload name and select the type of workload you want to create.

Elastic TKE Annotation description

Annotation KeyAnnotation ValueDescriptionRequired/Optional
Eks.tke.cloud.tencent.com/cpuPlease seeResource specificationEnter, the default unit is nuclear, which does not need to be indicated.CPU parameters of Pod specificationYes, the specification that does not fill in or Enter does not exist will report an error.
Eks.tke.cloud.tencent.com/memPlease seeResource specificationEnter, you need to indicate the unit, such as 512Mi, 0.5Gi, 1GiMemory parameters of Pod specificationYes, the specification that does not fill in or Enter does not exist will report an error.
Eks.tke.cloud.tencent.com/security-group-idSecurity group ID, but Enter has more than one, in order to,Split, for exampleSg-id1,sg-id2Security group bound by default for workloadNo, if not, Enter will default to Associate's workload bound to Intra-region 's default security group.
If Enter, please make sure that Enter Intra-region exists in the security group ID, otherwise an error will be reported.

Complete exampl

apiVersion: apps/v1beta2
kind: Deployment
metadata:
  annotations:
    deployment.kubernetes.io/revision: "1"
    description: test
    eks.tke.cloud.tencent.com/cpu: "1"
    eks.tke.cloud.tencent.com/mem: 2Gi
    eks.tke.cloud.tencent.com/security-group-id: "sg-dxxxxxx5,sg-zxxxxxxu"
  creationTimestamp: "2019-10-11T03:47:55Z"
  generation: 1
  labels:
    k8s-app: nginx
    qcloud-app: nginx
  name: nginx
  namespace: default
  resourceVersion: "33796648"
  selfLink: /apis/apps/v1beta2/namespaces/default/deployments/nginx
  uid: e86f6533-ebd9-11e9-b061-4effc6de97a3
spec:
  minReadySeconds: 10
  progressDeadlineSeconds: 600
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      k8s-app: nginx
      qcloud-app: nginx
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
    type: RollingUpdate
  template:
    metadata:
      annotations:
        eks.tke.cloud.tencent.com/cpu: "1"
        eks.tke.cloud.tencent.com/mem: 2Gi
        eks.tke.cloud.tencent.com/wan: "true"
      creationTimestamp: null
      labels:
        k8s-app: nginx
        qcloud-app: nginx
    spec:
      containers:
      - env:
        - name: PATH
          value: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
        - name: NGINX_VERSION
          value: 1.17.4
        - name: NJS_VERSION
          value: 0.3.5
        - name: PKG_RELEASE
          value: 1~buster
        image: ccr.ccs.tencentyun.com/alex_lee/nginx:latest
        imagePullPolicy: Always
        name: nginxcontainer
        resources:
          limits:
            cpu: 500m
            memory: 1Gi
          requests:
            cpu: 250m
            memory: 256Mi
        securityContext:
          privileged: false
          procMount: Default
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
        volumeMounts:
        - mountPath: /tmp
          name: vol
      dnsPolicy: ClusterFirst
      imagePullSecrets:
      - name: qcloudregistrykey
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30
      volumes:
      - emptyDir: {}
        name: vol