
apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp
  namespace: infra
  labels:
    app: myapp

spec:
  replicas: 2
  selector:
    matchLabels:
      app: myapp
  template:
    metadata:
      name: myapp
      labels:
        app: myapp
    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: myapp
                operator: In
                values:
                - "true"
      volumes:
        - name: tz-config
          hostPath:
            path: /usr/share/zoneinfo/Asia/Shanghai
        - name: myapp-configs
          configMap:
            name: myapp-configmap
            items:
              - key: entrypoint.sh
                path: entrypoint.sh
              - key: config.py
                path: config.py
      containers:
        - name: myapp
          image: tencentmusic/myapp:2020.10.01
          imagePullPolicy: IfNotPresent
          command: ["bash","/entrypoint.sh"]    # 如果修改了entrypoint要使用命令执行
          env:
          - name: STAGE
            value: prod         # init dev   prod
          - name: MYSQL_SERVICE
            value: "mysql+pymysql://root:admin@mysql-service:3306/myapp?charset=utf8"
          - name: REDIS_HOST
            value: "redis-master.infra"
          - name: REDIS_PORT
            value: "6379"
          - name: REDIS_PASSWORD
            value: "admin"
          - name: ENVIRONMENT
            value: "DEV"
          volumeMounts:
            - name: myapp-configs
              mountPath: /entrypoint.sh
              subPath: entrypoint.sh
            - name: myapp-configs
              mountPath: /home/myapp/myapp/config.py
              subPath: config.py
            - name: tz-config
              mountPath: /etc/localtime
            
          ports:
            - name: http
              containerPort: 80
              protocol: TCP
          resources:       
            limits:
              cpu: 10
              memory: 10Gi
            requests:
              cpu: 1
              memory: 1Gi
          livenessProbe:
            failureThreshold: 2
            httpGet:
              path: /health
              port: http
            initialDelaySeconds: 100
            periodSeconds: 10
            timeoutSeconds: 10
          readinessProbe:
            failureThreshold: 2
            httpGet:
              path: /health
              port: http
            initialDelaySeconds: 10
            periodSeconds: 10
            timeoutSeconds: 5



