Lab13 - Secrets and ConfigMaps
Lab13 - Secrets and ConfigMaps
Introduction
Kubernetes Secrets let you store and manage sensitive information, such as passwords, OAuth
tokens, and ssh keys. Storing confidential information in a Secret is safer and more flexible than
putting it verbatim in a Pod definition or in a container image.
A ConfigMap is an API object used to store non-confidential data in key-value pairs. Pods can
consume ConfigMaps as environment variables, command-line arguments, or as configuration
files in a volume. A ConfigMap allows you to decouple environment-specific configuration from
your container images, so that your applications are easily portable.
Objective:
• Create Secret
• Decode Secret
• Create Configmap
• Deploy mariadb app
• Cleanup
1.1 Let us clone the git repository which contains manifests required for this exercise, by
executing the below command.
# git clone https://github.com/EyesOnCloud/k8s-secret.git
Output:
# cat -n ~/k8s-secret/mysql-secret.yaml
Output:
1.3 Let us create Secret using the manifest file mysql-secret.yaml, by using the below
command.
Note: The manifest contains the base64 encoded password for MYSQL_ROOT_PASSWORD.
(echo -n 'KubernetesRocks!' | base64)
2.2 Let us decode the secret by passing the value to base64, by executing the below command.
You can also create Secrets directly using the kubectl create secret command. The MariaDB
image permits setting up a regular database user with a password by setting the MYSQL_USER
and MYSQL_PASSWORD environment variables. A Secret can hold more than one key/value
pair, so you can create a single Secret to hold both strings.
Output:
Note: the --from-literal, which sets the key name and the value all in one. You can pass as many
--from-literal arguments as you need to create one or more key/value pairs in the Secret.
3.1 Let us verify the username were created and stored correctly:
3.2 Let us verify the password were created and stored correctly:
Let us First create a file named max_allowed_packet.cnf with the following content:
4.1 Let us create a ConfigMap named mariadb-config, by executing the below command.
# cat -n ~/k8s-secret/mariadb-deployment.yaml
Output:
Use the kubectl exec command (with your Pod name) to validate that the Secrets and
ConfigMaps are in use.
7.1 check that the environment variables are exposed in the container:
Output:
7.2 Let us verify that the max_allowed_packet.cnf file was created in /etc/mysql/conf.d and
that it contains the expected content:
Output:
Output:
Output:
Output:
Output:
# exit