doc-exports/docs/cce/umn/cce_bestpractice_0010.html
Dong, Qiu Jian 86fb05065f CCE UMN for 24.2.0 version -20240428
Reviewed-by: Eotvos, Oliver <oliver.eotvos@t-systems.com>
Co-authored-by: Dong, Qiu Jian <qiujiandong1@huawei.com>
Co-committed-by: Dong, Qiu Jian <qiujiandong1@huawei.com>
2024-06-10 08:19:07 +00:00

100 lines
19 KiB
HTML

<a name="cce_bestpractice_0010"></a><a name="cce_bestpractice_0010"></a>
<h1 class="topictitle1">Creating a Container Workload</h1>
<div id="body1514888645779"><p id="cce_bestpractice_0010__p148771646679">This section describes how to deploy a workload on CCE. When using CCE for the first time, create an initial cluster and add a node into the cluster.</p>
<div class="note" id="cce_bestpractice_0010__note364316610194"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="cce_bestpractice_0010__p59989122181241">Containerized workloads are deployed in a similar way. The difference lies in:</p>
<ul id="cce_bestpractice_0010__ul22147669181314"><li id="cce_bestpractice_0010__li43949925181314">Whether environment variables need to be set.</li><li id="cce_bestpractice_0010__li40425758181317">Whether cloud storage is used.</li></ul>
</div></div>
<div class="section" id="cce_bestpractice_0010__section18618481919"><h4 class="sectiontitle">Required Cloud Services</h4><ul id="cce_bestpractice_0010__ul831765024713"><li id="cce_bestpractice_0010__li331715010479">Cloud Container Engine (CCE): a highly reliable and high-performance service that allows enterprises to manage containerized applications. With support for Kubernetes-native applications and tools, CCE makes it simple to set up an environment for running containers in the cloud.</li><li id="cce_bestpractice_0010__li157091053114715">Elastic Cloud Server (ECS): a scalable and on-demand cloud server. It helps you to efficiently set up reliable, secure, and flexible application environments, ensuring stable service running and improving O&amp;M efficiency.</li><li id="cce_bestpractice_0010__li17687259154720">Virtual Private Cloud (VPC): an isolated and private virtual network environment that users apply for in the cloud. You can configure the IP address ranges, subnets, and security groups, as well as assign elastic IP addresses and allocate bandwidth in a VPC.</li></ul>
</div>
<div class="section" id="cce_bestpractice_0010__section1482961017910"><h4 class="sectiontitle">Basic Concepts</h4><ul id="cce_bestpractice_0010__ul168011281394"><li id="cce_bestpractice_0010__li16680122819916">A cluster is a collection of computing resources, including a group of node resources. A container runs on a node. Before creating a containerized application, you must have an available cluster.</li><li id="cce_bestpractice_0010__li27531231895">A node is a virtual or physical machine that provides computing resources. You must have sufficient node resources to ensure successful operations such as creating applications. </li><li id="cce_bestpractice_0010__li98986331920">A workload indicates a group of container pods running on CCE. CCE supports third-party application hosting and provides the full lifecycle (from deployment to O&amp;M) management for applications. This section describes how to use a container image to create a workload.</li></ul>
</div>
<div class="section" id="cce_bestpractice_0010__section188985251214"><h4 class="sectiontitle">Procedure</h4><ol id="cce_bestpractice_0010__ol1825663213218"><li id="cce_bestpractice_0010__li1025612329217"><a name="cce_bestpractice_0010__li1025612329217"></a><a name="li1025612329217"></a><span>Prepare the environment as described in <a href="#cce_bestpractice_0010__table1399518309317">Table 1</a>.</span><p>
<div class="tablenoborder"><a name="cce_bestpractice_0010__table1399518309317"></a><a name="table1399518309317"></a><table cellpadding="4" cellspacing="0" summary="" id="cce_bestpractice_0010__table1399518309317" frame="border" border="1" rules="all"><caption><b>Table 1 </b>Preparing the environment</caption><thead align="left"><tr id="cce_bestpractice_0010__row1199703093116"><th align="left" class="cellrowborder" valign="top" width="7.920000000000001%" id="mcps1.3.5.2.1.2.1.2.4.1.1"><p id="cce_bestpractice_0010__p1081951683215">No.</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="18.81%" id="mcps1.3.5.2.1.2.1.2.4.1.2"><p id="cce_bestpractice_0010__p16997430173115">Category</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="73.27%" id="mcps1.3.5.2.1.2.1.2.4.1.3"><p id="cce_bestpractice_0010__p20997230103114">Procedure</p>
</th>
</tr>
</thead>
<tbody><tr id="cce_bestpractice_0010__row20997183017319"><td class="cellrowborder" valign="top" width="7.920000000000001%" headers="mcps1.3.5.2.1.2.1.2.4.1.1 "><p id="cce_bestpractice_0010__p11819171623218">1</p>
</td>
<td class="cellrowborder" valign="top" width="18.81%" headers="mcps1.3.5.2.1.2.1.2.4.1.2 "><p id="cce_bestpractice_0010__p1099715308314">Creating a VPC</p>
</td>
<td class="cellrowborder" valign="top" width="73.27%" headers="mcps1.3.5.2.1.2.1.2.4.1.3 "><p id="cce_bestpractice_0010__p12251621155413">Create a VPC before you create a cluster. A VPC provides an isolated, configurable, and manageable virtual network environment for CCE clusters.</p>
<p id="cce_bestpractice_0010__p385164035818">If you have a VPC already, skip to the next task.</p>
<ol type="a" id="cce_bestpractice_0010__ol727042112539"><li id="cce_bestpractice_0010__li1753852319535">Log in to the management console.</li><li id="cce_bestpractice_0010__li14696132515314">In the service list, choose <strong id="cce_bestpractice_0010__b129561340125715">Networking</strong> &gt; <strong id="cce_bestpractice_0010__b124713438579">Virtual Private Cloud</strong>.</li><li id="cce_bestpractice_0010__li8532162717530">On the <strong id="cce_bestpractice_0010__b842352706104051">Dashboard</strong> page, click <strong id="cce_bestpractice_0010__b2081831956103631">Create VPC</strong>.</li><li id="cce_bestpractice_0010__li10270821135314">Follow the instructions to create a VPC. Retain default settings for parameters unless otherwise specified.</li></ol>
</td>
</tr>
<tr id="cce_bestpractice_0010__row95361512153317"><td class="cellrowborder" valign="top" width="7.920000000000001%" headers="mcps1.3.5.2.1.2.1.2.4.1.1 "><p id="cce_bestpractice_0010__p1353661215330">2</p>
</td>
<td class="cellrowborder" valign="top" width="18.81%" headers="mcps1.3.5.2.1.2.1.2.4.1.2 "><p id="cce_bestpractice_0010__p5536612103314">Creating a key pair</p>
</td>
<td class="cellrowborder" valign="top" width="73.27%" headers="mcps1.3.5.2.1.2.1.2.4.1.3 "><p id="cce_bestpractice_0010__p1270061211540">Create a key pair before you create a containerized application. Key pairs are used for identity authentication during remote login to a node. If you have a key pair already, skip this task. </p>
<ol type="a" id="cce_bestpractice_0010__ol1142165117537"><li id="cce_bestpractice_0010__li19932548531">Log in to the management console.</li><li id="cce_bestpractice_0010__li180105665319">In the service list, choose <strong id="cce_bestpractice_0010__b1928103072812">Data Encryption Workshop</strong> under <strong id="cce_bestpractice_0010__b392873014286">Security &amp; Compliance</strong>.</li><li id="cce_bestpractice_0010__li1480815710536">In the navigation pane, choose <strong id="cce_bestpractice_0010__b149854893918">Key Pair Service</strong>. On the <strong id="cce_bestpractice_0010__b14656112406">Private Key Pairs</strong> tab, click <strong id="cce_bestpractice_0010__b1948231764017">Create Key Pair</strong>.</li><li id="cce_bestpractice_0010__li378118594537">Enter a key pair name, select <span class="uicontrol" id="cce_bestpractice_0010__uicontrol241535474412"><b>I agree to have the private key managed on the cloud</b></span> and <span class="uicontrol" id="cce_bestpractice_0010__uicontrol429491914518"><b>I have read and agree to the Key Pair Service Disclaimer</b></span>, and click <strong id="cce_bestpractice_0010__b2094719520566">OK</strong>.</li><li id="cce_bestpractice_0010__li914295117530">In the dialog box displayed, click <strong id="cce_bestpractice_0010__b11447735587">OK</strong>.<p id="cce_bestpractice_0010__en-us_topic_0053516957_p124778182714">View and save the key pair. For security purposes, a key pair can be downloaded only once. Keep it secure to ensure successful login. </p>
</li></ol>
</td>
</tr>
</tbody>
</table>
</div>
</p></li><li id="cce_bestpractice_0010__li75761023464"><span>Create a cluster and a node.</span><p><ol type="a" id="cce_bestpractice_0010__ol11431934869"><li id="cce_bestpractice_0010__li16388123263">Log in to the CCE console. On the <span class="uicontrol" id="cce_bestpractice_0010__uicontrol18993624144518"><b>Clusters</b></span> page, click <strong id="cce_bestpractice_0010__b71771832194515"></strong><strong id="cce_bestpractice_0010__b1515853017451">Create</strong> <strong id="cce_bestpractice_0010__b210862784520">Cluster</strong> and select the type for the cluster to be created.<p id="cce_bestpractice_0010__p1484994563810">Configure cluster parameters and select the VPC created in <a href="#cce_bestpractice_0010__li1025612329217">1</a>. </p>
</li><li id="cce_bestpractice_0010__li15999122053815">Create a node and select the key pair created in <a href="#cce_bestpractice_0010__li1025612329217">1</a> as the login option. </li></ol>
</p></li><li id="cce_bestpractice_0010__li8541912061"><span>Deploy a workload on CCE.</span><p><ol type="a" id="cce_bestpractice_0010__ol1610710121778"><li id="cce_bestpractice_0010__li836398383">Log in to the CCE console and click the name of the cluster to access the cluster console. In the navigation pane, choose <strong id="cce_bestpractice_0010__b1953510514717">Workloads</strong> and click <strong id="cce_bestpractice_0010__b19689194810714">Create Workload</strong>.</li><li id="cce_bestpractice_0010__li15350526133620">Configure the following parameters, and retain the default settings for other parameters:<ul id="cce_bestpractice_0010__ul159377554014"><li id="cce_bestpractice_0010__li1393685144017"><strong id="cce_bestpractice_0010__b1073684553419">Workload Name</strong>: Set it to <strong id="cce_bestpractice_0010__b84235270611610">apptest</strong>.</li><li id="cce_bestpractice_0010__li59372518408"><strong id="cce_bestpractice_0010__b2773131575412">Pods</strong>: Set it to <strong id="cce_bestpractice_0010__b4773115185413">1</strong>.</li></ul>
</li><li id="cce_bestpractice_0010__li182796474816">In the <span class="wintitle" id="cce_bestpractice_0010__wintitle12171855142114"><b>Container Settings</b></span> area, select the image uploaded in <a href="cce_bestpractice_0009.html">Building and Uploading an Image</a>.</li><li id="cce_bestpractice_0010__li15286167143415">In the <span class="wintitle" id="cce_bestpractice_0010__wintitle933831014418"><b>Container Settings</b></span> area, choose <span class="uicontrol" id="cce_bestpractice_0010__uicontrol11754894110"><b>Environment Variables</b></span> and add environment variables for interconnecting with the MySQL database. The environment variables are set in the <a href="cce_bestpractice_0007.html#cce_bestpractice_0007__li12314175319811">startup script</a>.<div class="note" id="cce_bestpractice_0010__note1582132112018"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="cce_bestpractice_0010__p15821232162017">In this example, interconnection with the MySQL database is implemented through configuring the environment variables. Determine whether to use environment variables based on your service requirements.</p>
</div></div>
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="cce_bestpractice_0010__table1965105283411" frame="border" border="1" rules="all"><caption><b>Table 2 </b>Configuring environment variables</caption><thead align="left"><tr id="cce_bestpractice_0010__row8651152183412"><th align="left" class="cellrowborder" valign="top" width="27%" id="mcps1.3.5.2.3.2.1.4.5.2.3.1.1"><p id="cce_bestpractice_0010__p76645263416">Variable Name</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="73%" id="mcps1.3.5.2.3.2.1.4.5.2.3.1.2"><p id="cce_bestpractice_0010__p666175216342">Variable Value/Variable Reference</p>
</th>
</tr>
</thead>
<tbody><tr id="cce_bestpractice_0010__row1066135263416"><td class="cellrowborder" valign="top" width="27%" headers="mcps1.3.5.2.3.2.1.4.5.2.3.1.1 "><p id="cce_bestpractice_0010__p196645220344">MYSQL_DB</p>
</td>
<td class="cellrowborder" valign="top" width="73%" headers="mcps1.3.5.2.3.2.1.4.5.2.3.1.2 "><p id="cce_bestpractice_0010__p96645210347">Database name.</p>
</td>
</tr>
<tr id="cce_bestpractice_0010__row196635217344"><td class="cellrowborder" valign="top" width="27%" headers="mcps1.3.5.2.3.2.1.4.5.2.3.1.1 "><p id="cce_bestpractice_0010__p066115223412">MYSQL_URL</p>
</td>
<td class="cellrowborder" valign="top" width="73%" headers="mcps1.3.5.2.3.2.1.4.5.2.3.1.2 "><p id="cce_bestpractice_0010__p866155263415">IP address and port number of the database.</p>
</td>
</tr>
<tr id="cce_bestpractice_0010__row96605212344"><td class="cellrowborder" valign="top" width="27%" headers="mcps1.3.5.2.3.2.1.4.5.2.3.1.1 "><p id="cce_bestpractice_0010__p1366152133414">MYSQL_USER</p>
</td>
<td class="cellrowborder" valign="top" width="73%" headers="mcps1.3.5.2.3.2.1.4.5.2.3.1.2 "><p id="cce_bestpractice_0010__p1366125215343">Database username.</p>
</td>
</tr>
<tr id="cce_bestpractice_0010__row535273615352"><td class="cellrowborder" valign="top" width="27%" headers="mcps1.3.5.2.3.2.1.4.5.2.3.1.1 "><p id="cce_bestpractice_0010__p535219361350">MYSQL_PASSWORD</p>
</td>
<td class="cellrowborder" valign="top" width="73%" headers="mcps1.3.5.2.3.2.1.4.5.2.3.1.2 "><p id="cce_bestpractice_0010__p1235293611356">Database user password.</p>
</td>
</tr>
</tbody>
</table>
</div>
</li><li id="cce_bestpractice_0010__li8246122043610">In the <span class="wintitle" id="cce_bestpractice_0010__wintitle14868145994820"><b>Container Settings</b></span> area, choose <strong id="cce_bestpractice_0010__b84235270615853">Data Storage</strong> and configure cloud storage for persistent data storage.<div class="note" id="cce_bestpractice_0010__note63639952216"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="cce_bestpractice_0010__p1136412915225">In this example, the MongoDB database is used and persistent data storage is also needed, so you need to configure cloud storage. Determine whether to use cloud storage based on your service requirements.</p>
</div></div>
<p id="cce_bestpractice_0010__p1839731763716">The mounted path must be the same as the MongoDB storage path in the Docker startup script. For details, see the <a href="cce_bestpractice_0007.html#cce_bestpractice_0007__li12314175319811">startup script</a>. In this example, the path is <strong id="cce_bestpractice_0010__b32821271555">/usr/local/mongodb/data</strong>.</p>
</li><li id="cce_bestpractice_0010__li19999112310401">In the <strong id="cce_bestpractice_0010__b144212318213">Service Settings</strong> area, click <span><img id="cce_bestpractice_0010__image688482275220" src="en-us_image_0000001897904609.png"></span> to add a service, configure workload access parameters, and click <span class="uicontrol" id="cce_bestpractice_0010__uicontrol552711812214"><b>OK</b></span>.<div class="note" id="cce_bestpractice_0010__note24721959165213"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="cce_bestpractice_0010__p24731559195216">In this example, the application will be accessible from public networks by using an elastic IP address.</p>
</div></div>
<ul id="cce_bestpractice_0010__ul69064431389"><li id="cce_bestpractice_0010__li1190616434813"><strong id="cce_bestpractice_0010__b27709281524">Service Name</strong>: name of the application that can be accessed externally. In this example, this parameter is set to <strong id="cce_bestpractice_0010__b8423527069017">apptest</strong>.</li><li id="cce_bestpractice_0010__li139217252466"><strong id="cce_bestpractice_0010__b144941850115212">Service Type</strong>: In this example, select <strong id="cce_bestpractice_0010__b10497155005216">NodePort</strong>.</li><li id="cce_bestpractice_0010__li195904442002"><strong id="cce_bestpractice_0010__b7882121610567">Service Affinity</strong><ul id="cce_bestpractice_0010__ul10852651217"><li id="cce_bestpractice_0010__li17623100818"><strong id="cce_bestpractice_0010__b209201053523">Cluster-level</strong>: The IP addresses and access ports of all nodes in a cluster can be used to access the workload associated with the Service. Service access will cause performance loss due to route redirection, and the source IP address of the client cannot be obtained.</li><li id="cce_bestpractice_0010__li54538251119"><strong id="cce_bestpractice_0010__b1365143120314">Node-level</strong>: Only the IP address and access port of the node where the workload is located can be used to 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.</li></ul>
</li><li id="cce_bestpractice_0010__li12615121100"><strong id="cce_bestpractice_0010__b549615410415">Port</strong><ul id="cce_bestpractice_0010__ul1181916301503"><li id="cce_bestpractice_0010__li44712813299"><strong id="cce_bestpractice_0010__b138355191115">Protocol</strong>: Set it to <strong id="cce_bestpractice_0010__b91501927514">TCP</strong>.</li><li id="cce_bestpractice_0010__li184881041124713"><strong id="cce_bestpractice_0010__b113321858165714">Service Port</strong>: port for accessing the Service.</li><li id="cce_bestpractice_0010__li121111217296"><strong id="cce_bestpractice_0010__b1243017571444">Container Port</strong>: port that the application will listen on the container. In this example, this parameter is set to <strong id="cce_bestpractice_0010__b842352706153430">8080</strong>.</li><li id="cce_bestpractice_0010__li11119112582916"><strong id="cce_bestpractice_0010__b17579455671">Node Port</strong>: Set it to <strong id="cce_bestpractice_0010__b4592055878">Auto</strong>. The system automatically opens a real port on all nodes in the current cluster and then maps the port number to the container port.</li></ul>
</li></ul>
</li><li id="cce_bestpractice_0010__li151183363920">Click <span class="uicontrol" id="cce_bestpractice_0010__uicontrol151411332096"><b>Create Workload</b></span>.<p id="cce_bestpractice_0010__p1128618537422">After the workload is created, you can view the running workload in the workload list.</p>
</li></ol>
</p></li></ol>
</div>
<div class="section" id="cce_bestpractice_0010__section1923817572133"><h4 class="sectiontitle">Verifying a Workload</h4><p id="cce_bestpractice_0010__p1678914614142">After a workload is created, you can access the workload to check whether the deployment is successful.</p>
<p id="cce_bestpractice_0010__p0756143914148">In the preceding configuration, the NodePort mode is selected to access the workload by using <span class="uicontrol" id="cce_bestpractice_0010__uicontrol149141659181716"><b>IP address:Port number</b></span>. If the access is successful, the workload is successfully deployed.</p>
<p id="cce_bestpractice_0010__p1870515317189">You can obtain the access mode from the <strong id="cce_bestpractice_0010__b32061864455">Access Mode</strong> tab on the workload details page.</p>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="cce_bestpractice_0340.html">Procedure</a></div>
</div>
</div>