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
Help Center/ Distributed Cache Service/ Best Practices/ Network Connection/ Connecting a Client to DCS Through CCE

Connecting a Client to DCS Through CCE

Updated on 2024-10-28 GMT+08:00

Overview

With the development of the container technology, more and more applications are deployed in containers. This section describes how to deploy a Redis client in a Cloud Container Engine (CCE) cluster container and connect it to DCS.

Prerequisites

Prepare the following resources:

  • VPC and subnet, for example, vpc-test. For details, see Creating a VPC.

    (Optional) Create two subnets. Place your DCS instance in one subnet (subnet 1) and your CCE cluster in the other (subnet 2).

  • DCS instance, for example, dcs-test. For details, see Buying a DCS Redis Instance.

    When creating a DCS instance, select the created VPC (vpc-test) and subnet 1.

  • CCE cluster, for example, cce-test. For details, see Buying a CCE Cluster.

    When creating a CCE cluster, set Network Model to VPC network, and select VPC vpc-test and subnet 2.

  • CCE node pool, for example, cce-test-nodepool. For details, see Creating a Node Pool.

    When creating a node pool, set Node Type to Elastic Cloud Server (VM), Container Engine to Docker, OS to CentOS 7.6, and bind an existing EIP or create one.

Procedure

Creating a Client Image

  1. Download a Redis client.

    1. Log in to the CCE cluster node.

      Click the name of the created node pool. On the displayed page, click Remote Login in the upper right corner.

    2. Run the gcc --version command to check whether the GCC compiler for compiling the Redis program is installed in the OS. The following figure shows that the GCC compiler has been installed.

      If the GCC compiler is not installed, run the following commands to install it:

      yum -y install gcc
      yum -y install gcc-c++
    3. Run the following command to create the redis directory in the home directory, and then go to the directory:
      cd /home && mkdir redis && cd redis
    4. Run the following command to download the Redis client. The following takes version 5.0.13 as an example.
      wget https://download.redis.io/releases/redis-5.0.13.tar.gz

    5. Decompress the Redis package, go to the Redis directory, run the compilation command, and return to the Redis directory.
      tar xvzf redis-5.0.13.tar.gz
      cd redis-5.0.13 && make redis-cli
      cd ..

  2. Create a Dockerfile.

    Run the vim Dockerfile command to create a Dockerfile and enter the following information:

    FROM centos:7
    RUN useradd -d /home/redis -m redis 
    COPY ./redis-5.0.13 /home/redis/redis-5.0.13
    RUN chown redis:redis /home/redis/redis-5.0.13 -R
    USER redis
    ENV  HW_HOME=/home/redis/redis-5.0.13        
    ENV   PATH=$HW_HOME/src:$PATH   
    WORKDIR /home/redis/

    Press Esc to exit the editing mode and run :wq! to save the configuration and exit the editing interface.

  3. Build a client image.

    1. Choose Software Repository for Container from the service list to go to the SWR console.
    2. Click Create Organization in the upper right corner and enter an organization name to create an organization. You can also use an existing organization. (Click Organization Management in the navigation pane to view organizations.)
    3. On the SWR Dashboard page, click Generate Login Command in the upper right corner to obtain and copy the login command. (swr.xxxxxx.com at the end of the login command is the image repository address.)
      Figure 1 Obtaining a login command
    4. Run the copied login command on the CCE node to log in to SWR.
      Figure 2 Logging in to SWR
    5. Run the following command to build an image:
      docker build -t {Image repository address}/{Organization name}/{Image name :version}.

      Image repository address indicates the address of the image repository, which is at the end of the login command. Organization name indicates the name of the organization created in b. Image name indicates the name of the image to be built. version indicates the image version. Replace them with the actual values. For example, docker build -t swr.xxxxxx.com/study1/redis:v1.

      Figure 3 Building an image

  4. Run the following command to upload the client image to SWR:

    docker push {Image repository address}/{Organization name}/{Image name :version}
    Figure 4 Uploading an image

  5. After the image is uploaded, you can view it on the My Images page of the SWR console.

    Figure 5 Viewing images

Deploying an Image on CCE

  1. On the DCS console, click the created Redis instance dcs-test to go to the details page.
  2. In the Connection area, obtain the IP address and port number of the Redis instance.
  3. Click Connect to Redis in the upper right corner to use the Web CLI.
  4. On the Web CLI, run a SET command. The following figure uses SET hello "hello redis!" as an example.

  5. On the CCE console, click the created CCE cluster cce-test.
  6. In the navigation pane, choose Workloads. Click Create Workload in the upper right corner. For details, see Creating a Workload.

    • In the Container Settings > Basic Info area, set Image Name to the name of the created Redis image.
    • In the Container Settings > Lifecycle area, configure the parameters as follows:

      Command: /bin/bash

      Args: -c

      while true ;do sleep 10;/home/redis/redis-5.0.13/src/redis-cli -h 10.0.0.0 -p 6379 -a DCS instance password get hello;done

      In the preceding command, 10.0.0.0 indicates the IP address of the DCS instance, 6379 indicates the port number of the DCS instance, DCS instance password indicates the password of the DCS instance, and hello indicates the data set when you connect to Redis through the Web CLI. Replace them with the actual values.

      Figure 6 Configuring lifecycle parameters

  7. If the workload is in the Running state, it has been successfully created.

    Figure 7 Checking the workload status

Testing the Redis Connection

  1. Log in to the CCE cluster node. For details, see 1.a.
  2. Download and configure the kubectl configuration file by referring to Connecting to a Cluster Using kubectl.
  3. Run the following command. If Running is returned, the Redis container is running.

    kubectl get pod -n default

  4. Run the following command to view the logs of the Redis container:

    kubectl logs --tail 10 -f redis-xxxxxxxx -n default

    redis-xxxxxxxx indicates the name of the created workload pod. (Click the workload name to view the workload pod name.)

    In the command output, the information returned by DCS is hello redis!, which is the data set when you connected to Redis.

  5. The test is complete.

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