github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/docs/user_docs/try-out-on-playground/try-kubeblocks-on-cloud.md (about) 1 --- 2 title: Try out KubeBlocks on Cloud 3 description: How to run Playground on Cloud 4 keywords: [Playground, try out, cloud] 5 sidebar_position: 1 6 sidebar_label: Try out KubeBlocks on cloud 7 --- 8 9 import Tabs from '@theme/Tabs'; 10 import TabItem from '@theme/TabItem'; 11 12 # Try out KubeBlocks on Cloud 13 14 This guide walks you through the quickest way to get started with KubeBlocks on cloud, demonstrating how to create a demo environment (Playground) with one command. 15 16 ## Preparation 17 18 When deploying KubeBlocks on the cloud, cloud resources are initialized with the help of [the terraform script](https://github.com/apecloud/cloud-provider). `kbcli` downloads the script and stores it locally, then calls the terraform commands to initialize a fully-managed Kubernetes cluster and deploy KubeBlocks on this cluster. 19 20 <Tabs> 21 <TabItem value="AWS" label="AWS" default> 22 23 ### Before you start to try KubeBlocks on AWS 24 25 Make sure you have all the followings prepared. 26 27 * [Install AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html) 28 * [Install kubectl](https://kubernetes.io/docs/tasks/tools/#kubectl) 29 * [Install kbcli](./../installation/install-with-kbcli/install-kbcli.md) 30 31 ### Configure access key 32 33 **Option 1.** Use `aws configure`. 34 35 Fill in an access key and run the command below to authenticate the requests. 36 37 ```bash 38 aws configure 39 AWS Access Key ID [None]: YOUR_ACCESS_KEY_ID 40 AWS Secret Access Key [None]: YOUR_SECRET_ACCESS_KEY 41 ``` 42 43 You can refer to [Quick configuration with aws configure](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-quickstart.html#cli-configure-quickstart-config) for detailed information. 44 45 **Option 2.** Use environment variables. 46 47 ```bash 48 export AWS_ACCESS_KEY_ID="YOUR_ACCESS_KEY_ID" 49 export AWS_SECRET_ACCESS_KEY="YOUR_SECRET_ACCESS_KEY" 50 ``` 51 52 ### Initialize Playground 53 54 ```bash 55 kbcli playground init --cloud-provider aws --region us-west-2 56 ``` 57 58 * `cloud-provider` specifies the cloud provider. 59 * `region` specifies the region to deploy a Kubernetes cluster. 60 You can find the region list on [the official website](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services/?nc1=h_ls). 61 62 During the initialization, `kbcli` clones [the GitHub repository](https://github.com/apecloud/cloud-provider) to the directory `~/.kbcli/playground`, installs KubeBlocks, and creates a MySQL cluster. After executing the `kbcli playground init` command, kbcli automatically switches the current context of kubeconfig to the new Kubernetes cluster. 63 Run the command below to view the created cluster. 64 65 ```bash 66 # View kbcli version 67 kbcli version 68 69 # View the cluster list 70 kbcli cluster list 71 ``` 72 73 :::note 74 75 The initialization lasts about 20 minutes. If the installation fails after a long time, please check your network. 76 77 ::: 78 79 </TabItem> 80 <TabItem value="GCP" label="GCP"> 81 82 ### Before you start to try KubeBlocks on GCP 83 84 Make sure you have all the followings prepared. 85 86 * Google Cloud account 87 * [Install kubectl](https://kubernetes.io/docs/tasks/tools/#kubectl) 88 * [Install kbcli](./../installation/install-with-kbcli/install-kbcli.md) 89 90 ### Configure GCP environment 91 92 ***Steps:*** 93 94 1. Install Google Cloud SDK. 95 96 ```bash 97 # macOS brew install 98 brew install --cask google-cloud-sdk 99 100 # windows 101 choco install gcloudsdk 102 ``` 103 104 2. Initialize GCP. 105 106 ```bash 107 gcloud init 108 ``` 109 110 3. Log in to GCP. 111 112 ```bash 113 gcloud auth application-default login 114 ``` 115 116 4. Configure GOOGLE_PROJECT environment variables,```kbcli playground``` creates GKE cluster in the project. 117 118 ```bash 119 export GOOGLE_PROJECT=<project-name> 120 ``` 121 122 ### Initialize Playground 123 124 The following command deploys a GKE service in the region `us-central1` on GCP, and installs KubeBlocks. 125 126 ```bash 127 kbcli playground init --cloud-provider gcp --region us-central1 128 ``` 129 130 * `cloud-provider` specifies the cloud provider. 131 * `region` specifies the region to deploy a Kubernetes cluster. 132 133 During the initialization, `kbcli` clones [the GitHub repository](https://github.com/apecloud/cloud-provider) to the directory `~/.kbcli/playground`, installs KubeBlocks, and creates a MySQL cluster. After executing the `kbcli playground init` command, kbcli automatically switches the current context of kubeconfig to the new Kubernetes cluster. 134 Run the command below to view the created cluster. 135 136 ```bash 137 # View kbcli version 138 kbcli version 139 140 # View the cluster list 141 kbcli cluster list 142 ``` 143 144 :::note 145 146 The initialization takes about 20 minutes. If the installation fails after a long time, please check your network. 147 148 ::: 149 150 </TabItem> 151 <TabItem value="Tencent Cloud" label="Tencent Cloud"> 152 153 ### Before you start to try KubeBlocks on Tencent Cloud 154 155 Make sure you have all the followings prepared. 156 157 * Tencent Cloud account 158 * [Install kubectl](https://kubernetes.io/docs/tasks/tools/#kubectl) 159 * [Install kbcli](./../installation/install-with-kbcli/install-kbcli.md) 160 161 ### Configure TKE environment 162 163 ***Steps:*** 164 165 1. Log in to Tencent Cloud. 166 2. Go to [Tencent Kubernetes Engine (TKE)](https://console.cloud.tencent.com/tke2) to grant resource operation permission to your account before using the container service. 167 3. Go to [API Console](https://console.cloud.tencent.com/cam/overview) -> **Access Key** -> **API Keys** and click **Create Key** to create a pair of Secret ID and Secret Key. 168 4. Add the Secret ID and Secret Key to the environment variables. 169 170 ```bash 171 export TENCENTCLOUD_SECRET_ID=YOUR_SECRET_ID 172 export TENCENTCLOUD_SECRET_KEY=YOUR_SECRET_KEY 173 ``` 174 175 ### Initialize Playground 176 177 The following command deploys a Kubernetes service in the region `ap-chengdu` on Tencent Cloud and installs KubeBlocks. 178 179 ```bash 180 kbcli playground init --cloud-provider tencentcloud --region ap-chengdu 181 ``` 182 183 * `cloud-provider` specifies the cloud provider. 184 * `region` specifies the region to deploy a Kubernetes cluster. 185 186 During the initialization, `kbcli` clones [the GitHub repository](https://github.com/apecloud/cloud-provider) to the directory `~/.kbcli/playground`, installs KubeBlocks, and creates a MySQL cluster. After executing the `kbcli playground init` command, kbcli automatically switches the current context of kubeconfig to the new Kubernetes cluster. 187 Run the command below to view the created cluster. 188 189 ```bash 190 # View kbcli version 191 kbcli version 192 193 # View the cluster list 194 kbcli cluster list 195 ``` 196 197 :::note 198 199 The initialization takes about 20 minutes. If the installation fails after a long time, please check your network. 200 201 ::: 202 203 </TabItem> 204 <TabItem value="Alibaba Cloud" label="Alibaba Cloud"> 205 206 ### Before you start to try KubeBlocks on Alibaba Cloud 207 208 Make sure you have all the followings prepared. 209 210 * Alibaba Cloud account. 211 * [Install kubectl](https://kubernetes.io/docs/tasks/tools/#kubectl) 212 * [Install kbcli](./../installation/install-with-kbcli/install-kbcli.md) 213 214 ### Configure ACK environment 215 216 ***Steps:*** 217 218 1. Log in to Alibaba Cloud. 219 2. Follow the instructions in [Quick start for first-time users](https://www.alibabacloud.com/help/en/container-service-for-kubernetes/latest/quick-start-for-first-time-users) to check whether you have activated Alibaba Cloud Container Service for Kubernetes (ACK) and assigned roles. 220 221 :::note 222 223 For users who deploy Alibaba Cloud in China Mainland, refer to [the corresponding guide](https://help.aliyun.com/document_detail/161387.htm?spm=a2c4g.85903.0.0.478d2246FdHMGt#task-2470091). 224 225 ::: 226 3. Click [AliyunOOSLifecycleHook4CSRole](https://ram.console.aliyun.com/role/authorize?spm=5176.2020520152.0.0.5b4716ddI6QevL&request=%7B%22ReturnUrl%22%3A%22https%3A%2F%2Fram.console.aliyun.com%22%2C%22Services%22%3A%5B%7B%22Roles%22%3A%5B%7B%22RoleName%22%3A%22AliyunOOSLifecycleHook4CSRole%22%2C%22TemplateId%22%3A%22AliyunOOSLifecycleHook4CSRole%22%7D%5D%2C%22Service%22%3A%22OOS%22%7D%5D%7D) and click **Agree to Authorization** to create an AliyunOOSLifecycleHook4CSRole role. 227 228 This operation grant permissions to access Operation Orchestration Service (OOS) and to access the resources in other cloud products since creating and managing a node pool is required for creating an ACK cluster. 229 230 Refer to [Scale a node pool](https://www.alibabacloud.com/help/zh/container-service-for-kubernetes/latest/scale-up-and-down-node-pools) for details. 231 4. Create an AccessKey ID and the corresponding AccessKey secret. 232 233 1. Go to [Alibaba Cloud Management Console](https://homenew.console.aliyun.com/home/dashboard/ProductAndService). Hover the pointer over your account console and click **AccessKey Management**. 234  235 2. Click **Create AccessKey** to create the AccessKey ID and the corresponding AccessKey secret. 236 3. Add the AccessKey ID and AccessKey secret to the environment variable to configure identity authorization information. 237 238 ```bash 239 export ALICLOUD_ACCESS_KEY="YOUR_ACCESS_KEY" 240 export ALICLOUD_SECRET_KEY="YOUR_SECRET_KEY" 241 ``` 242 243 :::note 244 245 Refer to [Create an AccessKey pair](https://www.alibabacloud.com/help/en/resource-access-management/latest/accesskey-pairs-create-an-accesskey-pair-for-a-ram-user) for details. 246 247 ::: 248 249 ### Initialize Playground 250 251 The following command deploys an ACK cluster in the region `cn-hangzhou` on Alibaba Cloud, and installs KubeBlocks. 252 253 ```bash 254 kbcli playground init --cloud-provider alicloud --region cn-hangzhou 255 ``` 256 257 * `cloud-provider` specifies the cloud provider. 258 * `region` specifies the region to deploy a Kubernetes cluster. 259 260 During the initialization, `kbcli` clones [the GitHub repository](https://github.com/apecloud/cloud-provider) to the directory `~/.kbcli/playground`, installs KubeBlocks, and creates a MySQL cluster. After executing the `kbcli playground init` command, kbcli automatically switches the current context of kubeconfig to the new Kubernetes cluster. 261 Run the command below to view the created cluster. 262 263 ```bash 264 # View kbcli version 265 kbcli version 266 267 # View the cluster list 268 kbcli cluster list 269 ``` 270 271 :::note 272 273 The initialization takes about 20 minutes. If the installation fails after a long time, please check your network. 274 275 ::: 276 277 </TabItem> 278 </Tabs> 279 280 ## Try KubeBlocks with Playground 281 Go through the following instructions to try basic features of KubeBlocks. 282 283 ### Describe a MySQL cluster 284 285 ***Steps:*** 286 287 1. View the database cluster list. 288 289 ```bash 290 kbcli cluster list 291 ``` 292 293 2. View the details of a specified database cluster, such as `STATUS`, `Endpoints`, `Topology`, `Images`, and `Events`. 294 295 ```bash 296 kbcli cluster describe mycluster 297 ``` 298 299 ### Access a MySQL cluster 300 301 **Option 1.** Connect database from container network. 302 303 Wait until the status of this cluster is `Running`, then run `kbcli cluster connect` to access a specified database cluster. For example, 304 305 ```bash 306 kbcli cluster connect mycluster 307 ``` 308 309 **Option 2.** Connect database remotely. 310 311 ***Steps:*** 312 313 1. Get Credentials. 314 ```bash 315 kbcli cluster connect --show-example --client=cli mycluster 316 ``` 317 2. Run `port-forward`. 318 319 ```bash 320 kubectl port-forward service/mycluster-mysql 3306:3306 321 > 322 Forwarding from 127.0.0.1:3306 -> 3306 323 Forwarding from [::1]:3306 -> 3306 324 ``` 325 326 3. Open another terminal tab to connect the database cluster. 327 328 ```bash 329 mysql -h 127.0.0.1 -P 3306 -u root -p"******" 330 > 331 ... 332 Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. 333 334 mysql> show databases; 335 > 336 +--------------------+ 337 | Database | 338 +--------------------+ 339 | information_schema | 340 | mydb | 341 | mysql | 342 | performance_schema | 343 | sys | 344 +--------------------+ 345 5 rows in set (0.02 sec) 346 ``` 347 348 ### Observe a MySQL cluster 349 350 KubeBlocks has complete observability capabilities. This section demonstrates the monitoring function of KubeBlocks. 351 352 ***Steps:*** 353 354 1. Open the grafana dashboard. 355 356 ```bash 357 kbcli dashboard open kubeblocks-grafana 358 ``` 359 360 ***Result*** 361 362 A monitoring page on Grafana website is loaded automatically after the command is executed. 363 364 2. Click the Dashboard icon on the left bar and two monitoring panels show on the page. 365  366 3. Click **General** -> **MySQL** to monitor the status of the MySQL cluster created by Playground. 367  368 369 ### High availability of MySQL 370 371 This guide shows a simple failure simulation to show you the failure recovery capability of MySQL. 372 373 #### Delete the Standalone MySQL cluster 374 375 Delete the Standalone MySQL cluster before trying out high availability. 376 377 ```bash 378 kbcli cluster delete mycluster 379 ``` 380 381 #### Create a Raft MySQL cluster 382 383 You can use `kbcli` to create a Raft MySQL cluster. The following is an example of creating a Raft MySQL cluster with default configurations. 384 385 ```bash 386 kbcli cluster create --cluster-definition='apecloud-mysql' --set replicas=3 387 ``` 388 389 #### Simulate leader pod failure recovery 390 391 In this example, delete the leader pod to simulate a failure. 392 393 ***Steps:*** 394 395 1. Make sure the newly created cluster is `Running`. 396 397 ```bash 398 kbcli cluster list 399 ``` 400 401 2. Find the leader pod name in `Topology`. In this example, the leader pod's name is maple05-mysql-1. 402 403 ```bash 404 kbcli cluster describe maple05 405 > 406 Name: maple05 Created Time: Jan 27,2023 17:33 UTC+0800 407 NAMESPACE CLUSTER-DEFINITION VERSION STATUS TERMINATION-POLICY 408 default apecloud-mysql ac-mysql-8.0.30 Running WipeOut 409 410 Endpoints: 411 COMPONENT MODE INTERNAL EXTERNAL 412 mysql ReadWrite 10.43.29.51:3306 <none> 413 414 Topology: 415 COMPONENT INSTANCE ROLE STATUS AZ NODE CREATED-TIME 416 mysql maple05-mysql-1 leader Running <none> k3d-kubeblocks-playground-server-0/172.20.0.3 Jan 30,2023 17:33 UTC+0800 417 mysql maple05-mysql-2 follower Running <none> k3d-kubeblocks-playground-server-0/172.20.0.3 Jan 30,2023 17:33 UTC+0800 418 mysql maple05-mysql-0 follower Running <none> k3d-kubeblocks-playground-server-0/172.20.0.3 Jan 30,2023 17:33 UTC+0800 419 420 Resources Allocation: 421 COMPONENT DEDICATED CPU(REQUEST/LIMIT) MEMORY(REQUEST/LIMIT) STORAGE-SIZE STORAGE-CLASS 422 mysql false <none> <none> <none> <none> 423 424 Images: 425 COMPONENT TYPE IMAGE 426 mysql mysql docker.io/apecloud/wesql-server:8.0.30-5.alpha2.20230105.gd6b8719 427 428 Events(last 5 warnings, see more:kbcli cluster list-events -n default mycluster): 429 TIME TYPE REASON OBJECT MESSAGE 430 ``` 431 432 3. Delete the leader pod. 433 434 ```bash 435 kubectl delete pod maple05-mysql-1 436 > 437 pod "maple05-mysql-1" deleted 438 ``` 439 440 4. Connect to the Raft MySQL cluster. It can be accessed within seconds. 441 442 ```bash 443 kbcli cluster connect maple05 444 > 445 Connect to instance maple05-mysql-2: out of maple05-mysql-2(leader), maple05-mysql-1(follower), maple05-mysql-0(follower) 446 Welcome to the MySQL monitor. Commands end with ; or \g. 447 Your MySQL connection id is 33 448 Server version: 8.0.30 WeSQL Server - GPL, Release 5, Revision d6b8719 449 450 Copyright (c) 2000, 2022, Oracle and/or its affiliates. 451 452 Oracle is a registered trademark of Oracle Corporation and/or its 453 affiliates. Other names may be trademarks of their respective 454 owners. 455 456 Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. 457 458 mysql> 459 ``` 460 461 ## Destroy Playground 462 463 1. Before destroying Playground, it is recommended to delete the database clusters created by KubeBlocks. 464 465 ```bash 466 # View all clusters 467 kbcli cluster list -A 468 469 # Delete a cluster 470 # A double-check is required or you can add --auto-approve to skip it 471 kbcli cluster delete <name> 472 473 # Uninstall KubeBlocks 474 # A double-check is required or you can add --auto-approve to skip it 475 kbcli kubeblocks uninstall --remove-pvcs --remove-pvs 476 ``` 477 478 2. Destroy Playground. 479 480 ```bash 481 kbcli playground destroy 482 ``` 483 484 :::caution 485 486 `kbcli playground destroy` deletes the Kubernetes cluster on the cloud, but there might be residual resources on the cloud, such as volumes and snapshots. Please delete them in time to avoid unexpected costs. 487 488 :::