百度智能云

All Product Document

          Cloud Container Engine

          Create Simple Services through Kubectl

          Connect to Kubernetes Cluster through Kubectl

          If you need to connect to the kubernetes cluster of Baidu AI Cloud from the local personal computer, you need to use the kubernetes command-line client kubectl, and the installation steps of kubectl are as follows

          Operation Steps

          For the installation of kubectl, please see the official kubernetes Installation and Setting up Kubectl Documentation.

          Note:

          The operation steps given in this operation guide are all based on the Linux operating environment.

          1.Unzip the downloaded file, add the execution permission for kubectl, and put it under PATH

              chmod +x ./kubectl
              sudo mv ./kubectl /usr/local/bin/kubectl

          2.Configure kubectl and download cluster credentials. Download the cluster configuration file in the cluster interface and put it in the default configuration path of kubectl

              mv kubectl.conf  ~/.kube/config

          3.After configuration, you can use kubectl to access the kubernetes cluster from the local computer

              kubectl get node

          Create a Nginx Application

          After connecting to the kubernetes cluster through kubectl, enter the following command:

          kubectl run my-nginx --image=nginx --replicas=3 --port=80 

          The above command creates 3 Nginx containers, each of which exposes its port 80.

          The instructions for creating Nginx container state are as follows:

          $ kubectl get pods 
          NAME                       READY     STATUS    RESTARTS   AGE 
          my-nginx-858393261-pfjdn   1/1       Running   0          14s 
          my-nginx-858393261-sn7g5   1/1       Running   0          14s 
          my-nginx-858393261-spv8w   1/1       Running   0          14s 

          Note: The "$" symbol represents the input instruction, and the other lines represent the container information displayed after the input instruction.

          Expose Services to the Internet

          Create Service

          In the public cloud environment, you can create a service of LoadBalancer type by entering the command. At the same time, you can also link with the public cloud to create a load balance and a public IP. The specific operation instructions are as follows:

          kubectl expose deployment my-nginx --port=80 --type=LoadBalancer 

          View Service

          By viewing the command of the service, you can see the status of the service and the created public IP.

          $ kubectl get services 
          NAME         CLUSTER-IP    EXTERNAL-IP      PORT(S)        AGE 
          kubernetes   172.17.0.1   <none>           443/TCP        1h 
          my-nginx     172.17.44.5   180.76.139.247   80:30356/TCP   47s 

          Through the link 180.76.139.247, you can see the created service as shown in the figure:

          After completing the service creation, users can log in to Baidu AI Cloud platform, select "Product Service > Load Balance", enter the BLB console to view the details of the load balance, and see Load Balance Operation Guide for specific operation steps.

          Note: The symbol "$" represents the input instruction, and other lines represent the service information displayed after the input instruction, among which 180.76.139.247 is the service website published to the Internet. In addition to the above instruction calls, service load balance can also be called through dashboard.

          Delete Service

          If you need to delete the service, you don't want to expose it to the public network. Services can be deleted directly.

          	 kubectl delete svc my-nginx 

          Note:

          Kubernetes will delete the public IP and load balance created just now, and then delete the created service.

          Previous
          Overview of FAQs
          Next
          How do Service Applications Use Load Balance