apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    k8s-app: kubeedge
    kubeedge: cloudcore
  name: cloudcore
  namespace: kubeedge
spec:
  selector:
    matchLabels:
      k8s-app: kubeedge
      kubeedge: cloudcore
  template:
    metadata:
      labels:
        k8s-app: kubeedge
        kubeedge: cloudcore
    spec:
      initContainers:
      - name: kubeconfig
        image: alpine:3.9
        volumeMounts:
        - name: kubeconfig
          mountPath: /etc/kubeedge/cloud
          subPath: kubeconfig.yaml
        command:
        - /bin/sh
        - -c
        - |
          apk --no-cache add coreutils && cat | tee /etc/kubeedge/cloud/kubeconfig.yaml <<EOF
          apiVersion: v1
          kind: Config
          clusters:
          - name: kubeedge
            cluster:
              certificate-authority-data: $(cat /var/run/secrets/kubernetes.io/serviceaccount/ca.crt | base64 -w 0)
          users:
          - name: kubeedge
            user:
              token: $(cat /var/run/secrets/kubernetes.io/serviceaccount/token)
          contexts:
          - name: kubeedge
            context:
              cluster: kubeedge
              user: kubeedge
          current-context: kubeedge
          EOF
      containers:
      - name: cloudcore
        image: kubeedge/cloudcore:v1.1.0
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 10000
          name: cloudhub
          protocol: TCP
        resources:
          limits:
            cpu: 200m
            memory: 1Gi
          requests:
            cpu: 100m
            memory: 512Mi
        volumeMounts:
        - name: conf
          mountPath: /etc/kubeedge/cloud/conf
        - name: certs
          mountPath: /etc/kubeedge/certs
        - name: kubeconfig
          mountPath: /etc/kubeedge/cloud
          subPath: kubeconfig.yaml
      restartPolicy: Always
      serviceAccount: cloudcore
      serviceAccountName: cloudcore
      volumes:
      - name: conf
        configMap:
          name: cloudcore
      - name: certs
        secret:
          secretName: cloudcore
      - name: kubeconfig
        emptyDir: {}
