Why Kubernetes has become so popular (2020 version)

Why Kubernetes has become so popular (2020 version)

At the time of writing this article, Kubernetes has a history of about 6 years. In the past two years, the popularity of Kubernetes has continued to rise and it has become one of the most popular platforms for engineers. This year, it was ranked as the third most popular platform. If you haven't heard of Kubernetes, it is a platform that allows you to run containers and coordinate container loads.

The container was originally a product of Linux kernel process isolation, including cgroups supported in 2007 and namespaces supported in 2002. In 2008, when LXC became available, containers became more important, and Google developed the "Borg" good city "run everything in a container" mechanism. Soon in 2013, Docker was released, which completely popularized containers. At the time, Mesos was the main tool for scheduling containers, however, it was not so popular. Kubernetes was released in 2015 and quickly became the de facto container scheduling standard.

In an attempt to understand the popularity of Kubernetes, let us consider some questions. When was the last time developers were able to agree on how to deploy an application? Do you know how many developers run tools out of the box? How many cloud operation and maintenance engineers do not understand how applications work? We will explore the answers to these questions in this article.

Infrastructure uses YAML expression

Coming out of the world of Puppet and Chef, an important shift in Kubernetes is from a code-based infrastructure to a data-based infrastructure—specifically, YAML. All resources in Kubernetes, including Pod, Configurations, Deployments, Volumes, etc., can be simply expressed in YAML files. such as.

apiVersion: v1
kind: Pod
metadata:
  name: site
  labels:
    app: web
spec:
  containers:
    - name: front-end
      image: nginx
      ports:
        - containerPort: 80

This way of representation makes it easier for DevOps or SRE engineers to fully express the workload without the need to express it in code in languages ​​such as Python, Ruby, or Javascript.

The benefits of using infrastructure as data also include.

  • GitOps or Git operation version control. Using this method, you can save all the Kubernetes YAML files under the git repository, so you can know exactly when the changes were made, who made the changes, and what was changed. This makes the entire organization more transparent and improves efficiency by preventing team members from being confused about where to look for configurations. At the same time, it is easier to automate changes to Kubernetes resources by simply merging a pull request.
  • Scalability. Defining resources as YAML allows cluster operators to change one or two numbers in Kubernetes resources to expand or shrink the cluster. Kubernetes has a horizontal pod autoscaler, which can specify the minimum and maximum number of pods required for a given deployment, so that it can automatically scale/expand to cope with traffic troughs/peaks. For example, if you are running a deployment that may require more capacity due to a sudden increase in traffic, you can change maxReplicas from 10 to 20.
    
    apiVersion: autoscaling/v2beta2
    kind: HorizontalPodAutoscaler
    metadata:
    name: myapp
    namespace: default
    spec:
    scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: myapp-deployment
    minReplicas: 1
    maxReplicas: 20
    metrics:
    - type: Resource
    resource:
      name: cpu
      target:
        type: Utilization
        averageUtilization: 50
* 安全和控制。YAML是验证在Kubernetes中部署什么和如何部署的好方法。例如,当涉及到安全问题时,一个重要的关注点就是你的工作负载是否以非root用户的身份运行。我们可以利用像conftest这样的工具(YAML/JSON验证器),再加上Open Policy Agent这样的策略验证器,来检查你的工作负载的SecurityContext是否不允许容器作为root用户运行。为此,用户可以使用一个简单的Open Policy Agent rego策略,如下。

package main

deny[msg] {
input.kind = "Deployment"
not input.spec.template.spec.securityContext.runAsNonRoot = true
msg = "Containers must not run as root"
}


* 云供应商的整合。科技行业的主要趋势之一就是在公有云供应商中运行工作负载。在云供应商组件的帮助下,Kubernetes允许每个集群与它所运行的云供应商进行集成。例如,如果用户在AWS中的Kubernetes中运行某应用程序,并希望该应用程序可以通过服务访问,云供应商会帮助自动创建一个LoadBalancer服务,该服务会自动提供一个Amazon Elastic Load Balancer来将流量转发到应用程序的pods。
* 
可扩展性

Kubernetes的可扩展性很强,开发者很喜欢这一点。Kubernetes已经内置了很多资源,如Pods、Deployments、StatefulSets、Secrets、ConfigMaps等。然而用户和开发者可以通过自定义资源定义的形式添加更多的资源。例如,如果我们想定义一个CronTab资源,我们可以这样做。

apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: crontabs.my.org
spec:
group: my.org
versions:

  • name: v1
    served: true
    storage: true
    Schema:
    openAPIV3Schema:
    type: object
    properties:
    spec:
    type: object
    properties:
    cronSpec:
    type: string
    pattern: '^(\d+|*)(/\d+)?(\s+(\d+|*)(/\d+)?){4}$'
    replicas:
    type: integer
    minimum: 1
    maximum: 10
    scope: Namespaced
    names:
    plural: crontabs
    singular: crontab
    kind: CronTab
    shortNames:
  • ct
    我们以后可以用如下的方式创建一个CronTab资源。

    apiVersion: "my.org/v1"
    kind: CronTab
    metadata:
    name: my-cron-object
    spec:
    cronSpec: " */5"
    image: my-cron-image
    replicas: 5

Another form of Kubernetes scalability is that developers can write their own Operator, which is a specific process that runs in a Kubernetes cluster and follows the control loop model. An Operator allows users to automatically manage CRD (Custom Resource Definition) by talking to the Kubernetes API.

The community has several tools that allow developers to create their own Operators. One of these tools is the Operator Framework and its Operator SDK. The SDK provides a framework for developers to start creating operators very quickly. For example, you can start creating an Operator with the following command line.


$ operator-sdk new my-operator --repo github.com/myuser/my-operator

This creates an entire boilerplate including YAML files and Golang code for your Operator.

.
|____cmd
| |____manager
| | |____main.go
|____go.mod
|____deploy
| |____role.yaml
| |____role_binding.yaml
| |____service_account.yaml
| |____operator.yaml
|____tools.go
|____go.sum
|____.gitignore
|____version
| |____version.go
|____build
| |____bin
| | |____user_setup
| | |____entrypoint
| |____Dockerfile
|____pkg
| |____apis
| | |____apis.go
| |____controller
| | |____controller.go

The way to add API and controller is as follows.

$ operator-sdk add api --api-version=myapp.com/v1alpha1 --kind=MyAppService
$ operator-sdk add controller --api-version=myapp.com/v1alpha1 --kind=MyAppService

Finally, build and push the Operator to your container registry.

$ operator-sdk build your.container.registry/youruser/myapp-operator

If developers need more control, they can modify the boilerplate code in the Golang file. For example, to modify the specific content of the controller, they can modify the controller.go file.

Another project, KUDO, can create an Operator just by using a declarative YAML file. For example, the Operator of Apache Kafka is defined in this way, which allows users to install a Kafka cluster on Kubernetes with only a few commands.

$ kubectl kudo install zookeeper
$ kubectl kudo install kafka

Then use another command to adjust kafka parameters.

$ kubectl kudo install kafka --instance=my-kafka-name \
            -p ZOOKEEPER_URI=zk-zookeeper-0.zk-hs:2181 \
            -p ZOOKEEPER_PATH=/my-path -p BROKER_CPUS=3000m \
            -p BROKER_COUNT=5 -p BROKER_MEM=4096m \
            -p DISK_SIZE=40Gi -p MIN_INSYNC_REPLICAS=3 \
            -p NUM_NETWORK_THREADS=10 -p NUM_IO_THREADS=20

Innovation

In the past few years, Kubernetes has had a major release every three or four months, that is to say, there will be three or four major versions every year. The introduction of new features has not slowed down. The last released version has more than 30 different new features and improvements. In addition, even in difficult times, code contributions show no signs of slowing down, as shown by the activities of the Kubernetes project Github.

The new features allow cluster operators to have more flexibility when facing a variety of different workloads. Software engineers also like to have more control and can directly deploy applications to the production environment.

community

Another big aspect of Kubernetes' popularity is its strong community. For starters, when Kubernetes entered version 1.0 in 2015, it was donated to the Cloud Native Computing Foundation (CNCF).

In addition, as the project progresses, there are a large number of community SIGs (special interest groups) that conduct research on different areas of Kubernetes. They are constantly adding new features to facilitate other users.

The Cloud Native Foundation also organized CloudNativeCon/KubeCon, which is the largest open source event in history as of this writing. This event is generally held three times a year, gathering thousands of relevant technical experts and professionals.

In addition, the Cloud Native Foundation has a technical oversight committee that works with its SIGs to study the foundation’s new and existing projects in the cloud native ecosystem. Most of these projects help increase the value of Kubernetes.

Finally, I believe that without the community consciously tolerating each other and welcoming any newcomers to join, Kubernetes will not be as successful as it is today.

future

One of the main challenges facing developers in the future is how to pay more attention to the details of the code, rather than the infrastructure for the code to run. For this reason, serverless architecture is becoming one of the main architectural paradigms to solve this challenge. There are already some very advanced frameworks, such as Knative and OpenFaas, which use Kubernetes to abstract the infrastructure from the developer.

In this article, we have shown a brief introduction to Kubernetes, but this is just the tip of the iceberg. Users can utilize more resources, functions and configurations. We will continue to see new open source projects and technologies to enhance or develop Kubernetes, and as we mentioned, these contributions and communities are everywhere.

Original link: https://stackoverflow.blog/2020/05/29/why-kubernetes-getting-so-popular/

Reference reading:

  • Use code to explain why you need an extension-oriented design
  • Several rules of code review
  • The right way to clean architecture
  • What is the ideal DevOps process? Take a look at Slack's code deployment practice
  • Why do I disapprove of writing comments in the code: talk about several realms of writing comments
  • The Art of Pull Request

This article is a translation of high-availability architecture, technical originality and architecture practice articles, and you are welcome to submit articles through the official account menu "Contact Us".

Highly available architecture

Changing the way the internet is built

Why Kubernetes has become so popular (2020 version)
Long press the QR code to follow the "High Availability Architecture" official account

Guess you like

Origin blog.51cto.com/14977574/2546124