quick start · 2019-12-14 · assume that workload a needs to access workload b in the same cluster...

32
Cloud Container Engine Quick Start Issue 01 Date 2019-11-11 HUAWEI TECHNOLOGIES CO., LTD.

Upload: others

Post on 04-Jan-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Quick Start · 2019-12-14 · Assume that workload A needs to access workload B in the same cluster ... which will be used for identity authentication upon remote node login. If you

Cloud Container Engine

Quick Start

Issue 01

Date 2019-11-11

HUAWEI TECHNOLOGIES CO., LTD.

Page 2: Quick Start · 2019-12-14 · Assume that workload A needs to access workload B in the same cluster ... which will be used for identity authentication upon remote node login. If you

Copyright © Huawei Technologies Co., Ltd. 2019. All rights reserved.No part of this document may be reproduced or transmitted in any form or by any means without prior writtenconsent 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 and thecustomer. All or part of the products, services and features described in this document may not be within thepurchase 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, guarantees orrepresentations 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 (2019-11-11) Copyright © Huawei Technologies Co., Ltd. i

Page 3: Quick Start · 2019-12-14 · Assume that workload A needs to access workload B in the same cluster ... which will be used for identity authentication upon remote node login. If you

Contents

1 Instructions for Beginners........................................................................................................... 1

2 Creating a Kubernetes Hybrid Cluster......................................................................................3

3 Creating a Deployment (Nginx) from Images......................................................................... 7

4 Create a StatefulSet (Tomcat) from a YAML File..................................................................12

5 Deploying WordPress and MySQL That Depend on Each Other..................................... 205.1 Overview...................................................................................................................................................................... 205.2 Creating MySQL from a Workload Chart.................................................................................................................... 215.3 Creating WordPress from Images.................................................................................................................................23

Cloud Container EngineQuick Start Contents

Issue 01 (2019-11-11) Copyright © Huawei Technologies Co., Ltd. ii

Page 4: Quick Start · 2019-12-14 · Assume that workload A needs to access workload B in the same cluster ... which will be used for identity authentication upon remote node login. If you

1 Instructions for Beginners

This document provides instructions for getting started with the Cloud Container Engine(CCE).

You can use CCE by using the console, Kubernetes command-line tool (kubectl), andapplication programming interfaces (APIs). For details about CCE concepts, see BasicConcepts.

Procedure

Complete the following tasks to get started with CCE.

Figure 1-1 Procedure for getting started with CCE

Step 1 Authorize an IAM user to use CCE.

HUAWEI CLOUD accounts have the permission to use CCE. However, IAM users created byHUAWEI CLOUD accounts do not have the permission. You need to manually assign thepermission to IAM users. For details, see Permissions Management by IAM.

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

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

compute and network performance, see Creating a BMS Cluster.

Step 3 Create a workload from images or a chart.

Select existing images/chart, or create new images/chart.

l For details on how to create a workload from images, see Creating a Deployment fromImages.

Cloud Container EngineQuick Start 1 Instructions for Beginners

Issue 01 (2019-11-11) Copyright © Huawei Technologies Co., Ltd. 1

Page 5: Quick Start · 2019-12-14 · Assume that workload A needs to access workload B in the same cluster ... which will be used for identity authentication upon remote node login. If you

l For details on how to create a workload from a YAML file, see 4 Create a StatefulSet(Tomcat) from a YAML File.

l For details on how to create a workload from a chart, see 5.2 Creating MySQL from aWorkload Chart.

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

For details, see Basic Deployment Operations.

----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 you quicklyunderstand and use CCE.

2. Where can I find the instructions on creating Docker images for traditionalapplications?For details, see Containerizing Enterprise Applications in the Help Center. You canalso follow the ContainerOps User Guide.

3. Is CCE suitable for users who have little experience in building images?Yes. You can select images from Official Docker Hub Images, Third-party Images,and Shared Images pages on the CCE console. The My Images page displays only theimages created by you. For details, see 3 Creating a Deployment (Nginx) fromImages.

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

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 public networks: NodePort,LoadBalancer, and DNAT gateway. For details, see Setting Workload Access.

6. How can I allow multiple workloads in the same cluster to access each other?Select the access type ClusterIP, which allows workloads in the same cluster to use theircluster-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 cancreate an intra-cluster access (ClusterIP) service for workload B. After the ClusterIPservice is created, workload B is reachable at <self-defined service name>.<workloadB's namespace>.svc.cluster.local:<port number>.

Cloud Container EngineQuick Start 1 Instructions for Beginners

Issue 01 (2019-11-11) Copyright © Huawei Technologies Co., Ltd. 2

Page 6: Quick Start · 2019-12-14 · Assume that workload A needs to access workload B in the same cluster ... which will be used for identity authentication upon remote node login. If you

2 Creating a Kubernetes Hybrid Cluster

Preparationl 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 for CCEclusters. For details, see Creating a VPC.

l Create a key pair, which will be used for identity authentication upon remote node login.

If you use a password to log in to a node, skip this step. For details, see Creating a KeyPair.

l Plan the container CIDR block and service CIDR block before creating a cluster. TheCIDR block is a one-time configuration and cannot be changed after the cluster iscreated. If you want to use another container CIDR block, you have to create a newcluster and assign the new container CIDR block to the cluster.

Context

This section describes how to quickly create a hybrid cluster. For details, see Creating aHybrid Cluster. In this example, the default or simple configurations are in use.

Procedure

Step 1 Log in to the CCE console. Choose Dashboard > Buy Cluster to open the Buy HybridCluster page. An alternative way to open that page is to choose Resource Management >Clusters in the navigation pane and click Buy under Hybrid cluster.

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

In this example, a majority of parameters retain default values. For details, see Table 2-1.

Table 2-1 Parameters for creating a cluster

Parameter Description

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

Cloud Container EngineQuick Start 2 Creating a Kubernetes Hybrid Cluster

Issue 01 (2019-11-11) Copyright © Huawei Technologies Co., Ltd. 3

Page 7: Quick Start · 2019-12-14 · Assume that workload A needs to access workload B in the same cluster ... which will be used for identity authentication upon remote node login. If you

Parameter Description

*Region Geographical region where the cluster will reside. The nearest region isrecommended.

*EnterpriseProject

This parameter is displayed only for enterprise users who have enabledEnterprise Project Management.

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

*Version Cluster version. Cluster's Kubernetes baseline version. The latest versionis recommended.

*ManagementScale

Maximum number of worker nodes that can be managed by the cluster.If you select 50 nodes, the cluster can manage a maximum of 50 workernodes.

*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. After theVPC 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.

AuthenticationMode

By default, this parameter is left unspecified.

ClusterDescription

Optional parameter.

AdvancedSettings

Leave advanced settings unspecified.

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

After the cluster configuration is complete, click Next to go to the node creation page.

Step 3 On the node creation page, configure the following parameters:l Node: Select Create now.

Cloud Container EngineQuick Start 2 Creating a Kubernetes Hybrid Cluster

Issue 01 (2019-11-11) Copyright © Huawei Technologies Co., Ltd. 4

Page 8: Quick Start · 2019-12-14 · Assume that workload A needs to access workload B in the same cluster ... which will be used for identity authentication upon remote node login. If you

l Billing Mode: Nodes inherit the billing mode from the cluster to which they belong.l Current Region: Geological region where the node will reside. Retain the default

region.l AZ: Retain the default AZ.l Node Type: Select VM node.l 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.

l Specifications: Select node specifications that fit your business needs.l OS: Select the operating system (OS) of the nodes to be created.l 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.

l 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.l 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 passwordfor logging to the node and confirm the password.Please remember the node login password. If you forget the password, the system isunable to retrieve your password and you will have to reset the password.

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

Figure 2-1 Creating a key pair

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

Cloud Container EngineQuick Start 2 Creating a Kubernetes Hybrid Cluster

Issue 01 (2019-11-11) Copyright © Huawei Technologies Co., Ltd. 5

Page 9: Quick Start · 2019-12-14 · Assume that workload A needs to access workload B in the same cluster ... which will be used for identity authentication upon remote node login. If you

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

Step 4 Click Next to install cluster add-ons.

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

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

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 Cluster List toperform other operations on the cluster or click Go to Cluster Events to view the clusterdetails.

----End

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

Figure 2-2 Cluster list

Now, a Kubernetes cluster is created.

Cloud Container EngineQuick Start 2 Creating a Kubernetes Hybrid Cluster

Issue 01 (2019-11-11) Copyright © Huawei Technologies Co., Ltd. 6

Page 10: Quick Start · 2019-12-14 · Assume that workload A needs to access workload B in the same cluster ... which will be used for identity authentication upon remote node login. If you

3 Creating a Deployment (Nginx) from

Images

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

PrerequisitesA 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 server is a node inthe cluster.

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

Figure 3-1 Node's EIP

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

Nginx OverviewNginx is a lightweight web server. On Cloud Container Engine (CCE), you can quickly set upan Nginx web server.

The following describes how to create Nginx from an open-source Docker Hub image. Ittakes about 5 minutes to complete Nginx creation.

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

Cloud Container EngineQuick Start 3 Creating a Deployment (Nginx) from Images

Issue 01 (2019-11-11) Copyright © Huawei Technologies Co., Ltd. 7

Page 11: Quick Start · 2019-12-14 · Assume that workload A needs to access workload B in the same cluster ... which will be used for identity authentication upon remote node login. If you

Figure 3-2 Nginx web page

ProcedureThe following is the procedure for creating a containerized workload from a container image.

Step 1 In the navigation pane, choose Workloads > Deployments. On the page that is displayed,click Create Deployment.

Figure 3-3 Creating a Deployment

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

Cloud Container EngineQuick Start 3 Creating a Deployment (Nginx) from Images

Issue 01 (2019-11-11) Copyright © Huawei Technologies Co., Ltd. 8

Page 12: Quick Start · 2019-12-14 · Assume that workload A needs to access workload B in the same cluster ... which will be used for identity authentication upon remote node login. If you

Figure 3-4 Specifying basic workload information

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

Figure 3-5 Selecting an image

Step 4 Retain the default settings for the image parameters, and click Next.

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.

l Access Type: set to Node access (node port).l Service Name: workload name exposed to external networks. In this example, the

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

– Cluster level: External traffic is routed to all nodes in the cluster while maskingclients' source IP addresses.

– Node level: External traffic is routed to the node where the load balancer used bythe service is located, without masking clients' source IP addresses.

Cloud Container EngineQuick Start 3 Creating a Deployment (Nginx) from Images

Issue 01 (2019-11-11) Copyright © Huawei Technologies Co., Ltd. 9

Page 13: Quick Start · 2019-12-14 · Assume that workload A needs to access workload B in the same cluster ... which will be used for identity authentication upon remote node login. If you

l Port Settings:

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

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

– Access Port: If this parameter is set to Automatically Generated, CCE willautomatically open a real port on all nodes in the current cluster and map the realport number to a container port number.

Figure 3-6 Adding a service

Step 6 Click Next. Skip the advanced settings, and click Create.

Step 7 After Nginx is created, click Back to Workload List. In the workload list, you can view therunning Nginx.

Step 8 Access the Nginx.

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

Figure 3-7 Obtaining the external access address

2. Enter the external access address in the address box of a browser to connect to theworkload. Figure 3-8 shows the welcome page after you successfully access the Nginxworkload.

Cloud Container EngineQuick Start 3 Creating a Deployment (Nginx) from Images

Issue 01 (2019-11-11) Copyright © Huawei Technologies Co., Ltd. 10

Page 14: Quick Start · 2019-12-14 · Assume that workload A needs to access workload B in the same cluster ... which will be used for identity authentication upon remote node login. If you

Figure 3-8 Accessing the Nginx

----End

Cloud Container EngineQuick Start 3 Creating a Deployment (Nginx) from Images

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

Page 15: Quick Start · 2019-12-14 · Assume that workload A needs to access workload B in the same cluster ... which will be used for identity authentication upon remote node login. If you

4 Create a StatefulSet (Tomcat) from a YAML

File

Prerequisitesl A hybrid cluster has been created. For details, see Creating a Kubernetes Hybrid

Cluster.l 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 a StatefulSet andorganize them into a complete StatefulSet by using label selectors.

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

l Volumesl ConfigMapsl Secretsl Node label selectorsl Health check probesl 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 StatefulSet page, clickCreate YAML.

Cloud Container EngineQuick Start 4 Create a StatefulSet (Tomcat) from a YAML File

Issue 01 (2019-11-11) Copyright © Huawei Technologies Co., Ltd. 12

Page 16: Quick Start · 2019-12-14 · Assume that workload A needs to access workload B in the same cluster ... which will be used for identity authentication upon remote node login. If you

Figure 4-1 Creating a StatefulSet from a YAML file

Step 4 In the YAML Editor dialog box, configure parameters in the YAML template. The followingdescribes how to create a YAML file for Tomcat.l 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

l In the base template, define volumes.Before defining a volume, ensure that the volume has been created and has obtained aPersistentVolumeClaim (PVC). Three volume types are available: HUAWEI CLOUDElastic Volume Service (EVS), Scalable File System (SFS), and Object Storage Service(OBS). For details on how to create these types of volumes, see Creating an EVS Disk,Creating an SFS File System, and Creating an OBS Bucket.For details on how to create a PVC for a volume, see How Do I Use Cloud Storage?. Inthis example, a PVC named cce-evs-test will be created for an EVS volume. The EVSvolume will be mounted by using PV/PVC.apiVersion: apps/v1beta2 # for versions before 1.8.0 use apps/v1beta1kind: StatefulSetmetadata: name: tomcat-statefulset labels: app: tomcatspec: replicas: 1 selector:

Cloud Container EngineQuick Start 4 Create a StatefulSet (Tomcat) from a YAML File

Issue 01 (2019-11-11) Copyright © Huawei Technologies Co., Ltd. 13

Page 17: Quick Start · 2019-12-14 · Assume that workload A needs to access workload B in the same cluster ... which will be used for identity authentication upon remote node login. If you

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

l In the base template, define ConfigMaps.ConfigMap resources provide a way to inject configuration data into pods. Beforedefining ConfigMaps, create ConfigMaps first. For details on how to use a ConfigMap,see Using a ConfigMap.In this example, the ConfigMap is named special-config and contains two key-valuepairs: SPECIAL_LEVEL:very and SPECIAL_TYPE:charm. The ConfigMap will beused 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 EngineQuick Start 4 Create a StatefulSet (Tomcat) from a YAML File

Issue 01 (2019-11-11) Copyright © Huawei Technologies Co., Ltd. 14

Page 18: Quick Start · 2019-12-14 · Assume that workload A needs to access workload B in the same cluster ... which will be used for identity authentication upon remote node login. If you

l Add secrets.A secret is a type of resource that holds sensitive data, such as authentication and keyinformation. The secret that will be encrypted must be added to the secret list. For detailson 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

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

Cloud Container EngineQuick Start 4 Create a StatefulSet (Tomcat) from a YAML File

Issue 01 (2019-11-11) Copyright © Huawei Technologies Co., Ltd. 15

Page 19: Quick Start · 2019-12-14 · Assume that workload A needs to access workload B in the same cluster ... which will be used for identity authentication upon remote node login. If you

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

l In the base template, define health check probes.On CCE, you can configure health check probes to check container health. Two types ofprobes are used for health checking: liveness probes and readiness 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: - name: tomcat image: tomcat ports: - containerPort: 8080

Cloud Container EngineQuick Start 4 Create a StatefulSet (Tomcat) from a YAML File

Issue 01 (2019-11-11) Copyright © Huawei Technologies Co., Ltd. 16

Page 20: Quick Start · 2019-12-14 · Assume that workload A needs to access workload B in the same cluster ... which will be used for identity authentication upon remote node login. If you

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

l Create a LoadBalancer service for Tomcat.A LoadBalancer service exposes a workload to public networks. By using the HUAWEICLOUD load balancer created by the LoadBalancer service, the workload will bereachable at load balancer's IP address.For details on how to create a service, see Creating a Service.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 targetPort: 8080 type: LoadBalancer

Cloud Container EngineQuick Start 4 Create a StatefulSet (Tomcat) from a YAML File

Issue 01 (2019-11-11) Copyright © Huawei Technologies Co., Ltd. 17

Page 21: Quick Start · 2019-12-14 · Assume that workload A needs to access workload B in the same cluster ... which will be used for identity authentication upon remote node login. If you

Step 5 Click Create after completing the YAML configuration.

Figure 4-2 Completing YAML configuration

Step 6 After Tomcat is deployed successful, choose Workloads > StatefulSets in the navigationpane of the CCE console. You will see that tomcat-StatefulSet is in the Running state. Clickthe copy icon to copy the external access address.

Figure 4-3 Deployment successful

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

Cloud Container EngineQuick Start 4 Create a StatefulSet (Tomcat) from a YAML File

Issue 01 (2019-11-11) Copyright © Huawei Technologies Co., Ltd. 18

Page 22: Quick Start · 2019-12-14 · Assume that workload A needs to access workload B in the same cluster ... which will be used for identity authentication upon remote node login. If you

Figure 4-4 Access successful

----End

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

Cloud Container EngineQuick Start 4 Create a StatefulSet (Tomcat) from a YAML File

Issue 01 (2019-11-11) Copyright © Huawei Technologies Co., Ltd. 19

Page 23: Quick Start · 2019-12-14 · Assume that workload A needs to access workload B in the same cluster ... which will be used for identity authentication upon remote node login. If you

5 Deploying WordPress and MySQL That

Depend on Each Other

5.1 OverviewWordPress was originally a blog platform based on PHP and MySQL. It is gradually evolvedinto a content management system. You can set up your own blog website on any server thatsupports PHP and MySQL. Thousands of plug-ins and countless theme templates areavailable for WordPress and easy to install.

This section describes how to create an application whose components are dependent on eachother. Main components:

l WordPress, which will be created from images.l MySQL, which will be created from a workload chart.

Prerequisitesl A cluster with at least one node has been created and the node has an EIP. For details on

how to create a cluster, see Creating a Hybrid Cluster.

Figure 5-1 Node's EIP

Cloud Container EngineQuick Start

5 Deploying WordPress and MySQL That Depend on EachOther

Issue 01 (2019-11-11) Copyright © Huawei Technologies Co., Ltd. 20

Page 24: Quick Start · 2019-12-14 · Assume that workload A needs to access workload B in the same cluster ... which will be used for identity authentication upon remote node login. If you

5.2 Creating MySQL from a Workload ChartCCE uses Kubernetes Helm charts to describe a related set of Kubernetes resources. Chartsare quick to deploy and manage, greatly simplifying installation, scheduling, and managementof Kubernetes resources.

On the CCE console, charts are classified into official charts and custom charts.

This section describes how to create Mysql-ndb from the official mysql-ndb chart.

Mysql-ndb Chart

The mysql-ndb chart can quickly deploy MySQL NDB clusters.

A MySQL NDB cluster is a high-availability and high-redundancy version of MySQLadapted for the distributed computing environment. NDB Cluster is a technology that enablesclustering of in-memory databases in a shared-nothing system. NDB Cluster is free from anysingle point of failure.

Creating a MySQL Database from a Helm Chart

This section describes how to create a MySQL database using an official chart.

Step 1 Log in to the CCE console. In the navigation pane, choose Charts > Official Charts.

Step 2 On the Official Charts tab page, click Install Chart under the mysql-ndb chart.

Figure 5-2 Installing the mysql-ndb chart

Step 3 Set the installation parameters. Parameters marked with an asterisk (*) are mandatory.l Release Name: Specify the name of the workload created after the chart is released. For

example, mysql.l Chart Name: Select an installed template.l Chart Version: Currently, mysql-ndb supports only 1.0.0.l Cluster: Select the cluster where the workload will run.l Namespace: Select the namespace where the workload will run. If this parameter is left

unspecified, the default namespace is used.

Cloud Container EngineQuick Start

5 Deploying WordPress and MySQL That Depend on EachOther

Issue 01 (2019-11-11) Copyright © Huawei Technologies Co., Ltd. 21

Page 25: Quick Start · 2019-12-14 · Assume that workload A needs to access workload B in the same cluster ... which will be used for identity authentication upon remote node login. If you

l Workload Deployment Specifications: Select standard specifications or customize thespecifications.

l Description: Enter the description of the release.l Database Name: The default value is clustertest. You can also change the value.l Normal User Name of Database: The default value is testuser. You can also change the

value.l Normal User Login Password of Database: Retain the default value or set it as

required.l Administrator Password: The default value is root. You can also change the value. The

name of the MySQL administrator is root.

Figure 5-3 Configuring basic chart information

Step 4 After the configuration is complete, click Install Now. Confirm the specifications, and clickSubmit. Then click Back to Release List.

After the installation is complete, you can view the installed MySQL on the Releases tabpage.

Figure 5-4 Installed releases

Cloud Container EngineQuick Start

5 Deploying WordPress and MySQL That Depend on EachOther

Issue 01 (2019-11-11) Copyright © Huawei Technologies Co., Ltd. 22

Page 26: Quick Start · 2019-12-14 · Assume that workload A needs to access workload B in the same cluster ... which will be used for identity authentication upon remote node login. If you

Step 5 Click View Access Mode in the Operation column of the MySQL to view the access address,username, and password.

Figure 5-5 Viewing the access address

----End

Related Operations

For details on how to use the MySQL database, see 5.3 Creating WordPress from Images.

5.3 Creating WordPress from ImagesWordPress was originally a blog platform based on PHP and MySQL. It is gradually evolvedinto a content management system. You can set up your own blog website on any server thatsupports PHP and MySQL. Thousands of plug-ins and countless theme templates areavailable for WordPress and easy to install.

This section describes how to create a public WordPress website from images.

Prerequisitesl A cluster with at least one node has been created and the node has an EIP. For details on

how to create a cluster, see Creating a Hybrid Cluster.

Figure 5-6 Node's EIP

l The MySQL database has been created by following the instructions in 5.2 CreatingMySQL from a Workload Chart. In this example, WordPress data is stored in theMySQL database.

Cloud Container EngineQuick Start

5 Deploying WordPress and MySQL That Depend on EachOther

Issue 01 (2019-11-11) Copyright © Huawei Technologies Co., Ltd. 23

Page 27: Quick Start · 2019-12-14 · Assume that workload A needs to access workload B in the same cluster ... which will be used for identity authentication upon remote node login. If you

Creating a WordPress Blog Website

Step 1 In the navigation pane, choose Workloads > Deployments. Click Create Deployment.

Figure 5-7 Creating a workload

Step 2 Enter the basic information about the workload and retain the default values for otherparameters.l Workload Name: Set it to wordpress.l Cluster Name: Select the cluster where the workload will run. WordPress must run in

the same cluster as the MySQL database.l Instances: Set it to 1.

Figure 5-8 Setting the basic information about the workload

Step 3 Click Next to add a container. Click Add Container. On the Official Docker Hub Imagestab page, search for the wordpress image and click OK.

Cloud Container EngineQuick Start

5 Deploying WordPress and MySQL That Depend on EachOther

Issue 01 (2019-11-11) Copyright © Huawei Technologies Co., Ltd. 24

Page 28: Quick Start · 2019-12-14 · Assume that workload A needs to access workload B in the same cluster ... which will be used for identity authentication upon remote node login. If you

Figure 5-9 Selecting an image

Step 4 Set container parameters, including Image Version and Environment Variables, and clickNext.

l Image Version: Set it to latest.

Figure 5-10 Selecting an image version

l Environment Variables: Set environment variables to ensure that the WordPress canaccess the MySQL database.

Table 5-1 Environment variables

Variable Name Variable/Variable Reference Example

WORDPRESS_DB_HOST

Enter the MySQL access addressobtained in step 5 of Example:Deploying the MySQLDatabase Using a WorkloadTemplate.

10.0.0.0:3306

Cloud Container EngineQuick Start

5 Deploying WordPress and MySQL That Depend on EachOther

Issue 01 (2019-11-11) Copyright © Huawei Technologies Co., Ltd. 25

Page 29: Quick Start · 2019-12-14 · Assume that workload A needs to access workload B in the same cluster ... which will be used for identity authentication upon remote node login. If you

Variable Name Variable/Variable Reference Example

WORDPRESS_DB_USER

Name of the databaseadministrator. The default valueis root.

-

WORDPRESS_DB_PASSWORD

Administrator password. Ensurethat the password is the same asthe administrator password set instep 3 of Example: Deploying aMySQL Database Using aWorkload Template.

-

Step 5 Click Next, and set an access mode so that the workload can be accessed from externalnetworks by using an EIP.

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

l Access Type: set to Node access (node port).l Service Name: Service names are user-defined. It is recommended that the service name

be the same as the workload name. In this example, the service name is wordpress.l Service Affinity: In this example, Cluster level is selected.

– Cluster level: External traffic is routed to all nodes in the cluster while maskingclients' source IP addresses.

– Node level: External traffic is routed to the node where the load balancer used bythe service is located, without masking clients' source IP addresses.

l Port Settings:– Protocol: In this example, this parameter is set to TCP.– Container Port: In this example, this parameter is set to 80 (port number of the

WordPress workload). The port number is preset in the image.– Access Port: If this parameter is set to Automatically Generated, CCE will

automatically open a real port on all nodes in the current cluster and map the realport number to a container port number.

Figure 5-11 Adding a service

Cloud Container EngineQuick Start

5 Deploying WordPress and MySQL That Depend on EachOther

Issue 01 (2019-11-11) Copyright © Huawei Technologies Co., Ltd. 26

Page 30: Quick Start · 2019-12-14 · Assume that workload A needs to access workload B in the same cluster ... which will be used for identity authentication upon remote node login. If you

Step 6 Click Next. Skip the advanced settings, and click Create. Click Back to Workload List toview the running WordPress.

Step 7 Access the WordPress.

Click to copy the external access address and paste it in the browser to access theWordPress.

Figure 5-12 Accessing the WordPress

The following figure shows the accessed WordPress.

Cloud Container EngineQuick Start

5 Deploying WordPress and MySQL That Depend on EachOther

Issue 01 (2019-11-11) Copyright © Huawei Technologies Co., Ltd. 27

Page 31: Quick Start · 2019-12-14 · Assume that workload A needs to access workload B in the same cluster ... which will be used for identity authentication upon remote node login. If you

Figure 5-13 WordPress workload

Cloud Container EngineQuick Start

5 Deploying WordPress and MySQL That Depend on EachOther

Issue 01 (2019-11-11) Copyright © Huawei Technologies Co., Ltd. 28

Page 32: Quick Start · 2019-12-14 · Assume that workload A needs to access workload B in the same cluster ... which will be used for identity authentication upon remote node login. If you

Figure 5-14 WordPress

----End

Deleting ResourcesUntil now, you have completed all the Getting Started walkthroughs and have understood howto use CCE. Fees are incurred while nodes are running. If the clusters used in the GettingStarted walkthroughs are no longer in use, perform the following steps to delete them. If youwill continue the CCE walkthroughs, retain the clusters.

Step 1 Log in to the CCE console.

Step 2 Delete cluster resources.

1. In the navigation pane, choose Resource Management > Clusters.2. Click More > Delete in the same row as the cluster you will delete.

----End

Cloud Container EngineQuick Start

5 Deploying WordPress and MySQL That Depend on EachOther

Issue 01 (2019-11-11) Copyright © Huawei Technologies Co., Ltd. 29