Table of Contents
- What are the secrets?
- Types of secrets:
- Built-in Secrets
- Creating your Secrets
- What are the secrets?
- Kubernetes secrets objects let you store and manage sensitive information, such as passwords, authorization tokens, and ssh keys.
- Putting this information in a secret is safer and more flexible than putting it verbatim in a pod lifecycle definition or a container image.
2. Types of secrets
a. Built-in Secrets
- Kubernetes automatically creates secrets that contain credentials for accessing the API and it automatically modifies your pods to use this type of secret.
- The automatic creation and use of API credentials can be disabled or overridden if desired. However, if all need to do is securely access the API server, this is the recommended workflow.
b. Creating your Secrets
- The kubectl create secret command packages these files into a secret and creates the object on the API server
- This is to protect the secrets from being exposed accidentally to an onlooker, or from being stored in a terminal log.
- First of all, we should log in as a root user.
- It some pods need to access a database the username and password that the pod should use is in the files.
- ./username.txt and ./password.txt on your local machine
- To store the username and password use this command
- Echo -n ‘admin’ > ./username.txt
- Echo -n ‘1f2dle2e67df’ > ./password.txt
The kubectl create secrete command packages these files into a secret and create the object on the API server.
So we will use this command:
Kubectl create secret generic db-user-pass- -from-files./username.txt – -from-file=./password.txt
Now to check the status of the service we can use the command: kubectl get secrets
Now here you can see that the default token along with the db-user -pass has been created.
Now if you want to check services running in this we can simply use this command:
Kubectl describe secrets/db-user-pass
If you creating a secrete manually.to store two strings in a secret using the data field convert time to base64 as follows:
echo -n ‘admin’ | base64 YWRtaW4=
echo -n ‘1f2d1e2e67df’ | base64 MWYyZDF1MmU2N2Rm=
- After this, we will create a secrete file which is vi secrets yaml. We will test this configuration and we will save this file
We will use this command:
Kubectl create -f ./secretyaml – – validate =false
If you want to decode the secret file which we have created using this command:
Kubectl get secret mysssecret -o yaml