To create a Kubernetes Secret, follow these steps:
-
Create a YAML file: Define the Secret in a YAML file. For example, create a file named
my-secret.yamlwith the following content:apiVersion: v1 kind: Secret metadata: name: my-secret type: Opaque data: password: dXNlcm5hbWU6cGFzc3dvcmQ=In this example:
- The name of the Secret is
my-secret. - The type is
Opaque. - The data contains a key-value pair, where the key is
passwordand the value is Base64-encoded.
- The name of the Secret is
-
Apply the Secret: Use the
kubectl applycommand to create the Secret in your Kubernetes cluster:kubectl apply -f my-secret.yaml -
Verify the Secret: Check that the Secret was created successfully by running:
kubectl get secretsYou should see
my-secretlisted among the secrets.
This process allows you to securely manage sensitive information within your Kubernetes applications.
