getting started - support.huaweicloud.com · yes. you can select images from official docker hub...

25
Cloud Container Engine Getting Started Issue 01 Date 2020-06-01 HUAWEI TECHNOLOGIES CO., LTD.

Upload: others

Post on 21-Jun-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Getting Started - support.huaweicloud.com · Yes. You can select images from Official Docker Hub Images, Third-party Images, and Shared Images pages on the CCE console. The My Images

Cloud Container Engine

Getting Started

Issue 01

Date 2020-06-01

HUAWEI TECHNOLOGIES CO., LTD.

Page 2: Getting Started - support.huaweicloud.com · Yes. You can select images from Official Docker Hub Images, Third-party Images, and Shared Images pages on the CCE console. The My Images

Copyright © Huawei Technologies Co., Ltd. 2020. All rights reserved.

No part of this document may be reproduced or transmitted in any form or by any means without priorwritten consent of Huawei Technologies Co., Ltd. Trademarks and Permissions

and other Huawei trademarks are trademarks of Huawei Technologies Co., Ltd.All other trademarks and trade names mentioned in this document are the property of their respectiveholders. NoticeThe purchased products, services and features are stipulated by the contract made between Huawei andthe customer. All or part of the products, services and features described in this document may not bewithin the purchase scope or the usage scope. Unless otherwise specified in the contract, all statements,information, and recommendations in this document are provided "AS IS" without warranties, guaranteesor representations of any kind, either express or implied.

The information in this document is subject to change without notice. Every effort has been made in thepreparation of this document to ensure accuracy of the contents, but all statements, information, andrecommendations in this document do not constitute a warranty of any kind, express or implied.

Issue 01 (2020-06-01) Copyright © Huawei Technologies Co., Ltd. i

Page 3: Getting Started - support.huaweicloud.com · Yes. You can select images from Official Docker Hub Images, Third-party Images, and Shared Images pages on the CCE console. The My Images

Contents

1 Introduction.............................................................................................................................. 1

2 Preparations..............................................................................................................................3

3 Creating a Kubernetes Hybrid Cluster................................................................................5

4 Creating a Deployment (Nginx) from an Image........................................................... 10

5 Creating a StatefulSet (Tomcat) from a YAML File...................................................... 15

Cloud Container EngineGetting Started Contents

Issue 01 (2020-06-01) Copyright © Huawei Technologies Co., Ltd. ii

Page 4: Getting Started - support.huaweicloud.com · Yes. You can select images from Official Docker Hub Images, Third-party Images, and Shared Images pages on the CCE console. The My Images

1 Introduction

This document provides instructions for getting started with Cloud ContainerEngine (CCE).

You can use CCE by using the console, kubectl (Kubernetes command-linetool), and application programming interfaces (APIs). For details about CCEconcepts, see Basic Concepts.

ProcedureComplete the following tasks to get started with CCE.

Figure 1-1 Procedure for getting started with CCE

Step 1 Register a HUAWEI CLOUD account and grant permissions to IAM users.

HUAWEI CLOUD accounts have the permissions to use CCE. However, IAM userscreated by a HUAWEI CLOUD account do not have the permission. You need tomanually grant the permission to IAM users. For details, see PermissionsManagement.

Step 2 Create a cluster.● For details on how to create a regular Kubernetes cluster, see Creating a

Kubernetes Hybrid Cluster.● For details on how to create a Kubernetes cluster of bare metal servers that

provide high compute and network performance, see Buying a BMS Cluster.

Step 3 Create a workload from images or a chart.

Select an existing image/chart or create a new one.

Cloud Container EngineGetting Started 1 Introduction

Issue 01 (2020-06-01) Copyright © Huawei Technologies Co., Ltd. 1

Page 5: Getting Started - support.huaweicloud.com · Yes. You can select images from Official Docker Hub Images, Third-party Images, and Shared Images pages on the CCE console. The My Images

● For details on how to create a workload from an image, see 4 Creating aDeployment (Nginx) from an Image.

● For details on how to create a workload from a YAML file, see 5 Creating aStatefulSet (Tomcat) from a YAML File.

● For details on how to create a workload from a chart, see Creating MySQLfrom a Chart.

Step 4 View workload status and logs. Upgrade, scale, and monitor the workload.

For details, see Managing a Workload.

----End

FAQs1. Is HUAWEI CLOUD CCE suitable for users who are not familiar with

Kubernetes?Yes. The CCE console is easy-to-use, and the Getting Started guide helps youquickly understand and use CCE.

2. Where can I find the instructions on creating Docker images fortraditional applications?For details, see Containerizing an Enterprise Application (ERP) in the CCEBest Practices. You can also use HUAWEI CLOUD SWR to build a Dockerimage.

3. Is CCE suitable for users who have little experience in building images?Yes. You can select images from Official Docker Hub Images, Third-partyImages, and Shared Images pages on the CCE console. The My Images pagedisplays only the images created by you. For details, see 4 Creating aDeployment (Nginx) from an Image.

4. How do I create a workload using CCE?Create a cluster and then create a workload in the cluster. For details, see 4Creating a Deployment (Nginx) from an Image.

5. How do I create a workload accessible to public networks?CCE provides different workload access types to address diverse scenarios.Currently, CCE provides three access types to expose a workload to publicnetworks: NodePort, LoadBalancer, and DNAT. For details, see NetworkOverview.

6. How can I allow multiple workloads in the same cluster to access eachother?Select the access type ClusterIP, which allows workloads in the same cluster touse their cluster-internal domain names to access each other.Cluster-internal domain names are in the format of <self-defined servicename>.<workload's namespace>.svc.cluster.local:<port number>. For example,nginx.default.svc.cluster.local:80.Example:Assume that workload A needs to access workload B in the same cluster.Then, you can create a ClusterIP Service for workload B. After the ClusterIPService is created, workload B is reachable at <self-defined servicename>.<workload B's namespace>.svc.cluster.local:<port number>.

Cloud Container EngineGetting Started 1 Introduction

Issue 01 (2020-06-01) Copyright © Huawei Technologies Co., Ltd. 2

Page 6: Getting Started - support.huaweicloud.com · Yes. You can select images from Official Docker Hub Images, Third-party Images, and Shared Images pages on the CCE console. The My Images

2 Preparations

Before using CCE, you need to make the following preparations:

● Registering a HUAWEI CLOUD Account● Topping Up Your Account● Creating an IAM user● (Optional) Creating a Key Pair

Registering a HUAWEI CLOUD AccountIf you already have a HUAWEI CLOUD account, skip this part. If you do not have aHUAWEI CLOUD account, perform the following operations to create one:

1. Visit https://www.huaweicloud.com/intl/en-us/ and click Register.2. On the page displayed, register an account as prompted.

After the registration, the system automatically redirects you to your personalinformation page.

Topping Up Your AccountEnsure that your account has sufficient balance.

● For details about CCE pricing, see CCE Pricing Details.● For details about how to top up an account, see How Does a Common

HUAWEI CLOUD Customer Top Up an Account?.

Creating an IAM userIf you want to allow multiple users to manage your resources without sharingyour password or keys, you can create users using IAM and grant permissions tothe users. These users can use specified links and their own accounts to accessHUAWEI CLOUD and help you manage resources efficiently. You can alsoconfigure account security policies to ensure the security of these accounts.

HUAWEI CLOUD accounts have the permissions to use CCE. However, IAM userscreated by HUAWEI CLOUD accounts do not have the permissions. You need tomanually assign the permissions to IAM users. For details, see PermissionsManagement.

Cloud Container EngineGetting Started 2 Preparations

Issue 01 (2020-06-01) Copyright © Huawei Technologies Co., Ltd. 3

Page 7: Getting Started - support.huaweicloud.com · Yes. You can select images from Official Docker Hub Images, Third-party Images, and Shared Images pages on the CCE console. The My Images

(Optional) Creating a VPC

A VPC provides an isolated, configurable, and manageable virtual network for CCEclusters.

Before creating the first cluster, ensure that a VPC has been created. For details,see Creating a VPC.

If you already have a VPC available, skip this step.

(Optional) Creating a Key Pair

The cloud platform uses public key cryptography to protect the login informationof your CCE nodes. Passwords or key pairs are used for identity authenticationduring remote login to nodes.

● You need to specify the key pair name and provide the private key whenlogging to CCE nodes using SSH if you choose the key pair login mode. Fordetails, see Creating a Key Pair.

● If you choose the password login mode, skip this task.

If you want to create pods in multiple regions, you need to create a key pair in each region.For more information about regions, see Region and AZ.

Creating a Key Pair on the Management Console

If you have no key pair, create one on the management console. The procedure isas follows:

Step 1 Log in to the management console.

Step 2 Click in the upper left corner and select a region and a project.

Step 3 Under Computing, click Elastic Cloud Server.

Step 4 In the navigation pane on the left, choose Key Pair.

Step 5 On the right pane, click Create Key Pair.

Step 6 Enter the key name and click OK.

Step 7 A key pair name consists of two parts: KeyPair and four random digits. You canenter an easy-to-remember name, for example, KeyPair-xxxx_ecs.

Step 8 Manually or automatically download the private key file. The file name is aspecified key pair name with a suffix of .pem. Securely store the private key file. Inthe dialog box displayed, click OK.

The private key file can be downloaded only once. Keep it secure. When creating an ECS,provide the name of your desired key pair. Each time you log in to the ECS using SSH,provide the private key.

----End

Cloud Container EngineGetting Started 2 Preparations

Issue 01 (2020-06-01) Copyright © Huawei Technologies Co., Ltd. 4

Page 8: Getting Started - support.huaweicloud.com · Yes. You can select images from Official Docker Hub Images, Third-party Images, and Shared Images pages on the CCE console. The My Images

3 Creating a Kubernetes Hybrid Cluster

Preparation● Before creating your first cluster, you must create a VPC. If you already have

an available VPC, skip this preparatory step.A VPC provides an isolated, configurable, and manageable virtual network forCCE clusters. For details, see Creating a VPC.

● Create a key pair, which will be used for identity authentication upon remotenode login.If you use a password to log in to a node, skip this step. For details, seeCreating a Key Pair.

● Plan the container CIDR block and service CIDR block before creating acluster. The CIDR block is a one-time configuration and cannot be changedafter the cluster is created. If you want to use another container CIDR block,you have to create a new cluster and assign the new container CIDR block tothe cluster.

ContextThis section describes how to quickly create a hybrid cluster. For details, seeBuying a Hybrid Cluster. In this example, the default or simple configurations arein use.

Procedure

Step 1 Log in to the CCE console. Choose Dashboard > Buy Cluster to open the BuyHybrid Cluster page. An alternative way to open that page is to choose ResourceManagement > Clusters in the navigation pane and click Buy next to HybridCluster.

Step 2 On the Configure Cluster page, configure cluster parameters.

In this example, a majority of parameters retain default values. For details, seeTable 3-1.

Cloud Container EngineGetting Started 3 Creating a Kubernetes Hybrid Cluster

Issue 01 (2020-06-01) Copyright © Huawei Technologies Co., Ltd. 5

Page 9: Getting Started - support.huaweicloud.com · Yes. You can select images from Official Docker Hub Images, Third-party Images, and Shared Images pages on the CCE console. The My Images

Table 3-1 Parameters for creating a cluster

Parameter Description

*Billing Mode Two billing modes are available: yearly/monthy and pay-per-use. In this example, pay-per-use is selected.

*Region Geographical region where the cluster will reside. The nearestregion is recommended.

*EnterpriseProject

This parameter is displayed only for enterprise users who haveenabled Enterprise Project Management.

*ClusterName

Name of the cluster to be created. A cluster name contains 4 to128 characters starting with a lowercase letter and not endingwith a hyphen (-). Only lowercase letters, digits, and hyphens(-) are allowed.

*Version Cluster version. Cluster's Kubernetes baseline version. The latestversion is recommended.

*ManagementScale

Maximum number of worker nodes that can be managed bythe cluster. If you select 50 nodes, the cluster can manage amaximum of 50 worker nodes.

*HighAvailability

The default value is Yes.

*VPC VPC where the cluster will be located.If no VPC is available, click Create VPC to create a VPC. Afterthe VPC is created, click refresh.

*Subnet Subnet in which the cluster will run.

*NetworkModel

Retain the default settings.

*ContainerNetworkSegment

Select Automatically select.

ServiceNetworkSegment

The default value is Unspecified.

Authentication Mode

By default, this parameter is left unspecified.

ClusterDescription

Optional parameter.

AdvancedSettings

Leave advanced settings unspecified.

*ValidityPeriod

This parameter is hidden if the billing mode is pay-per-use.

Cloud Container EngineGetting Started 3 Creating a Kubernetes Hybrid Cluster

Issue 01 (2020-06-01) Copyright © Huawei Technologies Co., Ltd. 6

Page 10: Getting Started - support.huaweicloud.com · Yes. You can select images from Official Docker Hub Images, Third-party Images, and Shared Images pages on the CCE console. The My Images

After the cluster configuration is complete, click Next: Create Node to go to thenode creation page.

Step 3 On the node creation page, configure the following parameters:● Create Node: Select Create now.● Billing Mode: Nodes inherit the billing mode from the cluster to which they

belong.● Current Region: Geological region where the node will reside. Retain the

default region.● AZ: Retain the default AZ.● Node Type: Select VM node.● Node Name: Name of the node.

A node name must start with a lowercase letter and cannot end with a hyphen (-).Only digits, lowercase letters, and hyphens (-) are allowed.

● Specifications: Select node specifications that fit your business needs.● OS: Select the operating system (OS) of the nodes to be created.● EIP: Select Automatically assign and configure EIP parameters as follows:

– Quantity: set to 1.– Specifications: Retain the default value.– Billed By: Select Bandwidth.– Bandwidth Type: set to Dedicated.– Bandwidth: Select the required amount of bandwidth.

● System Disk and Data Disk: Set the disk space of the node.– System Disk: Set disk type and capacity based on the site requirements.

The default disk capacity is 40 GB.– Data Disk: Set disk type and capacity based on the site requirements. The

default disk capacity is 100 GB.● Login Mode: Currently, you can use a password or key pair to log in to the

node.– If the login mode is Password: The default username is root. Enter the

password for logging to the node and confirm the password.Please remember the node login password. If you forget the password,the system is unable to retrieve your password and you will have to resetthe password.

– If the login mode is Key pair, select a key pair for logging to the nodeand select the check box to acknowledge that you have obtained the keyfile and without this file you will not be able to log in to the node.A key pair is used for identity authentication when you remotely log in toa node. If no key pair is available, click Create a key pair. For details onhow to create a key pair, see Creating a Key Pair.

Cloud Container EngineGetting Started 3 Creating a Kubernetes Hybrid Cluster

Issue 01 (2020-06-01) Copyright © Huawei Technologies Co., Ltd. 7

Page 11: Getting Started - support.huaweicloud.com · Yes. You can select images from Official Docker Hub Images, Third-party Images, and Shared Images pages on the CCE console. The My Images

Figure 3-1 Creating a key pair

● Advanced ECS Settings: Do not specify ECS advanced settings.● Advanced Kubernetes Settings: Do not specify Kubernetes advanced

settings.● Nodes: The quantity of nodes you will create. The default value is 1.● Validity Period: This parameter is hidden if the billing mode is pay-per-use.

Step 4 Click Next: Install Add-on to install cluster add-ons.

System resource add-ons are mandatory. Advanced functional add-ons areoptional.

Install optional add-ons either when or after the cluster is created. To install add-ons after cluster creation, choose Add-ons in the navigation pane of the CCEconsole and select the add-on you will install. For details, see Add-ons.

Step 5 Click Buy Now and confirm the specifications.

Confirm the specifications you have configured and their prices.

Step 6 Click Pay Now.

It takes about 6 to 10 minutes to create a cluster. You can click Back to ClusterList to perform other operations on the cluster or click Go to Cluster Events toview the cluster details.

----End

VerificationAfter the cluster is created, you can view the cluster on the Clusters page.

Figure 3-2 Cluster list

Cloud Container EngineGetting Started 3 Creating a Kubernetes Hybrid Cluster

Issue 01 (2020-06-01) Copyright © Huawei Technologies Co., Ltd. 8

Page 12: Getting Started - support.huaweicloud.com · Yes. You can select images from Official Docker Hub Images, Third-party Images, and Shared Images pages on the CCE console. The My Images

Now, a Kubernetes cluster is created.

Cloud Container EngineGetting Started 3 Creating a Kubernetes Hybrid Cluster

Issue 01 (2020-06-01) Copyright © Huawei Technologies Co., Ltd. 9

Page 13: Getting Started - support.huaweicloud.com · Yes. You can select images from Official Docker Hub Images, Third-party Images, and Shared Images pages on the CCE console. The My Images

4 Creating a Deployment (Nginx) from anImage

You can use images to quickly create a single-pod workload that can be accessedfrom public networks. This section uses the Nginx application as an example.

Prerequisites

A cluster of at least one node has been created. The node has an elastic IP address(EIP).

A cluster is a logical group of cloud servers that run workloads. Each cloud serveris a node in the cluster.

For details on how to create a cluster, see Buying a Hybrid Cluster.

Figure 4-1 Node EIP

After the cluster is created, you can create a workload.

Nginx Overview

Nginx is a lightweight web server. On CCE, you can quickly set up a Nginx webserver.

The following describes how to create Nginx from an open-source Docker Hubimage. It takes about 5 minutes to complete Nginx creation.

After Nginx is created successfully, you can access the Nginx web page.

Cloud Container EngineGetting Started 4 Creating a Deployment (Nginx) from an Image

Issue 01 (2020-06-01) Copyright © Huawei Technologies Co., Ltd. 10

Page 14: Getting Started - support.huaweicloud.com · Yes. You can select images from Official Docker Hub Images, Third-party Images, and Shared Images pages on the CCE console. The My Images

Figure 4-2 Nginx web page

Procedure

The following is the procedure for creating a containerized workload from acontainer image.

Step 1 In the navigation pane, choose Workloads > Deployments. On the pagedisplayed, click Create Deployment.

Figure 4-3 Creating a Deployment

Step 2 Configure the following parameters and retain the default value for otherparameters:● Workload Name: Set it to nginx.● Cluster Name: Select the cluster where Nginx will run.● Instances: Set the quantity of pods to 1.

Figure 4-4 Specifying basic workload information

Cloud Container EngineGetting Started 4 Creating a Deployment (Nginx) from an Image

Issue 01 (2020-06-01) Copyright © Huawei Technologies Co., Ltd. 11

Page 15: Getting Started - support.huaweicloud.com · Yes. You can select images from Official Docker Hub Images, Third-party Images, and Shared Images pages on the CCE console. The My Images

Step 3 Click Next: Add Container. click Add Container. On the Official Docker HubImages tab page, search for the nginx image and click OK.

Figure 4-5 Selecting an image

Step 4 Retain the default values of image parameters and click Next: Set ApplicationAccess to set the workload access type.

Step 5 Click Add Service, set workload access parameters, and click OK.

In this example, the Nginx application will be externally accessible at an elastic IP address.

● Access Type: Select LoadBalancer (ELB).● Service Name: workload name exposed to external networks. In this example,

the service name is nginx.● Service Affinity: In this example, Cluster level is selected.

– Cluster level: The IP addresses and access ports of all nodes in a clustercan access the workload associated with the Service. Service access willcause performance loss due to route redirection, and the source IPaddress of the client cannot be obtained.

– Node level: Only the IP address and access port of the node where theworkload is located can access the workload associated with the Service.Service access will not cause performance loss due to route redirection,and the source IP address of the client can be obtained.

● ELB Configuration: Set the parameters based on service requirements. In thisexample, retain the default values.

● Port Settings:– Protocol: In this example, this parameter is set to TCP.

Cloud Container EngineGetting Started 4 Creating a Deployment (Nginx) from an Image

Issue 01 (2020-06-01) Copyright © Huawei Technologies Co., Ltd. 12

Page 16: Getting Started - support.huaweicloud.com · Yes. You can select images from Official Docker Hub Images, Third-party Images, and Shared Images pages on the CCE console. The My Images

– Container Port: port used by the workload for container listening. In thisexample, this parameter is set to 80.

– Access Port: Set this parameter to 8080. The port number is mapped tothe container port.

Figure 4-6 Adding a Service

Step 6 Click Next: Configure Advanced Settings. Skip the advanced settings, and clickCreate.

Step 7 After Nginx is created, click Back to Workload List. In the workload list, you canview the running Nginx.

Step 8 Access Nginx.

1. Obtain the external access address of the created Nginx.

Figure 4-7 Obtaining the external access address

2. Enter the external access address in the address box of a browser to connectto the workload. Figure 4-8 shows the welcome page after you successfullyaccess the Nginx workload.

Cloud Container EngineGetting Started 4 Creating a Deployment (Nginx) from an Image

Issue 01 (2020-06-01) Copyright © Huawei Technologies Co., Ltd. 13

Page 17: Getting Started - support.huaweicloud.com · Yes. You can select images from Official Docker Hub Images, Third-party Images, and Shared Images pages on the CCE console. The My Images

Figure 4-8 Accessing Nginx

----End

Helpful Links● Fault Locating and Troubleshooting for Abnormal Workloads● What Should I Do If Pod Scheduling Fails?● What Should I Do If Image Re-pull Fails?● What Should I Do If Container Restart Fails?

Cloud Container EngineGetting Started 4 Creating a Deployment (Nginx) from an Image

Issue 01 (2020-06-01) Copyright © Huawei Technologies Co., Ltd. 14

Page 18: Getting Started - support.huaweicloud.com · Yes. You can select images from Official Docker Hub Images, Third-party Images, and Shared Images pages on the CCE console. The My Images

5 Creating a StatefulSet (Tomcat) from aYAML File

Prerequisites● A hybrid cluster has been created. For details, see Creating a Kubernetes

Hybrid Cluster.● Volumes, ConfigMaps, secrets, node labels, and other resource objects

required for running a StatefulSet have been created.

ContextIn a YAML file, you need to define the resource objects required for running aStatefulSet and organize them into a complete StatefulSet by using label selectors.

This section uses Tomcat as an example. The following resource objects arerequired:

● Volumes● ConfigMaps● Secrets● Node label selectors● Health check probes● Services/load balancing

Procedure

Step 1 Log in to the CCE console.

Step 2 In the navigation pane, choose Workloads > StatefulSets.

Step 3 Click Create StatefulSet. In the upper right corner of the Create StatefulSetpage, click Create YAML.

Cloud Container EngineGetting Started 5 Creating a StatefulSet (Tomcat) from a YAML File

Issue 01 (2020-06-01) Copyright © Huawei Technologies Co., Ltd. 15

Page 19: Getting Started - support.huaweicloud.com · Yes. You can select images from Official Docker Hub Images, Third-party Images, and Shared Images pages on the CCE console. The My Images

Figure 5-1 Creating a StatefulSet from a YAML file

Step 4 In the YAML Editor dialog box, configure parameters in the YAML template. Thefollowing describes how to create a YAML file for Tomcat.● Create a base template (a YAML file) for Tomcat.

apiVersion: apps/v1beta2 # for versions before 1.8.0 use apps/v1beta1kind: StatefulSetmetadata: name: tomcat-statefulset labels: app: tomcatspec: replicas: 1 selector: matchLabels: app: tomcat template: metadata: labels: app: tomcat spec: containers: - name: tomcat image: tomcat # replace it with your exactly <image_name:tags> ports: - containerPort: 8080

● In the base template, define volumes.Before defining a volume, ensure that the volume has been created and hasobtained a PersistentVolumeClaim (PVC). Three volume types are available:HUAWEI CLOUD Elastic Volume Service (EVS), Scalable File System (SFS), andObject Storage Service (OBS). For details on how to create these types ofvolumes, see Using EVS Disks for Storage, Using SFS File Systems forStorage, and Using OBS Buckets for Storage.For details on how to create a PVC for a volume, see How Do I Use CloudStorage?. In this example, a PVC named cce-evs-test will be created for anEVS volume. The EVS volume will be mounted by using a PV/PVC.apiVersion: apps/v1beta2 # for versions before 1.8.0 use apps/v1beta1kind: StatefulSetmetadata: name: tomcat-statefulset labels: app: tomcatspec: replicas: 1

Cloud Container EngineGetting Started 5 Creating a StatefulSet (Tomcat) from a YAML File

Issue 01 (2020-06-01) Copyright © Huawei Technologies Co., Ltd. 16

Page 20: Getting Started - support.huaweicloud.com · Yes. You can select images from Official Docker Hub Images, Third-party Images, and Shared Images pages on the CCE console. The My Images

selector: matchLabels: app: tomcat template: metadata: labels: app: tomcat spec: containers: - name: tomcat image: tomcat # replace it with your exactly <image_name:tags> ports: - containerPort: 8080 volumeMounts: #add volume - name: cce-evs-test mountPath: /data volumes: #add volume - name: cce-evs-test persistentVolumeClaim: claimName: cce-evs-test

● In the base template, define ConfigMaps.ConfigMap resources provide a way to inject configuration data into pods.Before defining ConfigMaps, create ConfigMaps first. For details on how touse a ConfigMap, see Using a ConfigMap.In this example, the ConfigMap is named special-config and contains twokey-value pairs: SPECIAL_LEVEL:very and SPECIAL_TYPE:charm. TheConfigMap will be used as environment variables.apiVersion: apps/v1beta2 # for versions before 1.8.0 use apps/v1beta1kind: StatefulSetmetadata: name: tomcat-statefulset labels: app: tomcatspec: replicas: 1 selector: matchLabels: app: tomcat template: metadata: labels: app: tomcat spec: containers: - name: tomcat image: tomcat # replace it with your exactly <image_name:tags> ports: - containerPort: 8080 volumeMounts: - name: cce-evs-test mountPath: /data env: - name: SPECIAL_LEVEL_KEY #add configmap valueFrom: configMapKeyRef: name: special-config key: SPECIAL_LEVEL - name: SPECIAL_TYPE_KEY #add configmap valueFrom: configMapKeyRef: name: special-config key: SPECIAL_TYPE volumes: - name: cce-evs-test persistentVolumeClaim: claimName: cce-evs-test

Cloud Container EngineGetting Started 5 Creating a StatefulSet (Tomcat) from a YAML File

Issue 01 (2020-06-01) Copyright © Huawei Technologies Co., Ltd. 17

Page 21: Getting Started - support.huaweicloud.com · Yes. You can select images from Official Docker Hub Images, Third-party Images, and Shared Images pages on the CCE console. The My Images

● Add secrets.A secret is a type of resource that holds sensitive data, such as authenticationand key information. The secret that will be encrypted must be added to thesecret list. For details on how to create a secret, see Creating a Secret.apiVersion: apps/v1beta2 # for versions before 1.8.0 use apps/v1beta1kind: StatefulSetmetadata: name: tomcat-statefulset labels: app: tomcatspec: replicas: 1 selector: matchLabels: app: tomcat template: metadata: labels: app: tomcat spec: containers: - name: tomcat image: tomcat # replace it with your exactly <image_name:tags> ports: - containerPort: 8080 volumeMounts: - name: cce-evs-test mountPath: /data env: - name: SPECIAL_LEVEL_KEY valueFrom: configMapKeyRef: name: special-config key: SPECIAL_LEVEL - name: SPECIAL_TYPE_KEY valueFrom: configMapKeyRef: name: special-config key: SPECIAL_TYPE - name: SECRET_USERNAME #add secret valueFrom: secretKeyRef: name: account key: username - name: SECRET_PASSWORD #add secret valueFrom: secretKeyRef: name: account key: password volumes: - name: cce-evs-test persistentVolumeClaim: claimName: cce-evs-test

● In the base template, add node label selectors.When deploying a workload, you can schedule the workload onto nodes withspecified labels.In this example, the group:worker label is attached to a node. After Tomcat issuccessfully deployed, it will be scheduled onto the node with thegroup:worker label.apiVersion: apps/v1beta2 # for versions before 1.8.0 use apps/v1beta1kind: StatefulSetmetadata: name: tomcat-statefulset labels:

Cloud Container EngineGetting Started 5 Creating a StatefulSet (Tomcat) from a YAML File

Issue 01 (2020-06-01) Copyright © Huawei Technologies Co., Ltd. 18

Page 22: Getting Started - support.huaweicloud.com · Yes. You can select images from Official Docker Hub Images, Third-party Images, and Shared Images pages on the CCE console. The My Images

app: tomcatspec: replicas: 1 selector: matchLabels: app: tomcat template: metadata: labels: app: tomcat spec: containers: - name: tomcat image: tomcat ports: - containerPort: 8080 volumeMounts: - name: cce-evs-test mountPath: /data env: - name: SPECIAL_LEVEL_KEY valueFrom: configMapKeyRef: name: special-config key: SPECIAL_LEVEL - name: SPECIAL_TYPE_KEY valueFrom: configMapKeyRef: name: special-config key: SPECIAL_TYPE - name: SECRET_USERNAME valueFrom: secretKeyRef: name: account key: username - name: SECRET_PASSWORD valueFrom: secretKeyRef: name: account key: password volumes: - name: cce-evs-test persistentVolumeClaim: claimName: cce-evs-test nodeSelector: #add node selector group: worker

● In the base template, define health check probes.

On CCE, you can configure health check probes to check container health.Two types of probes are used for health checking: liveness probes andreadiness probes.apiVersion: apps/v1beta2 # for versions before 1.8.0 use apps/v1beta1kind: StatefulSetmetadata: name: tomcat-statefulset labels: app: tomcatspec: replicas: 1 selector: matchLabels: app: tomcat template: metadata: labels: app: tomcat spec: containers:

Cloud Container EngineGetting Started 5 Creating a StatefulSet (Tomcat) from a YAML File

Issue 01 (2020-06-01) Copyright © Huawei Technologies Co., Ltd. 19

Page 23: Getting Started - support.huaweicloud.com · Yes. You can select images from Official Docker Hub Images, Third-party Images, and Shared Images pages on the CCE console. The My Images

- name: tomcat image: tomcat ports: - containerPort: 8080 livenessProbe: #add health check httpGet: path: / port: 8080 initialDelaySeconds: 30 timeoutSeconds: 5 periodSeconds: 5 readinessProbe: #add health check httpGet: path: / port: 8080 initialDelaySeconds: 5 timeoutSeconds: 1 periodSeconds: 5 volumeMounts: - name: cce-evs-test mountPath: /data env: - name: SPECIAL_LEVEL_KEY valueFrom: configMapKeyRef: name: special-config key: SPECIAL_LEVEL - name: SPECIAL_TYPE_KEY valueFrom: configMapKeyRef: name: special-config key: SPECIAL_TYPE - name: SECRET_USERNAME valueFrom: secretKeyRef: name: account key: username - name: SECRET_PASSWORD valueFrom: secretKeyRef: name: account key: password volumes: - name: cce-evs-test persistentVolumeClaim: claimName: cce-evs-test nodeSelector: group: worker

● Create a LoadBalancer Service for Tomcat.A LoadBalancer Service exposes a workload to public networks. By using theHUAWEI CLOUD load balancer created by the LoadBalancer Service, theworkload will be reachable at load balancer's IP address.For details on how to create a Service, see Network Management.In the Tomcat example, the chart is as follows:apiVersion: v1kind: Servicemetadata: name: tomcat-svc labels: app: tomcat-svcspec: selector: app: tomcat ports: - protocol: TCP port: 8080

Cloud Container EngineGetting Started 5 Creating a StatefulSet (Tomcat) from a YAML File

Issue 01 (2020-06-01) Copyright © Huawei Technologies Co., Ltd. 20

Page 24: Getting Started - support.huaweicloud.com · Yes. You can select images from Official Docker Hub Images, Third-party Images, and Shared Images pages on the CCE console. The My Images

targetPort: 8080 type: LoadBalancer

Step 5 Click Create after completing the YAML configuration.

Figure 5-2 Completing YAML configuration

Step 6 After Tomcat is successfully deployed, choose Workloads > StatefulSets in thenavigation pane of the CCE console. You will see that tomcat-statefulset is in theRunning state. Click the copy icon to copy the external access address.

Figure 5-3 StatefulSet deployed successfully

Step 7 You can open the Tomcat welcome page in a browser.

Cloud Container EngineGetting Started 5 Creating a StatefulSet (Tomcat) from a YAML File

Issue 01 (2020-06-01) Copyright © Huawei Technologies Co., Ltd. 21

Page 25: Getting Started - support.huaweicloud.com · Yes. You can select images from Official Docker Hub Images, Third-party Images, and Shared Images pages on the CCE console. The My Images

Figure 5-4 Tomcat accessed normally

----End

Follow-Up OperationsBased on your chart, you can explore Tomcat-related features such as volumemanagement, secret management, ConfigMap management, node scheduling,and health check.

Cloud Container EngineGetting Started 5 Creating a StatefulSet (Tomcat) from a YAML File

Issue 01 (2020-06-01) Copyright © Huawei Technologies Co., Ltd. 22