Search code examples
amazon-web-servicesazurekubernetescertificate

Provide certificate file into pod in k8s


We a pod which needs certificate file We need to provide a path to a certificate file, (we have this certificate) how should we put this certificate file into k8s that the pod will have an access to it e.g. that we were able to provide it like the following to the pod "/path/to/certificate_authority.crt” Should we use secret/ configmap, if yes than how?


Solution

  • Create a TLS secret then mount it to the desired folder.

    apiVersion: v1
    kind: Secret
    metadata:
      name: secret-tls
    type: kubernetes.io/tls
    data:
      # the data is abbreviated in this example
      tls.crt: |
            MIIC2DCCAcCgAwIBAgIBATANBgkqh ...
      tls.key: |
            MIIEpgIBAAKCAQEA7yn3bRHQ5FHMQ ...
    

    Documentation

    To mount the secret in a volume from your pod:

    apiVersion: v1
    kind: Pod
    metadata:
      name: mypod
    spec:
      containers:
      - name: mypod
        image: redis
        volumeMounts:
        - name: foo
          mountPath: "/path/to/"
          readOnly: true
      volumes:
      - name: foo
        secret:
          secretName: secret-tls
    

    Documentation