Connecting a Client to DCS Through CCE
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
- Download a Redis client.
- 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.
- 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++
- 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
- 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
- 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 ..
- Log in to the CCE cluster node.
- 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.
- Build a client image.
- Choose Software Repository for Container from the service list to go to the SWR console.
- 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.)
- 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
- Run the copied login command on the CCE node to log in to SWR.
Figure 2 Logging in to SWR
- 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
- 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
- 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
- On the DCS console, click the created Redis instance dcs-test to go to the details page.
- In the Connection area, obtain the IP address and port number of the Redis instance.
- Click Connect to Redis in the upper right corner to use the Web CLI.
- On the Web CLI, run a SET command. The following figure uses SET hello "hello redis!" as an example.
- On the CCE console, click the created CCE cluster cce-test.
- 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
- If the workload is in the Running state, it has been successfully created.
Figure 7 Checking the workload status
Testing the Redis Connection
- Log in to the CCE cluster node. For details, see 1.a.
- Download and configure the kubectl configuration file by referring to Connecting to a Cluster Using kubectl.
- Run the following command. If Running is returned, the Redis container is running.
kubectl get pod -n default
- 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.
- The test is complete.
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