github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/docs/user_docs/try-out-on-playground/try-kubeblocks-on-your-laptop.md (about) 1 --- 2 title: Try out KubeBlocks in 5 minutes on laptop 3 description: A quick tour of KubeBlocks Playground 4 keywords: [Playground, try out, laptop,] 5 sidebar_position: 1 6 sidebar_label: Try out KubeBlocks on laptop 7 --- 8 9 # Try out KubeBlocks in 5 minutes on laptop 10 11 This guide walks you through the quickest way to get started with KubeBlocks, demonstrating how to create a demo environment (Playground) with one command. 12 13 ## Before you start 14 15 Meet the following requirements for a smooth user experience: 16 17 * Minimum system requirements: 18 * CPU: 4 cores, use `sysctl hw.physicalcpu` command to check CPU; 19 * RAM: 4 GB, use `top -d` command to check memory. 20 21 * Make sure the following tools are installed on your laptop: 22 * [Docker](https://docs.docker.com/get-docker/): v20.10.5 (runc ≥ v1.0.0-rc93) or above; 23 * [kubectl](https://kubernetes.io/docs/tasks/tools/#kubectl): it is used to interact with Kubernetes clusters; 24 * [kbcli](./../installation/install-with-kbcli/install-kbcli.md): it is used for the interaction between Playground and KubeBlocks. 25 26 ## Initialize Playground 27 28 ***Steps:*** 29 30 1. Install Playground. 31 32 ```bash 33 kbcli playground init 34 ``` 35 36 This command: 37 1. Creates a Kubernetes cluster in the container with [K3d](https://k3d.io/v5.4.6/). 38 2. Deploys KubeBlocks in the K3d cluster. 39 3. Creates a standalone MySQL cluster. 40 41 :::note 42 43 * If you previously ran `kbcli playground init` and it failed, running it again may cause errors. Please run the `kbcli playground destroy` command first to clean up the environment, then run `kbcli playground init` again. 44 * If you run Playground on Windows and the error below occurs, it is caused by the safety strategy of Windows 11 and the `kbcli.exe` you operate might be tampered with by a third party (or when you built the kbcli binary file through source on Windows). 45 46 ```bash 47 error: failed to set up k3d cluster: failed to create k3d cluster kb-playground: Failed Cluster Start: Failed to start server k3d-kb-playground-server-0: Node k3d-kb-playground-server-0 failed to get ready: error waiting for log line `k3s is up and running` from node 'k3d-kb-playground-server-0': stopped returning log lines 48 ``` 49 50 You can follow the steps to solve this problem. 51 52 1. Uninstall or delete the current `kbcli.exe`. 53 2. Download the latest kbcli by `winget` or visit the [GitHub release page](https://github.com/apecloud/kubeblocks/releases) of KubeBlocks to download kbcli again. 54 55 ::: 56 57 58 2. Check the MySQL cluster repeatedly until the status becomes `Running`. 59 60 ```bash 61 kbcli cluster list 62 ``` 63 64 **Result:** 65 66 You just created a cluster named `mycluster` in the default namespace. You can find the user guide under the installation success tip. View this guide again by running `kbcli playground init -h`. 67 68 ## Try KubeBlocks with Playground 69 70 You can explore KubeBlocks, by referring to [Describe a MySQL cluster](#describe-a-mysql-cluster), [Access a MySQL cluster](#access-a-mysql-cluster), [Observe a MySQL cluster](#observe-a-mysql-cluster), and [High availability](#high-availability-of-mysql). Go through the following instructions to try basic features of KubeBlocks. 71 72 ### Describe a MySQL cluster 73 74 ***Steps:*** 75 76 1. View the database cluster list. 77 78 ```bash 79 kbcli cluster list 80 ``` 81 82 2. View the details of a specified database cluster, such as `STATUS`, `Endpoints`, `Topology`, `Images`, and `Events`. 83 84 ```bash 85 kbcli cluster describe mycluster 86 ``` 87 88 ### Access a MySQL cluster 89 90 **Option 1.** Connect database from container network. 91 92 Wait until the status of this cluster is `Running`, then run `kbcli cluster connect` to access a specified database cluster. For example, 93 94 ```bash 95 kbcli cluster connect mycluster 96 ``` 97 98 **Option 2.** Connect database from host network. 99 100 ***Steps:*** 101 102 1. Get Credentials. 103 ```bash 104 kbcli cluster connect --show-example --client=cli mycluster 105 ``` 106 3. Run `port-forward`. 107 108 ```bash 109 kubectl port-forward service/mycluster-mysql 3306:3306 110 > 111 Forwarding from 127.0.0.1:3306 -> 3306 112 Forwarding from [::1]:3306 -> 3306 113 114 3. Open another terminal tab to connect the database cluster. 115 116 ```bash 117 mysql -h 127.0.0.1 -P 3306 -u root -paiImelyt 118 > 119 ... 120 Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. 121 122 mysql> show databases; 123 > 124 +--------------------+ 125 | Database | 126 +--------------------+ 127 | information_schema | 128 | mydb | 129 | mysql | 130 | performance_schema | 131 | sys | 132 +--------------------+ 133 5 rows in set (0.02 sec) 134 ``` 135 136 ### Observe a MySQL cluster 137 138 KubeBlocks supports complete observability capabilities. This section demonstrates the monitoring function of KubeBlocks. 139 140 ***Steps:*** 141 142 1. Open the grafana dashboard. 143 144 ```bash 145 kbcli dashboard open kubeblocks-grafana 146 ``` 147 148 **Result:** 149 150 A monitoring page on Grafana website is loaded automatically after the command is executed. 151 152 2. Click the Dashboard icon on the left bar and monitoring panels show on the page. 153  154 3. Click **General** -> **MySQL** to monitor the status of the MySQL cluster. 155  156 157 ### High availability of MySQL 158 159 This guide shows a simple failure simulation to show you the failure recovery capability of MySQL. 160 161 #### Delete the Standalone MySQL cluster 162 163 Delete the Standalone MySQL cluster before trying out high availability. 164 165 ```bash 166 kbcli cluster delete mycluster 167 ``` 168 169 #### Create a Raft MySQL cluster 170 171 You can use `kbcli` to create a Raft MySQL cluster. The following is an example of creating a Raft MySQL cluster with default configurations. 172 173 ```bash 174 kbcli cluster create --cluster-definition='apecloud-mysql' --set replicas=3 175 ``` 176 177 #### Simulate leader pod failure recovery 178 179 In this example, delete the leader pod to simulate a failure. 180 181 ***Steps:*** 182 183 1. Make sure the newly created cluster is `Running`. 184 185 ```bash 186 kbcli cluster list 187 ``` 188 189 2. Find the leader pod name in `Topology`. In this example, the leader pod's name is maple05-mysql-1. 190 191 ```bash 192 kbcli cluster describe maple05 193 > 194 Name: maple05 Created Time: Jan 27,2023 17:33 UTC+0800 195 NAMESPACE CLUSTER-DEFINITION VERSION STATUS TERMINATION-POLICY 196 default apecloud-mysql ac-mysql-8.0.30 Running WipeOut 197 198 Endpoints: 199 COMPONENT MODE INTERNAL EXTERNAL 200 mysql ReadWrite 10.43.29.51:3306 <none> 201 202 Topology: 203 COMPONENT INSTANCE ROLE STATUS AZ NODE CREATED-TIME 204 mysql maple05-mysql-1 leader Running <none> k3d-kubeblocks-playground-server-0/172.20.0.3 Jan 30,2023 17:33 UTC+0800 205 mysql maple05-mysql-2 follower Running <none> k3d-kubeblocks-playground-server-0/172.20.0.3 Jan 30,2023 17:33 UTC+0800 206 mysql maple05-mysql-0 follower Running <none> k3d-kubeblocks-playground-server-0/172.20.0.3 Jan 30,2023 17:33 UTC+0800 207 208 Resources Allocation: 209 COMPONENT DEDICATED CPU(REQUEST/LIMIT) MEMORY(REQUEST/LIMIT) STORAGE-SIZE STORAGE-CLASS 210 mysql false <none> <none> <none> <none> 211 212 Images: 213 COMPONENT TYPE IMAGE 214 mysql mysql docker.io/apecloud/wesql-server:8.0.30-5.alpha2.20230105.gd6b8719 215 216 Events(last 5 warnings, see more:kbcli cluster list-events -n default mycluster): 217 TIME TYPE REASON OBJECT MESSAGE 218 ``` 219 220 3. Delete the leader pod. 221 222 ```bash 223 kubectl delete pod maple05-mysql-1 224 > 225 pod "maple05-mysql-1" deleted 226 ``` 227 228 4. Connect to the Raft MySQL cluster. It can be accessed within seconds. 229 230 ```bash 231 kbcli cluster connect maple05 232 > 233 Connect to instance maple05-mysql-2: out of maple05-mysql-2(leader), maple05-mysql-1(follower), maple05-mysql-0(follower) 234 Welcome to the MySQL monitor. Commands end with ; or \g. 235 Your MySQL connection id is 33 236 Server version: 8.0.30 WeSQL Server - GPL, Release 5, Revision d6b8719 237 238 Copyright (c) 2000, 2022, Oracle and/or its affiliates. 239 240 Oracle is a registered trademark of Oracle Corporation and/or its 241 affiliates. Other names may be trademarks of their respective 242 owners. 243 244 Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. 245 246 mysql> 247 ``` 248 249 #### Demonstrate availability failure by NON-STOP NYAN CAT (for fun) 250 251 The above example uses `kbcli cluster connect` to test availability, in which the changes are not obvious to see. 252 253 NON-STOP NYAN CAT is a demo application to observe how the database cluster exceptions affect actual businesses. Animations and real-time key information display provided by NON-STOP NYAN CAT can directly show the availability influences of database services. 254 255 ***Steps:*** 256 257 1. Install the NYAN CAT demo application. 258 259 ```bash 260 kbcli addon enable nyancat 261 ``` 262 263 <details> 264 265 <summary>Expected output</summary> 266 267 ```bash 268 addon.extensions.kubeblocks.io/nyancat enabled 269 ``` 270 271 </details> 272 273 2. Check the NYAN CAT add-on status and when its status is `Enabled`, this application is ready. 274 275 ```bash 276 kbcli addon list | grep nyancat 277 ``` 278 279 3. Open the web page. 280 281 ```bash 282 kbcli dashboard open kubeblocks-nyancat 283 ``` 284 285 4. Open another terminal tab and delete the leader pod. Then view the influences on the Raft MySQL cluster through the NYAN CAT page. 286 287 ```bash 288 kubectl delete pod maple05-mysql-1 289 ``` 290 291  292 293 5. Uninstall the NYAN CAT demo application after your trial. 294 295 ```bash 296 kbcli addon disable nyancat 297 ``` 298 299 ## Destroy Playground 300 301 Destroying Playground cleans up resources and data: 302 303 * Delete all KubeBlocks database clusters. 304 * Uninstall KubeBlocks. 305 * Delete the Kubernetes cluster created by K3d. 306 307 Destroy Playground. 308 309 ```bash 310 kbcli playground destroy 311 ```