Zero-based Raiders! How to use kubectl and HPA extension Kubernetes applications

Now, Kubernetes has completely changed the way software is developed. Kubernetes as a container management workloads and services open source platform, which has a portable, scalable features, and promote the declarative configuration and automation, but it also proved to be a major player in the complex micro-management services. The Kubernetes been able to be widely adopted in the industry, the reason is Kubernetes meet the following requirements:

  • Companies want to keep the cost low, while constantly growing

  • DevOps wanted a stable platform for running large-scale applications

  • Developers hope to have a reliable and reproducible process to write, test and debug the code

However, if you thought about how to get powerful orchestration platform container while using the resources actually needed? The key is to know the best use of resources need to extend what applications and when they need to extend the application. Therefore, in this article, we will discuss and learn how to extend Kubernetes container, and we will be particularly focused on two services: kubectl and Horizontal Pod Autoscaler (HPA).

kubectl

In most cases and Kubernetes interaction is through a command-line tool named kubectl. kubectl mainly used for communication and Kubernetes API to create, update and delete workloads within the Kubernetes. In the following, we will provide some common commands, you can use them to start managing Kubernetes.

Most common kubectl command provides a specific action or actions to be performed, such as create, delete, and so on. This method usually involves interpretation Kubernetes description of the object (pod, services, resources, etc.) files (YAML or JSON). These files can be used in the template as well as the environment continues to document and help keep attention on Kubernetes declarative configuration. The command line will be transmitted to the operation specified API Server, which then communicates with the necessary Kubernetes backend service. The table below can help you install kubectl:

file

Note: With the new release, the best version for Windows kubectl will vary. Want to find the most appropriate binaries, please visit the following URL:

https://storage.googleapis.com/kubernetes-release/release/stable.txt

And adjust the above URL.

kubectl syntax

kubectl syntax is as follows:

kubectl [command] [TYPE] [NAME] [flags]
  • Command: refers to the action you want to perform (create, delete, etc.)

  • Type: refers to the resource type for which you want to execute the command (Pod, Service, etc.)

  • Name: The name of the resource object (case sensitive), if you do not specify a name, it will get all the information and resources you command to match.

  • Flags: This part of the syntax is not necessary, but when you need to find the specified resource, very useful. For example, -namespace lets you specify a particular namespace in which to perform the operation.

kubectl operation

The following examples can help you run common kubectl familiar with the operation:


kubectl apply - Apply or Update a resource from a file or stdin.
 
# Create a service using the definition in example-service.yaml.
 
kubectl apply -f example-service.yaml
 
kubectl get - List one or more resources.
 
# List all pods in plain-text output format.
 
kubectl get pods
 
# List all pods in plain-text output format and include additional information (such as node name).
 
kubectl describe - Display detailed state of one or more resources, including the uninitialized ones by default.
 
# Display the details of the node with name <node-name>.
 
kubectl describe nodes <node-name>
 
kubectl delete - Delete resources either from a file, stdin, or specifying label selectors, names, resource selectors, or resources.
 
# Delete a pod using the type and name specified in the pod.yaml file.
 
kubectl delete -f pod.yaml
 
# Delete all the pods and services that have the label name=<label-name>.
 
kubectl delete pods,services -l name=<label-name>
 
kubectl logs - Print the logs for a container in a pod.
 
# Return a snapshot of the logs from pod <pod-name>.
 
kubectl logs <pod-name>
 
# Start streaming the logs from pod <pod-name>. This is similar to the 'tail -f' Linux command.
 
kubectl logs -f <pod-name>

These are commonly used kubectl operation, if you want to know more, you can check the official guide kubectl. In addition, we Past articles are also described:

7 kubectl you will use the command

Use the whole solution of course Kubectl management Kubernetes

Horizontal Pod Autoscaler (HPA)

Pod level automatic retractable (HPA) is an important function Kubernetes, which allows you to configure the service to automatically cluster retractable running. HPA realized as a Kubernetes API resources and controller. Determine the behavior of the resource controller, controller replication controller periodically adjust the number of copies or deployment, the average CPU utilization and user-specified target to match observed.

Meanwhile, the HPA is implemented as a control loop, which is a period -horizontal-pod-autoscaler-sync-period control flag controller manager (default is 30 seconds).

During each cycle, controller manager will be based on each query resource utilization HPA index specified in the definition. Controller manager will get index (for all other metrics) from the resource index API (for per-pod resource index) or custom indicators API.

  • For per-pod index resources (such as CPU), controller gets the indicators for each Pod HPA positioning from the resource index API. Then, if the target utilization value, then the controller will be the utilization percentage value is calculated for each pod in the container equivalent resource request. If the original target value is set, the direct use of the original index value. Then, the pod Controller all target utilization or the original value (depending on the type of the specified target) were averaged, and the desired stretch ratio to produce a number of copies for.

  • For custom per-pod index, controller functions like per-pod resource index, but it applies to the original value, rather than the utilization value.

  • For objects index, you will obtain a single index (the index describes the object in question), and compared with a target value, to generate the desired number of copies for the telescopic ratio.

HPA controller will obtain the index in two different ways: direct Heapster access and REST client access. When using direct Heapster access, HPA will be through the service broker child resource API server directly queries Heapster. Please note, Heapster need to deploy and run kube-system namespace on the cluster.

HPA workflow includes the following four steps, as shown:

  1. During set the default 30-second intervals, HPA will continue to check the index value you configured

  2. If the specified threshold, the HPA try to increase the number of pod

  3. HPA major updates in the deployment or replication controller in the number of copies

  4. Then, the deployment / replication controller will add any additional required pod

file

When you launch HPA consider the following factors:

  • The default is 30 seconds HPA inspection, this default value by the controller manager - configure horizontal-pod-autoscaler-sync-period flag.

  • HPA related indicators of default tolerance of 10%.

  • After the last expansion event, HPA will wait 3 minutes to allow the index to stabilize. Configure horizontal-pod-autoscaler-upscale-delay flag - the same can wait for events.

  • From a narrow incident began, HPA will wait 5 minutes, in order to avoid autoscaler jitter. Configure horizontal-pod-autoscaler-downscale-delay flag - is also.

  • Compared with the replication controller, HPA and deploy the most suitable object or Pod indicators used in conjunction with, does not apply to rollover with direct manipulation of replication controller. When you deploy, the need to deploy the underlying object to manage the size of the replica set.

  • When used in conjunction with the HPA custom metrics (such as Pod or object indicators index), you need to decide when to stretch. Since Kubernetes support a variety of indicators, so you can use many metrics to determine stretching time. Please note, Kubernetes will be considered in the order in each index. For more examples please refer to:
    https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale

in conclusion

In this article, we discussed two main tools extend Kubernetes applications, both of which are key components of all Kubernetes services. We have seen how to install and use different functions, such as application, get, delete, and kubectl description of logs. At the same time, we look back and learn about Horizontal Pod Autoscaler of, for example, the importance of how it works and its impact on any Kubernetes services. When expanding micro-service applications, an important function of kubectl and HPA are Kubernetes.

Released last month Rancher 2.3 has been integrated HPA function, you can use the UI in Rancher. Currently, Rancher 2.3 has also been stable, if you want a more comprehensive understanding Rancher 2.3 Follow us Rancher K8S cloud classroom next Wednesday night it!

file

Welcome to add a micro-channel assistant (rancher2), into the official technical group for more Kubernetes use Raiders

Guess you like

Origin www.cnblogs.com/rancherlabs/p/11810277.html