You need to enable JavaScript to run this app.
Volcengine Kubernetes Engine

Volcengine Kubernetes Engine

Copy page
Download PDF
Getting started
Using VKE via kubectl
Copy page
Download PDF
Using VKE via kubectl
This topic describes how to deploy applications in a VKE cluster by using the kubectl command-line tool.​
Step 1: Create a cluster​
For the detailed procedure and parameter description, see Step 1: Create a cluster in the Using VKE via the console topic.​
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.​
  1. Download and install the latest version of kubectl in your local environment.​
  1. On the Cluster page of the VKE console, find the cluster demo-cluster you have created and click its name.​
  1. On the Overview page of the cluster, click the Connection tab.​
  1. 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.​
  • ​​​
  1. 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.​
  1. 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.​
  • ​
    kubectl get node​
    ​
  • If output similar to the following information is displayed, kubectl is connected to the cluster.​
  • ​
    NAME STATUS ROLES AGE VERSION​
    192.168.0.6 Ready <none> 4h15m v1.26.10-vke.11​
    ​
Step 3: Deploy an application​
After connecting to the cluster from kubectl, use the kubectl client to create a Deployment for deploying an application.​
  1. 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.​
  • ​
    apiVersion: apps/v1​
    kind: Deployment​
    metadata:​
    name: doc-deployment # Deployment name​
    namespace: default # Namespace name​
    spec:​
    replicas: 1 # Number of pod instances​
    selector:​
    matchLabels:​
    app: doc-deployment​
    template:​
    metadata:​
    labels: # # Make sure this matches the selector value in the Service YAML file created later.​
    app: doc-deployment​
    spec:​
    containers:​
    - name: doc-deployment-container # Container name​
    image: doc-cn-beijing.cr.volces.com/vke/nginx-demo:v1.0 # You can replace it with your own image address, or use the address provided here​
    ports:​
    - containerPort: 80 # Exposed container port number​
    protocol: TCP # The network protocol​
    ​
  1. Run the following command to deploy the application.​
  • ​
    kubectl apply -f nginx.yaml​
    ​
The following output is expected:​
  • ​
    deployment.apps/doc-deployment created​
    ​
  1. Run the following command to view the deployment status.​
  • ​
    kubectl get deployment ${your_deployment_name}​
    ​
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:​
​
kubectl get deployment doc-deployment​
​
  • If the output is similar to the following information, the application has been deployed.​
  • ​
    NAME READY UP-TO-DATE AVAILABLE AGE​
    doc-deployment 1/1 1 1 85s​
    ​
  1. In the $home directory on your local computer, create an nginx-svc.yaml file and copy the following sample code into that file.​
tip​
Modify parameter values according to the comments in the sample code as needed. For more descriptions, see Creating Load Balancer services through kubectl.​
  • ​
    apiVersion: v1​
    kind: Service​
    metadata:​
    name: nginx-svc # Service name​
    namespace: default # Namespace name​
    spec:​
    selector: # Make sure that this matches the value of the matchLabels parameter under the selector of the previously created application file​
    app: doc-deployment​
    ports:​
    - protocol: TCP # Port protocol​
    name: doc-port # The port mapping name​
    port: 80 # The Service port.​
    targetPort: 80 # Container port: the port number or port name through which the workload provides services. For example, the default port for Nginx is 80.​
    type: LoadBalancer # Service type. Valid values: Nodeport, ClusterIP, and LoadBalancer.​
    ​
  1. Run the following command to create a Service.​
  • ​
    kubectl apply -f nginx-svc.yaml​
    ​
  • The information similar to the following message is expected to be displayed.​
  • ​
    service/nginx-svc created​
    ​
  1. Run the following command to view the Service status.​
  • ​
    kubectl get svc ${your_service_name}​
    ​
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:​
​
kubectl get svc nginx-svc​
​
  • If the output is similar to the following information, the application is deployed.​
  • ​
    NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE​
    nginx-svc LoadBalancer 172.**.**.** 180.**.**.** 80:31709/TCP 65s​
    ​
  1. 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.​
Last updated: 2026.07.16 15:55:45