Creating a Secret

Secrets are user-defined resources that store authentication and sensitive information such as application keys. They can be used as files or environment variables in applications.

Prerequisites

You have created cluster and node resources. For more information, see Infrastructure Management. If cluster and node resources are already available, skip this operation.

Creating a Secret

  1. Log in to ServiceStage and choose Application Management > Application Configuration > Secret.
  2. Click Create Secret.
  3. Create a secret by Visualization or YAML.

    • Manner 1. Visualization. On the displayed page, set the parameters listed in the following table. Parameters marked with an asterisk (*) are mandatory.
      Table 1 Parameters for creating a secret

      Parameter

      Description

      Basic Information

      *Name

      Name of the secret, which must be unique in the same namespace.

      *Cluster

      Cluster where the secret will be used.

      *Namespaces

      Namespace to which the secret belongs. The default value is default.

      Description

      Description of the secret.

      *Secret Type

      Type of the secret. Options:

      • Opaque: general secret type.
      • dockerconfigjson: stores and pulls the authentication information required by private repository images.
      • IngressTLS: stores the certificate required by Layer-7 ELB.
      • Other: Enter a secret type that is none of the above.

      Secret Data

      Used in applications.

      • Opaque secrets
        1. Click Add Data.
        2. Set keys and values. Keys must be encoded using Base64. For more information, see Base64 Encoding.
      • dockerconfigjson secrets: Enter the username and password of a private image repository.
      • IngressTLS secrets: Upload certificates and private key files.

      Secret Label

      Labels are attached to objects, such as applications, nodes, and services, in the form of key-value pairs.

      Labels define the identifiable attributes of these objects and are used to manage and select the objects.

      1. Click Add Label.
      2. Set keys and values.
    • Method 2. YAML.

      To create a secret by uploading a file, ensure that a resource description file has been created. ServiceStage supports resource description files in JSON or YAML format. For more information, see Secret Resource File Configuration.

      1. Select a cluster from the Cluster drop-down list.
      2. (Optional) Click Upload File, select the created secret file, and then click Open.

        Upload a file whose size is smaller than 2 MB. The file can be uploaded in the YAML format.

      3. Write or modify the secret file in Orchestration content.

  4. After the configuration is complete, click Create.

    The new secret is displayed in the secret list.

Secret Resource File Configuration

This section provides examples of configuring secret resource description files.

For example, to retrieve the username and password for an application, you can prepare a secret file.

username: my-username

password: my-password

  • YAML format

    The following shows the content of a secret file named secret.yaml. The value must be encoded using Base64. For more information, see Base64 Encoding.

    apiVersion: v1
    kind: Secret
    metadata:
      name: mysecret           #Secret name.
      namespace: default       #Namespace. The default value is default.
    data:
      username: ******    #The value must be encoded using Base64.
      password: ******  #The value must be encoded using Base64.
    type: Opaque     #You are advised not to change this parameter value.
  • JSON format

    The following shows the content of a secret file named secret.json.

    {
      "apiVersion": "v1",
      "kind": "Secret",
      "metadata": {
        "name": "mysecret",
        "namespace": "default"
      },
      "data": {
        "username": "******",
        "password": "******"
      },
      "type": "Opaque"
    }

Base64 Encoding

To encrypt a character string using Base64, run the echo -n to-be-encoded content | base64 command. The following is an example.

root@ubuntu:~# echo -n "3306" | base64
MzMwNg==

Modifying or Deleting a Secret

The secret list contains system secret resources, which can only be viewed and cannot be modified or deleted.

Operation

Description

Modifying a secret

  1. Select the secret to be modified, and click Update.
  2. Modify the secret information according to Table 1.
  3. Click Update.

Deleting a secret

Click Delete in the Operations column of the secret to be deleted, and follow the system prompts to delete the secret.

Deleting secrets in batches

  1. Select the secrets to be deleted.
  2. Click Delete in the upper left of the page, and follow the system prompts to delete the secrets.