Practice Kubernetes (K8S) using the Command command

Tram Ho

Today’s tutorial will show you how to use K8S using commands instead of web UI. There are many advantages to avoiding too much reliance on the web interface. There are 2 options to do this:

  • Use Cloud Shell
  • Active cloud shell under the guidance of this
  • Gcloud and kubectl are available in cloud shell (Kubernetes command-line tool)
  • Use ** Command-line tools locally **
  • Install gcloud for your local machine here
  • Use gcloud to install kubectl

If the installation process fails, it is possible under the guidance of this

  • Install Docker on the local machine
  • Install Git

The preparations are complete, now to the main part.

  1. Configure default google-cloud parameters

in the direction you choose the right parameters

  • Sign in to google account for the first time
  • Select default project
  • Select the default zone (containing the default region) in this example, I choose the zone us-central1-a located in us-central1

After configuring is done, you can review your information

The result will be as follows (*** is I cover my personal information)

  1. Create a cluster, in this example I will create an autopilot cluster, my-cluster is the name of the cluster

Wait 5 minutes for the system to create cluster 3. Connect cluster

  1. Create a deployment from sample image: nginx: latest taken from dockerhub

  1. Create a HorizontalPodAutoscaler for your deployment, helping to auto scale (based on% CPU usage, the system will automatically scale)

Pods created can be checked

  1. Pods created, running on the local network, need external permissions to use these services. We go to the step of creating the service. Because nginx runs port 80 so –target-port = 80 Open link from outside, port 8080 –port 8080 Expose type LoadBalancer (when we have multiple pods, requests will be divided into pods)

  1. Check the services that have been created

output

Initially external-ip is

Wait a second. Check again, the system will initialize and assign the external ip to the service, then the service creation will be done.

In my case, I was able to access the web http://35.184.165.64:8080/

  1. When you want to update the new version of the new_image image

  1. When not in use, you can delete the service and the cluster

Share the news now

Source : Viblo