Kubernetes secret - Linux Guru

Store a directory in a kubernetes secret

Here you will learn how to add directory in kubernetes secret and mount it on each pods.
Secrets can be defined as Kubernetes objects used to store sensitive data such as user name and passwords with encryption. In order to create secrets from a text file such as user name, password and keys, we first need to store them in particular folder and use the following command.

Create kubernetes secrets from a directory :

Make sure you are connected to cluster first. suppose you want to upload secret from .config folder and all the env and secret files under it.
kubectl create secret generic secret-name --from-file=.config

Update, add or change existing secret (Optional):

If you have running secret in kubernetes and want to update some secret passwords or add new secret.e
kubectl create secret generic secret-name --from-file=.config --dry-run -o yaml | kubectl apply -f -

Once we have created the secrets, it can be consumed in a pod or the replication controller as Environment Variable Or Volume.
As volume you need to add following into your deployment yaml file.

        - name: myvolume
              mountPath: /path/.config
            readOnly: true
          - name: myvolume
               secretName: secret-name
In the above code, We have created a volume which included created secrets and mounted it on pod.

Vishal Vyas [Linux Guru]

Welcome to Linux Guru! Hello, friends. My name is Vishal Vyas, and I am a DevOps engineer with expertise in Linux and Cloud Computing. I am also a Certified Kubernetes Administrator with over 12 years of experience in the IT field, working with various technologies. Through this blog, I aim to share my technical knowledge on Linux, AWS, DevOps, and web technologies. I will be posting about what I have learned from the latest web technologies and similar topics.

Post a Comment

If you have any doubts, Please let me know

Previous Post Next Post