当前位置:网站首页>One article introduces you to the world of kubernetes

One article introduces you to the world of kubernetes

2022-06-24 01:06:00 Luga Lee

 Based on these tools , I believe it can help you from  0  Get started  Kubernetes  colony , Start the journey of cloud origin  ~

     Kubernetes, Usually we abbreviate it to  “K8s”, Is an open source container orchestration platform , Initially in   Shipyard Widely used in the platform . Many of the tasks involved in maintaining containerized applications based on automation patterns , For example, deployment 、 Expand 、 Load balancing 、 Grayscale and resource elasticity, etc . Its aerial view is as follows :

Kubernetes Aerial view

Kubernetes  Inferiority

     Kubernetes It is the main orchestration platform for cloud native ecological asset management , Thousands of companies have optimized their deployment , Authors efficiency . However , It is notorious for its steep learning curve and cumbersome underlying principles . in short , Kubernetes  It's really a little innocent , It is not only welcomed by the majority of open source enthusiasts, but also deterred everyone , Makes it difficult to achieve a bowl level .

     That means , If everyone is trying to learn and master  Kubernetes Iceberg technicians , So you're lucky , Because there are a lot of open source resources that can help you start right Kubernetes Cloud native journey .

Kubernetes  advantage

     Although the use of Kubernetes You may encounter all kinds of difficulties 、 Danger , But fortunately , be based on h reasonable Kubernetes  The platform will bring us the following benefits :

     1、 Reduce cloud costs by efficiently expanding clusters

     2、 Simplify the different engineering processes of the team ( For example, development 、 Test and release )

     3、 Minimize safety issues , Such as cross container communication

     4、 Determine how traffic passes through infrastructure

     5、 Prevent resource poor services from interrupting each other

     Yours Kubernetes The journey

     indeed , Study Kubernetes It's a long and complicated 、 The process of excitement and decadence , But everyone has to start somewhere . Actually , just 2-3 God , We can use it locally or in the cloud Kubernetes Deploy and manage containers . This article will be a high-level guide , Lead everyone step by step , From macro to micro , From tools to principles , With  0 Basic introduction  Kubernetes The world .

     Before we start ...

We need to download and install the base environment , for example ,Docker、Kubectl And other basic tools , So that it can provide commands for normal interaction with the cluster .

The first 1 God : Local clusters

     Set up local Kubernetes Clustering is one of the best practice routes for getting familiar with basic operations and concepts . In this paper , I will focus on the more classic 2 Tools ,Minikube  and   K3d, Following pair 2 A brief analysis of .

     If you are a Yunyuan Xiaobai , It means that everything will start from scratch ,Minikube Maybe it's a good choice . Use Minikube, We can quickly and easily set up local... From the command line Kubernetes colony . There are many cases on the Internet , How to use Kubernetes In document Minikube Create clusters . About Minikube Related content , Not to be repeated in this article , You can refer to the previous article :Kubernetes Build tools .

     Minikube There is no doubt about the power of , Its role is played incisively and vividly in the local environment of the majority of technicians . In addition to this , As a rising star ,K3d Run as local K3s( K8s Lightweight version of ) Another way of is accelerating .K3d One of the most attractive features is , It allows us to Docker Create and manage clusters in ( Instead of running in a virtual machine Minikube ). Check out this starter repo : https://github.com/iwilltry42/k3d-demo Get an example of K3d Applications .

[[email protected] ~ ] % curl -s https://raw.githubusercontent.com/rancher/k3d/main/install.sh | bash
... ...
[[email protected] ~ ] % k3d cluster create mycluster -p 9080:[email protected]
... ...
K3d Command

The first 2 God : Deploy

      In container Ecology ,Kubernetes The basic building blocks of are called checklists YAML file . These documents are submitted to Kubernetes Explain what we want to create , And how you want to create .

     Here are Nginx Example listing of service deployment , With the latest version v1.19 For example , The details are as follows :

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.19.10
        ports:
        - containerPort: 80

For single copy , We can easily create and maintain , However , Once we want to deploy multiple copies of the application , Maintaining copies of several slightly different lists can be a bit stretched .

     This is it. Helm The use of template making . Template based tools , We can easily create and manage variations of the application , Maintain the generality of a specific value , And make adaptive adjustment as needed .Helm As a comprehensive tool for cluster creation and release management, it came into being .

      besides ,Helm It has also become a tool for packaging the entire application  Kubernetes System , We refer to these packages collectively as diagrams . for example , We can use charts based on helm install kube prometheus stack prometheus community/kube prometheus stack Install the monitoring service from the command line ( Measurement collector 、 Time series databases and dashboards ).

Helm workflow

      About Helm Related content , Refer to the previous article :Helm Management tools resolve .

     The first 3 God : management

      Past the front 2 Days of practice , We have now deployed a complete cluster , But at the same time , We need to know what happened , Need to be based on our actual business or Demo Effective management . Inside this , We usually recommend the following tools , Of course , There are better , Maybe it depends on everyone's usage habits and style .

      First , Let's take a look at the most classic command line tool -Kubectl, Based on this tool ,Kubectl For monitoring Kubernetes Clustering is very useful . We can get Kubernetes Know the state of any object , View real time logs , And in Pod Get the command line . Some useful 、 The little-known meaning of fun is as follows :

kubectl watch: see Kubernetes Real time events for objects .  kubectl port forward: A self-organizing port tunnel from the local host to services in the cluster .  kubectl proxy: establish kubernetes API Our local agent .

     And Kubectl Command line tools are similar , such as Ktunnel . It is also a CLI Tools , Used in Kubernetes Establish a reverse tunnel between the cluster and the local machine . It allows us to expose our deployed machines to the external environment as services in the cluster , Its working principle can be referred to as follows :

Ktunnel Schematic diagram of working principle

If we want to record one group at a time Pod,Kubectl We have not really given us relevant and effective help in this regard . So , We can try it  Stern Tools .

      be based on Stern, We can span any given ( adopt regex )Pod Set view log . It even displays logs of services started and stopped during execution .

     for example , function stern-n kube System DNS Will be displayed Kube String contained in system namespace  “DNS” Any of the Pod All the logs of .

[[email protected] ~ ] % go get -u github.com/stern/stern
... ...
[[email protected] ~ ] % asdf plugin-add stern
... ...
[[email protected] ~ ] % asdf install stern latest
... ...
[[email protected] ~ ] % stern envvars --context staging --container gateway
... ...

Next , Let's introduce 2 Classic GUI Management tools :K9s And Lens . In terms of overview tools ,K9 and Lens It's actually different sides of the same coin . Whatever the choice , It all comes down to personal preferences , But in essence , Both have complete functions and good maintainability , It's worth trying .

     If you like the terminal based console , Give priority to K9s , After all, it can monitor existing K8s The basic dashboard of the cluster . besides ,K9s It has a series of useful functions , for example , Benchmarking and resource allocation information, etc .

[[email protected] ~ ] % wget https://github.com/derailed/k9s/releases/download/v0.24.2/k9s_Linux_x86_64.tar.gz
[[email protected] ~ ] % tar -xzf k9s_*.tar.gz -C ~/luga-cloud/tools/k9s
... ...
[[email protected] ~ ] % ~/luga-cloud/tools/k9s/k9s
K9s Command
K9s Command

     If you like GUI Provide availability and clarity , Please check out Lens. It provides a series of tools for general cluster overview , And other related tools , So that we can learn more about the detailed configuration with just a few clicks .

# Download the 3.4.0 AppImage for Lens, mark it executable and copy it to your $PATH
# (output omitted for brevity)

[[email protected] ~ ] % wget https://github.com/lensapp/lens/releases/download/v3.4.0/Lens-3.4.0.AppImage
[[email protected] ~ ] % chmod +x Lens-3.4.0.AppImage
[[email protected] ~ ] % sudo mv Lens-3.4.0.AppImage /usr/sbin/lens
Lens Administrative console

      Brief analysis based on the above tools , I believe you can set foot on the road to Kubernetes  The journey of enlightenment . Next , We need to spend a lot of energy combing 、 master  Kubernetes  Every specific component of Ecology , Only based on this , We can be right  Kubernetes  The ecological architecture system is familiar 、 Achieve mastery through a comprehensive .

Kubernetes Ecological architecture reference system
原网站

版权声明
本文为[Luga Lee]所创,转载请带上原文链接,感谢
https://yzsam.com/2021/11/20211120214659987l.html