Kubernetes Secret Creation - DBName, Username, Password and Encryption Key

In this section, you will learn to create a secret to store database name, username, password, and encryption key.

To create a Kubernetes secret:
  1. Create a yaml file with dbname, dbusername, dbpassword, encryptionKey using the syntax given below:
    ocudr-secret.yaml
    apiVersion: v1
    kind: Secret
    metadata:
      name: ocudr-secrets
    type: Opaque
    data:
      dbname: dWRyZGI=
      dsusername: dWRydXNlcg==
      dspassword: dWRycGFzc3dk
      encryptionkey: TXkgc2VjcmV0IHBhc3NwaHJhc2U=

    Note:

    The name used to define a secret above should be same as given in the dbCredSecretName configuration under global section in values.yaml.

    The values of dbname, dsusername, dspassword, encryptionKey are base64 encoded. These are created by executing the following commands:

    echo -n "<db name>" | base64

    echo -n "<db username>" | base64

    echo -n "<db password>" | base64

    echo -n "<encryptionKey string>" | base64

    Note:

    You will create a secret using this yaml file.
  2. Execute the following command to create a namespace where deployment is done.

    kubectl create namespace <namespace>

    Note:

    To create a secret, you need a namespace where deployment is done.
  3. Execute the following command to create a secret:

    kubectl create -f <secret File Name> -n <namespace>

  4. Execute the following command to verify a secret creation:

    kubectl describe secret <secret name> -n <namespace>