注意:以下文档只适用于TOP接口,请谨慎使用!

文档中心 > 聚石塔

Yaml配置模板参考

更新时间:2020/08/05 访问次数:511

写在前面

聚石塔支持的Yaml配置,均是K8S原生Yaml配置;基于聚石塔的应用模型,我们在原生yaml的基础上,限制了一些字段的设置。具体的限制参考如下

ConfigMap

kind: ConfigMap
# metadata下仅支持name和labels
metadata:
  name: zookeeper-config
apiVersion: v1
data:
  init.sh: |-
    #!/bin/bash
    set -e
    set -x
    [ -z "$ID_OFFSET" ] && ID_OFFSET=1
    export ZOO_MY_ID=$((${HOSTNAME##*-} + $ID_OFFSET))
    echo "${ZOO_MY_ID:-1}" | tee $ZOO_DATA_DIR/myid
    cat ${EXTERNAL_CONF_PATH}/zookeeper.properties > ${ZOO_CONF_DIR}/zoo.cfg
    sed -i "s/server\.${ZOO_MY_ID}\=[a-z0-9.-]*/server.${ZOO_MY_ID}=0.0.0.0/" ${ZOO_CONF_DIR}/zoo.cfg
  zookeeper.properties: |-
    tickTime=2000
    dataDir=/data
    dataLogDir=/datalog
    clientPort=2181
    maxClientCnxns=1
    initLimit=5
    syncLimit=2
    autopurge.snapRetainCount=3
    autopurge.purgeInterval=1
    server.1=zk-0.zk-hs:2888:3888
    server.2=zk-1.zk-hs:2888:3888
    server.3=zk-2.zk-hs:2888:3888

无状态Deployment

apiVersion: apps/v1
kind: Deployment
# metadata下只支持设置labels和annotations
# 不支持namespace和name
metadata:
 labels:
   k1: v1
 annotations:
   k1: v1
# spc不支持paused和replicas,其他均支持
# 支持的字段如下 selector,minReadySeconds,template,progressDeadlineSeconds,revisionHistoryLimit,strategy
spec:
  # 支持matchLabels 和 matchExpressions
  selector:
    matchLabels:
      test: hangyu
  template:
    # podTemplate.metadata 只支持设置labels和annotations
    metadata:
      labels:
        test: hangyu
    # 支持设置affinity,initContainers,containers,volumes,nodeSelector,terminationGracePeriodSeconds
    # 支持设置activeDeadlineSeconds,hostAliases,imagePullSecrets,serviceAccountName
    spec:
      containers:
        - env:
            - name: JAVA_OPT
              value: >-
                -server -Xms1g -Xmx1g -Xmn512m -XX:MetaspaceSize=128m
                -XX:MaxMetaspaceSize=128m -Duser.timezone=Asia/Shanghai
            - name: SPRINGBOOT_OPT
              value: >-
                --management.info.build.mode=full
                --spring.profiles.active=production --logging.path=/acs/log
                --logging.file=/acs/log/application.log
            - name: PRESHELL
            - name: POSTSHELL
            - name: MAIN_PORT
              value: '8080'
            - name: MANAGEMENT_PORT
              value: '8081'
          image: 'registry-vpc.cn-zhangjiakou.aliyuncs.com/jstopen/springboot2:1.0.0'
          livenessProbe:
            httpGet:
              path: /actuator/health
              port: 8081
              scheme: HTTP
          name: jck-app-hangyu-10078
          ports:
            - containerPort: 8080
              name: main-port
              protocol: TCP
            - containerPort: 8081
              name: management-port
              protocol: TCP
          readinessProbe:
            httpGet:
              path: /actuator/health
              port: 8081
              scheme: HTTP
          resources:
            limits:
              cpu: '1'
              memory: 1000Mi
          volumeMounts:
            - mountPath: /acs/data
              name: jck-v-wedf
            - mountPath: /acs/log
              name: jck-v-wedg
      volumes:
        - emptyDir: {}
          name: jck-v-wedf
        - emptyDir: {}
          name: jck-v-wedg

注:
1.metadata下只支持设置labels和annotations,不支持namespace和name
2.spec下不支持paused和replicas,其他均支持
3.podTemplate.metadata 只支持设置labels和annotations
4.podTemplate.spec 下的字段基本都支持

有状态StatefulSet

apiVersion: apps/v1
kind: StatefulSet
# metadata下支持设置labels、annotations、name; 仅不支持namespace
metadata:
  name: zaide-ss
  labels:
    app: st
# spc不支持revisionHistoryLimit和replicas,其他均支持
# 支持的字段如下 podManagementPolicy,selector,serviceName,template,updateStrategy,volumeClaimTemplates
spec:
  podManagementPolicy: OrderedReady
  # 支持matchLabels 和 matchExpressions
  selector:
    matchLabels:
      app: st
  serviceName: lingfeng-service
  template:
    # podTemplate.metadata 只支持设置labels和annotations
    metadata:
      labels:
        app: st
        lingfeng: lingfeng2
    # 支持设置affinity,initContainers,containers,volumes,nodeSelector,terminationGracePeriodSeconds
    # 支持设置activeDeadlineSeconds,hostAliases,imagePullSecrets,serviceAccountName
    spec:
      containers:
        - image: 'registry.cn-zhangjiakou.aliyuncs.com/jstopen/nginx-1.14.2:1.0.0'
          name: test
          imagePullPolicy: Always
          resources:
            requests:
              cpu: 250m
              memory: 512Mi
          volumeMounts:
            - mountPath: /acs/env/nginx/user.nginx.conf
              name: jck-v-nyi6
            # 挂载PVC
            - mountPath: /test/pvc
              name: claim-template
      terminationGracePeriodSeconds: 30
      volumes:
        - configMap:
            defaultMode: 420
            items:
              - key: '-acs-env-nginx-user.nginx.conf'
                mode: 420
                path: '-acs-env-nginx-user.nginx.conf'
            name: hangyu-configmap
          name: jck-v-nyi6
  # 存储卷声明模板
  volumeClaimTemplates:
  - metadata: 
      name: claim-template
    spec: 
      accessModes: 
      - ReadWriteOnce
      resources:
        requests:
          storage: 1Gi
      storageClassName: sc

限制基本与deployment类似。与deployment不同的是,StatefulSet允许设置name
支持设置podManagementPolicy和volumeClaimTemplates

守护进程DaemonSet

暂时没有开放Yaml

定时任务CronJob

apiVersion: batch/v1beta1
kind: CronJob
metadata:
spec:
  schedule: "*/2 * * * *"
  successfulJobsHistoryLimit: 5
  failedJobsHistoryLimit: 3
  jobTemplate:
    spec:
      parallelism: 1
      template:
        metadata:
          labels:
            app: test-batch-job
        spec:
          containers:
          - name: main
            image: busybox
            args:
            - /bin/sh
            - -c
            - date; sleep 90; echo Hello from the CronJob Instance; date;
          restartPolicy: Never

注:metadata下只支持设置labels和annotations,不支持namespace和name

FAQ

关于此文档暂时还没有FAQ
返回
顶部