Creating a Secret
A secret is a type of resource that holds sensitive data, such as authentication and key information, required by a workload. Its content is user-defined. After creating secrets, you can use them as files or environment variables in a containerized workload.
Creating a Secret
- Log in to the cluster console. In the navigation pane, choose ConfigMaps and Secrets, and click the Secrets tab. You can create a secret directly or using YAML. If you want to create a secret using YAML, go to 4.
- Select the namespace to which the secret will belong.
- Click Create Secret.
Set the parameters listed in Table 1.
Table 1 Basic information parameters Parameter
Description
Name
Name of the secret you create, which must be unique.
Namespace
Namespace to which the secret belongs. The current namespace is used by default.
Description
Description of the secret.
Secret Type
Type of the secret.
- Opaque: general secret type. In high-sensitive scenarios, you are advised to encrypt sensitive data using data encryption services and then store the encrypted data in secrets.
- kubernetes.io/dockerconfigjson: a secret that stores the authentication information required for pulling images from a private repository. If you select this secret type, enter the image repository address.
- IngressTLS: a secret that stores the certificate required by ingresses. If you select this secret type, upload the certificate file and private key file.
- Other: another type of secret, which is specified manually.
Data
Workload secret data can be used in containers.
- If the secret type is Opaque, enter the key and value. The value must be a Base64-encoded value. You can select Auto Base64 Encoding to Base64-encode the entered value. For details about manual Base64 encoding, see Base64 Encoding.
- If the secret type is kubernetes.io/dockerconfigjson, enter the username and password of the private image repository.
Label
Labels are attached to objects such as workloads, nodes, and Services in key-value pairs.
Labels define identified attributes of these objects and can be used to manage and select objects.
- Set Key and Value.
- Click Confirm.
- Create a secret from a YAML file by clicking Create from YAML.
To create a resource by uploading a file, ensure that the resource description file has been created. UCS supports files in JSON or YAML format. For details, see Secret Resource File Configuration.
You can import or directly write the file content in YAML or JSON format. - When the configuration is complete, click OK.
The new secret is displayed in the secret list.
Secret Resource File Configuration
This section provides a configuration example of a secret resource file.
For example, you can retrieve the username and password for a workload through a secret.
- YAML format
The content in the secret file secret.yaml is as follows. The value must be encoded using Base64. For details, see Base64 Encoding.
apiVersion: v1 kind: Secret metadata: name: mysecret #Secret name namespace: default #Namespace. The default value is default. data: username: bXktdXNlcm5hbWUK #Username, which 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 content in the secret file secret.json is as follows:
{ "apiVersion": "v1", "kind": "Secret", "metadata": { "name": "mysecret", "namespace": "default" }, "data": { "username": "bXktdXNlcm5hbWUK", "password": "******" }, "type": "Opaque" }
Related Operations
The secrets in the kube-system namespace can only be viewed.
Operation |
Description |
---|---|
Editing a YAML file |
Click Edit YAML in the row where the target secret resides to edit its YAML file. |
Updating a secret |
|
Deleting a secret |
Click Delete in the row where the target secret resides. Delete the secret as prompted. |
Deleting secrets in batches |
|
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot