SoFunction
Updated on 2025-03-05

k8s Collection of common interview questions

What is k8s and why businesses choose to use it

I shared it in this video some time ago/bregman-arie/devops-exercisesThis knowledge warehouse.

k8s is an open source application that provides users with the ability to manage, deploy and expand containers. The following examples are easier to understand:

You can run containers in different machines or nodes, and you can synchronize some changes to these containers. In short, we just need to writeyamlDocument, tellk8sWhat are my expectations? All the processes of synchronous changes are left to k8s to complete.

Actually, it is the declarative API we often call

  • The second feature has been mentioned just now. It can help us manage multiple containers in one click and synchronize all changes.
  • The number of replicas of the application can be adjusted according to the current load. If the load is high, several new application instances will be created, and if the lower ones will be reduced, this can be completed manually or automatically.

When to use or not to use k8s

  • If you mainly use low-level infrastructure such as physical machines, it is not recommended to use it.k8s, This situation is usually a relatively traditional business, and there is no need to use itk8s

The second case is that it is not recommended to use it if it is a small team or the container size is small, unless you want to use the scrolling release and self-scaling capabilities of k8s, but these functions can be implemented by writing tools on your own.

What are the characteristics of k8s

  • It is self-healing,k8sHave health testing for containers, such as using starter probes, survival probes, etc., or containersOOMThe application will be restarted and tried to repair it.
  • Boast load balancing, useserviceTraffic can be automatically loaded into subsequent pods. If the pod provides http service, it is enough, but if it is a long link like grpc, you need to use a service mesh like istio, which can identify the protocol type and achieve request-level load balancing.
  • OperatorAutomatic operation and maintenance capabilities: k8s can automatically adjust the number of pods, storage, etc. of the current cluster according to the operation of the application, and getPulsarFor example, when traffic surges, it will automatically add new ones.broker, automatic capacity expansion when the disk is insufficient, etc.
  • Rolling update capability: When we publish or rollback the version, k8s will wait for the new container to start before cutting back the traffic, and gradually stop the old instance.
  • Horizontal expansion ability: You can flexibly add or reduce the number of copies, and of course you can also automatically control it.
  • Data encryption: UsesecretYou can save some sensitive configurations or files.

What objects do k8s have

This is to examine ourk8sAre you familiar with it? Commonly used are:

  • Pod
  • Service
  • ReplicationController
  • DaemonSet
  • namespace
  • ConfigMap
    Actually, this does not work much, but mainly knows how to use different components in different scenarios.

Which fields are required

I don't think this question is meaningful, as long as I have written ityamlYou'll know,metadata, kind, apiVersion

apiVersion: apps/v1  
kind: Deployment  
metadata:  
  labels:  
    app: app
  name: app

What is kubectl

It is actually a k8s command line client.

Which objects are used more when you deploy an application

  • The first one is definitelydeployment, this should be the most common way to deploy.
  • service: You can load traffic into the pod.
  • Ingress: If you need to access Pods from outside the cluster, you have toIngressThen cooperate with the domain name to access.

Why is there no k get containers command

This question is mainly based on the rightPodUnderstanding, because ink8smiddlePodIt is the smallest unit. If you want to access the container, you can access it in the Pod.

We can add-cParameters enter the specific container.

kubectl exec -it app -c istio-proxy

What do you think are the best practices for using k8s

This mainly depends on whether you encounter any pitfalls during daily use:

The first is to verifyyamlWhether the content is correct is indeed very important. Once the execution is wrong, the consequences are very serious. For example, it is best to use helm.dry-runanddebug, first look at the generated oneyamlWhether it is what you expect.

helm upgrade app --dry-run --debug
  • The second limits the use of resources, such as CPU and memory, which is also very important. If not set, once a bug occurs in the application, it may affect the entire k8s cluster.
  • Specifies a tag for Pod, deployment, for grouping.
# Resource Limitationsresources:  
  limits:  
    cpu: 200m  
    memory: 200Mi  
  requests:  
    cpu: 100m  
    memory: 100Mi

Reference source:/bregman-arie/devops-exercises/blob/master/topics/kubernetes/#kubernetes-101

The above is the detailed content of the common interview questions in k8s. For more information about the interview highlights of k8s, please pay attention to my other related articles!