Mounting Secrets as Files
Learn how we can mount secrets as files.
We'll cover the following...
Just like we did with ConfigMaps
, we can also mount Secrets
as files in our containers:
Press + to interact
apiVersion: apps/v1kind: Deploymentmetadata:name: hellok8sspec:replicas: 2selector:matchLabels:app: hellok8stemplate:metadata:labels:app: hellok8sspec:volumes:- name: secretssecret:secretName: hellok8s-secretcontainers:- image: brianstorti/hellok8s:v4name: hellok8s-containervolumeMounts:- name: secretsmountPath: /secrets
Run the code below, and see if it works.
apiVersion: v1 kind: Secret metadata: name: hellok8s-secret data: SECRET_MESSAGE: "SXQgd29ya3Mgd2l0aCBhIFNlY3JldAo="
Testing our application
Press + to interact
kubectl apply -f deployment.yamlkubectl apply -f hellok8s-secret.yamlkubectl get pods# NAME READY STATUS RESTARTS# hellok8s-6696859cbd-72g9b 1/1 Running 0# hellok8s-6696859cbd-hbczd 1/1 Running 0# Replace the pod anme to what you have running locallykubectl exec -it hellok8s-6696859cbd-72g9b -- \cat /secrets/SECRET_MESSAGE# It works with a Secret
...
Access this course and 1400+ top-rated courses and projects.