apiVersion: v1
kind: Pod
metadata:
  name: vault-agent-consule-nginx
  namespace: default
spec:
  serviceAccountName: vault-auth
  volumes:
  - configMap:
      name: vault-agent-config
      items:
      - key: vault-agent-config.hcl
        path: vault-agent-config.hcl
    name: vault-agent-config

  - configMap:
      name: consul-config
      items:
      - key: configmap-consul.hcl
        path: configmap-consul.hcl
    name: consul-config

  - emptyDir: {}
    name: shared-data
  - emptyDir: {}
    name: vault-token    

  initContainers:
  - name: vault-agent
    args:
    - agent
    - -config=/etc/vault/vault-agent-config.hcl
    - -log-level=debug
    env:
    - name: VAULT_ADDR
      value: http://vault:8200
    image: vault

    volumeMounts:
    - mountPath: /etc/vault
      name: vault-agent-config
    - name: vault-token
      mountPath: /home/vault

  containers:
  - name: consul-template
    image: hashicorp/consul-template:alpine
    imagePullPolicy: Always
    volumeMounts:
      - name: vault-token
        mountPath: /home/vault
      - name: consul-config
        mountPath: /etc/consul-template
      - name: shared-data
        mountPath: /etc/secrets
    env:
      - name: HOME
        value: /home/vault
      - name: VAULT_ADDR
        value: http://vault:8200
    args: ["-config=/etc/consul-template/configmap-consul.hcl"]
    resources:
      requests:
        cpu: 100m
        memory: 64Mi
      limits:
        cpu: 200m
        memory: 128Mi
  - name: nginx-container
    image: nginx
    ports:
    - containerPort: 80
    volumeMounts:
    - mountPath: /usr/share/nginx/html
      name: shared-data
    resources:
      requests:
        cpu: 100m
        memory: 64Mi
      limits:
        cpu: 200m
        memory: 128Mi

