Use of kubernetes YAML files

Use of kubernetes YAML files

01 Introduction to YAML files

When K8S starts a Pod, it will use a YAML file to start it. Today we will look at the most commonly used format of YAML files.

The syntax of YAML is very similar to that of JSON. Both are organized in the form of key-value. It can represent common data types such as list and dict. Its suffix is ​​generally ".yml". It has the following characteristics:

1. Case sensitivity

2. Use indentation to indicate progressive relationships

3. Tabs are not allowed for indentation, only spaces are allowed

4. The number of spaces for indentation is not important, as long as the elements at the same level are aligned on the left, which is similar to Python syntax

5. Use "#" to indicate comments

6. The key-value structure is surrounded by {}, and the list structure is surrounded by [].

YAML---key-value type

a. Use the key:value format to express it. There needs to be a space between the key and the value, otherwise an error will be reported;

b. If there is a hierarchical relationship, it can be expressed in the following two ways:

key:{key1: value1,key2: value1}

Or key:
    key1:value1
    key2:value2

c. Represents a key-value format, where value is a dict

Websites:
  YAML: yaml.org
   Ruby: ruby-lang.org
   Python: python.org
   Perl: use.perl.org

Expressed in json format:
  websites:
    YAML: 'yaml.org',
    Ruby: 'ruby-lang.org',
    Python: 'python.org',
    Perl: 'use.perl.org'
   }

YAML---list type

Starting with - indicates an array, as follows:

- A
- B
- C

Represented as an array: [A,B,C]

Here is a slightly more complex example:

students:
    -
        id: 1
        name: zhangsan
        age: 12
    -
        id: 2
        name: lisi
        age: 15

Represented as an array:
students:[{id: 1,name: zhangsan,age: 12},{id: 2,name: lisi,age: 15}]

The elements in the array are also a dict of key-value structure.

Comparison between a Json and a Yaml:

yaml format file nodes:
  - name: jobE
    type: command
    config:
      command: echo "This is job E"
    dependsOn:
       -jobD

  - name: jobD
    type: command
    config:
      command: echo "This is job D"
    dependsOn:
      -jobA
      -jobB
      -jobC


Expressed in json format:
{
    "nodes":[
        {
            "name":"jobE",
            "type":"command",
            "config":{
                "command":"echo \"This is job E\""
            },
            "dependsOn":[
                "jobD"
            ]
        },
        {
            "name":"jobD",
            "type":"command",
            "config":{
                "command":"echo \"This is job D\""
            },
            "dependsOn":[
                "jobA",
                "jobB",
                "jobC"
            ]
        }
    ]
}

02 The relationship between Master, Node and Pod in K8S

Master architecture diagram:

in:

The API Server provides an HTTP REST interface, which is the only entry point for adding, deleting, modifying, and checking all resources in k8s, and is also the entry point for cluster control;

Scheduler is the process responsible for resource scheduling;

Controller Manager is the automation control center for all resource objects;

Etcd provides data storage services for resource objects

K8S uses the deployment method of Master node and Node node to manage the entire cluster. The relationship between Master node, Node node and Pod is more appropriately described by the official structure diagram:

As you can see, there is a direct communication interaction process between the Master and the Node, and the Pod is deployed on the Node. To put it simply, it is:

Master is a server with a fixed IP address

Node is a server with a fixed IP address

A Pod is a process on a Node and has a virtual IP address, which may or may not be the same as the Node IP address.

As we know, a Pod can have multiple containers. If we add more containers, it will become the following:

The calling relationship between them is simply:

When a Pod is created, its information will be put into the Master's Etcd storage. Then the information about creating the Pod will be scheduled by K8S to a Node and bound. Then the kubelet process on the Node where the Pod is located will be instantiated into a group of related Docker containers and started.

The above is the detailed content of the use of kubernetes YAML files. For more information about kubernetes YAML files, please pay attention to other related articles on 123WORDPRESS.COM!

You may also be interested in:
  • How to deploy a single-node redis database in kubernetes environment
  • Detailed explanation of the use of cloud native technology kubernetes scheduling unit pod
  • Detailed tutorial on using the client-go tool to call the kubernetes API interface (v1.17 version)
  • Introduction to Kubernetes Probes

<<:  Future-oriented all-round web design: progressive enhancement

>>:  Summary of the differences between Vue's watch, computed, and methods

Recommend

Move MySQL database to another disk under Windows

Preface Today I installed MySQL and found that th...

CentOS installation mysql5.7 detailed tutorial

This article shares the detailed steps of install...

Use of Linux network configuration tools

This article introduces RHEL8 network services an...

Linux Jenkins configuration salve node implementation process diagram

Preface: Jenkins' Master-Slave distributed ar...

Understanding flex-grow, flex-shrink, flex-basis and nine-grid layout

1. flex-grow, flex-shrink, flex-basis properties ...

About debugging CSS cross-browser style bugs

The first thing to do is to pick a good browser. ...

Solution to MySQL remote connection failure

I have encountered the problem that MySQL can con...

How to implement the strategy pattern in Javascript

Table of contents Overview Code Implementation Su...

CSS3 realizes the graphic falling animation effect

See the effect first Implementation Code <div ...

MySql8 WITH RECURSIVE recursive query parent-child collection method

background When developing a feature similar to c...

JavaScript Reflection Learning Tips

Table of contents 1. Introduction 2. Interface 3....

Detailed explanation of data sharing between Vue components

Table of contents 1. In project development, the ...

How to use Dayjs to calculate common dates in Vue

When using vue to develop projects, the front end...