Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Situation Awareness
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
Software Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

Creating a Secret

Updated on 2024-01-26 GMT+08:00

Scenario

A secret is a type of resource that holds sensitive data, such as authentication and key information. Its content is user-defined. After creating secrets, you can use them as files or environment variables in a containerized workload.

Constraints

Secrets cannot be used in static pods.

Procedure

  1. Log in to the CCE console and click the cluster name to access the cluster console.
  2. Choose ConfigMaps and Secrets in the navigation pane, click the Secrets tab, and click Create Secret in the upper right corner.
  3. Set parameters.

    Table 1 Parameters for creating a secret

    Parameter

    Description

    Name

    Name of the secret you create, which must be unique.

    Namespace

    Namespace to which the secret belongs. If you do not specify this parameter, the value default is used by default.

    Description

    Description of a secret.

    Type

    Type of the secret you create.

    • Opaque: common secret.
    • kubernetes.io/dockerconfigjson: a secret that stores the authentication information required for pulling images from a private repository.
    • kubernetes.io/tls: Kubernetes TLS secret, which is used to store the certificate required by layer-7 load balancing Services. For details about examples of the kubernetes.io/tls secret and its description, see TLS secrets.
    • IngressTLS: TLS secret provided by CCE to store the certificate required by layer-7 load balancing Services.
    • Other: another type of secret, which is specified manually.

    Secret Data

    Workload secret data can be used in containers.

    • If Secret Type is Opaque, click . In the dialog box displayed, enter a key-value pair and select Auto Base64 Encoding.
    • If Secret Type is kubernetes.io/dockerconfigjson, enter the account and password for logging in to the private image repository.
    • If Secret Type is kubernetes.io/tls or IngressTLS, upload the certificate file and private key file.
      NOTE:
      • A certificate is a self-signed or CA-signed credential used for identity authentication.
      • A certificate request is a request for a signature with a private key.

    Secret Label

    Label of the secret. Enter a key-value pair and click Add.

  4. After the configuration is complete, click OK.

    The new secret is displayed in the key list.

Secret Resource File Configuration Example

This section describes configuration examples of secret resource description files.

  • Opaque type

    The secret.yaml file is defined as shown below. The data field is filled in as a key-value pair, and the value field must be encoded using Base64. For details about the Base64 encoding method, see Base64 Encoding.

    apiVersion: v1
    kind: Secret
    metadata:
      name: mysecret           #Secret name
      namespace: default       #Namespace. The default value is default.
    data:
      <your_key>: <your_value>  # Enter a key-value pair. The value must be encoded using Base64.
    type: Opaque
  • kubernetes.io/dockerconfigjson type

    The secret.yaml file is defined as shown below. The value of .dockerconfigjson 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:
      .dockerconfigjson: eyJh*****    # Content encoded using Base64.
    type: kubernetes.io/dockerconfigjson

    To obtain the .dockerconfigjson content, perform the following steps:

    1. Obtain the following login information of the image repository.
      • Image repository address: The section uses address as an example. Replace it with the actual address.
      • Username: The section uses username as an example. Replace it with the actual username.
      • Password: The section uses password as an example. Replace it with the actual password.
    2. Use Base64 to encode the key-value pair username:password and fill the encoded content in 3.
      echo -n "username:password" | base64

      Command output:

      dXNlcm5hbWU6cGFzc3dvcmQ=
    3. Use Base64 to encode the following JSON content:
      echo -n '{"auths":{"address":{"username":"username","password":"password","auth":"dXNlcm5hbWU6cGFzc3dvcmQ="}}}' | base64

      Command output:

      eyJhdXRocyI6eyJhZGRyZXNzIjp7InVzZXJuYW1lIjoidXNlcm5hbWUiLCJwYXNzd29yZCI6InBhc3N3b3JkIiwiYXV0aCI6ImRYTmxjbTVoYldVNmNHRnpjM2R2Y21RPSJ9fX0=

      The encoded content is the .dockerconfigjson content.

  • kubernetes.io/tls type
    The value of tls.crt and tls.key must be encoded using Base64. For details, see Base64 Encoding.
    kind: Secret
    apiVersion: v1
    metadata:
      name: mysecret           #Secret name
      namespace: default       #Namespace. The default value is default.
    data:
      tls.crt: LS0tLS1CRU*****FURS0tLS0t  # Certificate content, which must be encoded using Base64.
      tls.key: LS0tLS1CRU*****VZLS0tLS0=  # Private key content, which must be encoded using Base64.
    type: kubernetes.io/tls
  • IngressTLS type
    The value of tls.crt and tls.key must be encoded using Base64. For details, see Base64 Encoding.
    kind: Secret
    apiVersion: v1
    metadata:
      name: mysecret           #Secret name
      namespace: default       #Namespace. The default value is default.
    data:
      tls.crt: LS0tLS1CRU*****FURS0tLS0t  # Certificate content, which must be encoded using Base64.
      tls.key: LS0tLS1CRU*****VZLS0tLS0=  # Private key content, which must be encoded using Base64.
    type: IngressTLS

Creating a Secret Using kubectl

  1. According to Connecting to a Cluster Using kubectl, configure the kubectl command to connect an ECS to the cluster.
  2. Create and edit the Base64-encoded cce-secret.yaml file.

    # echo -n "content to be encoded" | base64
    ******

    vi cce-secret.yaml

    The following YAML file uses the Opaque type as an example. For details about other types, see Secret Resource File Configuration Example.

    apiVersion: v1
    kind: Secret
    metadata:
      name: mysecret
    type: Opaque
    data:
      <your_key>: <your_value>  # Enter a key-value pair. The value must be encoded using Base64.

  3. Create a secret.

    kubectl create -f cce-secret.yaml

    You can query the secret after creation.

    kubectl get secret -n default

Related Operations

After creating a secret, you can update or delete it as described in Table 2.
NOTE:

The secret list contains system secret resources that can be queried only. The system secret resources cannot be updated or deleted.

Table 2 Related Operations

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

  1. Select the name of the secret to be updated and click Update.
  2. Modify the secret data. For more information, see Table 1.
  3. Click OK.

Deleting a secret

Select the secret you want to delete and click Delete.

Follow the prompts to delete the secret.

Deleting secrets in batches

  1. Select the secrets to be deleted.
  2. Click Delete above the secret list.
  3. Follow the prompts to delete the secrets.

Base64 Encoding

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

root@ubuntu:~# echo -n "content to be encoded" | base64
******

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback