This topic describes how to deploy applications in a VKE cluster by using the kubectl command-line tool.
Step 1: Create a cluster
tip
To use an existing cluster, make sure that access to the API server over the Internet is enabled.
Step 2: Connect to the cluster
You can use the kubectl client to connect to the cluster you created.
- Download and install the latest version of kubectl in your local environment.
- On the Cluster page of the VKE console, find the cluster demo-cluster you have created and click its name.
- On the Overview page of the cluster, click the Connection tab.
- Select the Public network tab, and click Generate Kubeconfig. In the pop-up window, set Valid period (365 days in this example) to obtain the cluster access credentials.
-
- In your local environment, open the $HOME/.kube/config file and paste the obtained cluster access credentials into it.
warning
$HOME/.kube/config is the file generated after you install the kubectl client in your local environment. $HOME is a variable, and its value depends on your local operating system (such as macOS, Linux, or Windows) and the path where you install the kubectl client.
- Run the following command in your kubectl client to query the status of nodes (including virtual nodes) in the cluster and check whether the connection is successful.
- If output similar to the following information is displayed, kubectl is connected to the cluster.
Step 3: Deploy an application
After connecting to the cluster from kubectl, use the kubectl client to create a Deployment for deploying an application.
- In your local environment, create a YAML file named nginx.yaml and paste the following sample code into it.
tip
Modify the parameter values based on the comments in the sample code.
- Run the following command to deploy the application.
The following output is expected:
- Run the following command to view the deployment status.
tip
Replace ${your_deployment_name} with the name of the Deployment. For example, the complete command looks like the following if the name is doc-deployment:
- If the output is similar to the following information, the application has been deployed.
- In the $home directory on your local computer, create an nginx-svc.yaml file and copy the following sample code into that file.
- Run the following command to create a Service.
- The information similar to the following message is expected to be displayed.
- Run the following command to view the Service status.
tip
Replace ${your_service_name} with the service name you specified. For example, if the name is nginx-svc, the complete command is as follows:
- If the output is similar to the following information, the application is deployed.
- In your browser, enter the EXTERNAL-IP returned in the previous step to access the Nginx welcome page.
-
Step 4: Monitor the application
After the application is deployed, you can use cloud-native observability to monitor its status, including CPU and memory usage, to facilitate subsequent O&M work. For details, see Enabling observability. Release resources
If you no longer need a cluster, delete it and its associated resources by following the instructions in Deleting Clusters. To keep the cluster running without interruptions, ensure that your Volcano Engine account balance is at least CNY 100 (including any vouchers) and greater than zero (excluding vouchers). If you continue to use VKE clusters, you will be charged the following two types of fees. For details, see Product billing. - Cluster management fees charged by VKE.
- Cloud infrastructure costs: Volcano Engine resources used in the cluster, such as NAT Gateway, CLB, EIP, and EBS, are billed separately by the corresponding cloud services.