Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the practical skills of Kubernetes

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains "what are the practical skills of Kubernetes". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "what are the practical skills of Kubernetes"?

1. Automatic completion of kubectl command parameters

If you use Kubernetes, you must use the Kubectl command. The default installation of the Kubectl command does not support automatic completion of parameters. The following configure the automatic completion method of Kubectl command parameters:

On Linux, such as Centos

$yum install-y bash-completion $source / usr/share/bash-completion/bash_completion $source > ~ / .bashrc

On MAC

$brew install bash-completion $source $(brew-- prefix) / etc/bash_completion $source > ~ / .zshrc

Common operations of Kubectl [1]

1. How to find Pod with non-running status?

$kubectl get pods-A-- fieldMutual selectorstatus.phaseautomotive running runs | grep-v Complete

2. How to find the Pod of running status?

$kubectl get pods-A-- field-selector=status.phase=Running | grep-v Complete

3. Get a list of nodes containing the number of Pod running on each node?

$kubectl get po-o json-- all-namespaces | jq '.items | group_by (.spec.nodeName) | map ({"nodeName":. [0] .spec.nodeName, "count": length}) | sort_by (.count)' [{"nodeName": "service1", "count": 6}, {"nodeName": "service3", "count": 13}]

4. Use kubectl top to get the Pod list and sort it according to the CPU or memory consumed

# get cpu $kubectl top pods-A | sort-- reverse-- key 3-- numeric # get memory $kubectl top pods-A | sort-- reverse-- key 4-- numeric

Add Namespace default CPU and memory limit

Sometimes Pod does not impose resource restrictions, which will affect the entire host application due to excessive usage of individual Pod. The following is a specific example, which can adjust the relevant parameters according to the actual situation.

ApiVersion: "v1" kind: "LimitRange" metadata: name: "resource-limits" namespace: default spec: limits:-type: "Pod" max: cpu: "4" memory: "4Gi" min: cpu: "100m" memory: "100Mi"-type: "Container" max: cpu: "4" Memory: "4Gi" min: cpu: "100m" memory: "100Mi" default: cpu: "500m" memory: "500Mi" defaultRequest: cpu: "100m" memory: "100Mi" maxLimitRequestRatio: cpu: "60"

Third, use Kubelet to reserve resources for Node

EvictionHard: imagefs.available: 15% memory.available: 1G nodefs.available: 10% nodefs.inodesFree: 5%

Fourth, use Kubernetes RBAC to divide the authority

When multiple teams deploy applications to a kubernetes cluster, the situation can become complicated. Remember not to open administrator privileges to everyone. The personal recommendation is to differentiate and isolate each team based on the namespace, and then use the RBAC policy to allow only individual teams to access their own namespaces.

If we open up administrator privileges to everyone, it can be maddening to read, create, and delete access at the pod level, because misoperations often occur. To do this, only administrators should be allowed access, thus distinguishing the privileges of people who manage the cluster from those who deploy the cluster.

Make full use of PodDisruptionBudget controller

How to ensure that the applications in the kubernetes cluster always work properly?

Answer: use the PodDisruptionBudget controller.

During the kubectl drain operation, kubernetes will judge the number of application Pod clusters according to the PodDisruptionBudget controller, and then ensure that the application Pod will be terminated without business interruption or business SLA degradation. PDB (PodDisruptionBudget) should be placed on each deployment that has more than one instance. We can use a simple yaml to create a PDB for the cluster and use a tag selector to determine which tagged resources the PDB should act on.

Note: PDB only considers active interrupts, and situations such as hardware failures are not considered by PDB.

Example:

ApiVersion: policy/v1beta1 kind: PodDisruptionBudget metadata: name: zk-pdb spec: minAvailable: 2 selector: matchLabels: app: zookeeper

Use probes to detect the status of the application

Kubernetes supports the configuration of probes. Kubelet uses probes to determine whether the application in Pod is healthy. K8S provides two types to implement this function, Readiness probe and Liveiness probe.

Readiness: the probe is used to determine when the container is ready to receive traffic.

Liveiness: the probe is used to determine whether the container is healthy, and if not, whether to redeploy a new container to replace it according to the policy.

Example:

ReadinessProbe: tcpSocket: port: 8080 initialDelaySeconds: 5 periodSeconds: 10 livenessProbe: tcpSocket: port: 8080 initialDelaySeconds: 15 periodSeconds: 20 so far, I believe you have a deeper understanding of "what are the practical skills of Kubernetes?" Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report