YAML application deployment example (with initial container configuration)

This example provides configuration of an initial container.

apiVersion: apps/v1    # Required. Specify the API version, which is fixed at apps/v1.

kind: Deployment     # Required. Specify an application type, which can be Deployment (stateless application) or StatefulSet (stateful application).

metadata:

  labels:    # Required. Specify an application label in the format of app: application name.

    app: tomcattest

  name: tomcattest    # Required. Specify an application name, which must be the same as that on the basic settings page and must be unique in the same application group.

  namespace: spaceh0h8w1lp    # Namespace selected for the application group on the basic settings page.

spec:

  replicas: 1

  selector:    # Required. Specify a label selector, which must be the same as the label of the template (app: application name).

    matchLabels:

      app: tomcattest

  template:

    metadata:

      labels:

        app: tomcattest     # Required. Enter a label in the format of app: application name.

    spec:

      affinity:     # A container scheduling policy.

        nodeAffinity:     # Define the nodes that can schedule a pod.

          preferredDuringSchedulingIgnoredDuringExecution:

          - preference:

              matchExpressions:

              - key: beta.kubernetes.io/instance-type

                operator: In

                values:

                - adcf1f03-9fda-4cc8-8d29-66f384ed6581

            weight: 50

        podAffinity:     # Define which pods with workloads are deployed in the same topology domain.

          preferredDuringSchedulingIgnoredDuringExecution:

          - podAffinityTerm:

              labelSelector:

                matchExpressions:

                - key: apps

                  operator: In

                  values:

                  - testbb

              namespaces:

              - space2woixyjc

              topologyKey: kubernetes.io/hostname

            weight: 100

        podAntiAffinity:    # Define which pods with workloads are not deployed in the same topology domain.

          preferredDuringSchedulingIgnoredDuringExecution:

          - podAffinityTerm:

              labelSelector:

                matchExpressions:

                - key: apps

                  operator: NotIn

                  values:

                  - testccc

              topologyKey: kubernetes.io/hostname

            weight: 100

      containers:

      - args:    # Command parameter.

        - --port=8080

        command:    # Command to be executed.

        - /bin/start

        env:    # Environment variable used to change container configuration after deployment.

        - name: SERVICE_NAME

          value: tomcattest

        image: os-harbor-svc.default.svc.cloudos:443/library/zy-demo-image:v1   # Required. Address of the image used by the container.

        imagePullPolicy: IfNotPresent    # Required. Image check and update policy upon startup: Always, Never, or IfNotPresent.

        livenessProbe:    # Liveness check.

          exec:

            command:

            - /bin/bash

            - -c

            - /tmp/healthy

          failureThreshold: 12

          initialDelaySeconds: 12

          periodSeconds: 12

          successThreshold: 1

          timeoutSeconds: 10

        name: tomcattest    # Required. Container name.

        readinessProbe:    # Readiness check.

          failureThreshold: 1

          httpGet:

            path: /health

            port: 8080

            scheme: HTTP

          initialDelaySeconds: 10

          periodSeconds: 3

          successThreshold: 2

          timeoutSeconds: 3

        resources:    # Required. Container flavor.

          limits:    # Required. Maximum resources allowed for the operation of the container.

            cpu: 300m    # CPU resource.

            memory: 300Mi    # Memory resource.

          requests:    # Required. Minimum resources guaranteed for the startup of the container. The request must be smaller than the limit.

            cpu: 200m

            memory: 200Mi

        securityContext:

          capabilities:    # Linux capabilities.

            add:

            - DAC_OVERRIDE

            - FOWNER

            - FSETID

          privileged: false    # Run the container in privileged mode. In this mode, the processes in the container run as root.

          readOnlyRootFilesystem: true     # Read-only access to the root file system.

          runAsUser: 0     # User UID.

        terminationMessagePath: /dev/termination-log

        terminationMessagePolicy: File

        volumeMounts:

        - mountPath: /tmp    # Mount path.

          name: hostpath-dn2csq7m0    # Storage volume name of the service container. The pods must have the same storage volume name.

        - mountPath: /tmppvc

          name: pvc-htb3am891

        - mountPath: /conf

          name: emptydir-m23qoldk1

        - mountPath: /seca

          name: secret-653i9fy20

      initContainers:    # Configure an initial container.

      - command:

        - sh

        - -c

        - echo app is running

        env:

        - name: t1234

          value: "1234"

        image: os-harbor-svc.default.svc.cloudos:443/library/zy-demo-image:v1

        imagePullPolicy: IfNotPresent

        name: init1

        volumeMounts:

        - mountPath: /tmp/local    # Mount path.

          name: hostpath-dn2csq7m0    # Storage volume name of the initial container. The service container must have the same storage volume name.

        - mountPath: /tmp/tmpdir

          name: emptydir-m23qoldk1    # Storage volume name of the initial container. The service container must have the same storage volume name.

      dnsPolicy: ClusterFirst

      hostIPC: true    # Use the IPC namespace of the host.

      hostNetwork: true    # Use the network namespace of the host.

      hostPID: true    # Use the PID namespace of the host.

      restartPolicy: Always

      schedulerName: default-scheduler

      securityContext: {}

      serviceAccount: default

      serviceAccountName: default

      terminationGracePeriodSeconds: 30

      volumes:    # The configMap, secret, persistentVolumeClaim, and hostPath volume types are supported.

      - hostPath:

          path: /etc/hosts

          type: ""

        name: hostpath-dn2csq7m0

      - emptyDir: {}

        name: emptydir-m23qoldk1

      - name: pvc-htb3am891

        persistentVolumeClaim:

          claimName: pvctesta

      - name: secret-653i9fy20

        secret:

          defaultMode: 420

          secretName: default-token-hb627

      - configMap:

          defaultMode: 420

          name: confgg

        name: cm-vhqj6sc90