From today on, we will learn various special effects of K8S in depth through practice. The most important and basic function of container orchestration is of course containerization.

As we have learned previously, K8S manages the life cycle of POD through controller, which can meet different scenarios in the future. It also provides ReplicaSet, DaemonSet, StatefuleSet and Job controllers

Deployment

Kubectl run nginx-deployment --image=nginx:1.7.9 --replicas=2Copy the code

Check the status of nginx-Deployment with kubectl get Deployment. The output shows two healthy copies running.

Learn more about kubectl Describe Deployment.

kubectl describe deployment nginx-deployment
Copy the code

Most of the content is self-parsing, so focus on this one. A ReplicaSet container is created and Events is the Deployment log to record the ReplicaSet startup process. That is, Deployment manages pods through ReplicaSet.

We execute kubeclt Describe Replicaset to see the details.

Controlled By specifies that this ReplicaSet is created with Deployment nginx-Deployment. Kubectl get Pod kubectl get Pod kubectl get Pod

Both copies are in the running state.

Then use Kubectl Describe Pod to view the excess information

It also validates a process

  1. The user creates Deployment through kubectl
  2. Deployment create ReplicaSet
  3. ReplicatSet create Pod

Command vs configuration file

There are two ways to create a container, one is kubectl which, after executing this command, will give me a yML configuration file. This file will record the process of your operation.

Command line, simple and quick, if you need to manage your containers like code, or deploy more than one, then configuration is suitable for this scenario.

Introduction to the Deployment configuration file

Scaffolding is all done in Java development that, that does not say yML syntax

There are several important parameters in a Deployment configuration

  • ApiVserion: indicates the current version
  • Kind is to create the resource type
  • Metadata is the metadata of a resource, name is the required metadata, and there must be at least one label. The key and value of the label can be any
  • Spec is a deplyment specification
  • Replicas: replications
  • Template defines the POD template, the important part

With the configuration file, we just need to run the container into K8S with kubectl apply -f xxxx.yml

scaling

Scaling is actually increasing/decreasing the number of copies of pod

Now that we have the configuration file, we just need to change the Replicas parameter in the configuration file

Then kubectl apply

K8s does not schedule pods to master nodes by default for security reasons.

Failover

We shut down the K8S-Node2 node

K8s-node2 will be marked as unavailable, and the pod on k8S-node2 will be marked as Unknown. Two new pods will be created on k8S-node1, keeping the total number of copies to the configured number.

After k8S-node2 recovers, unknown pod will be deleted directly and will not be scheduled to K8S-node2.

Method to delete a container

Control pod position with lable

By default, Scheduler schedules pods to all nodes. Sometimes bosses don’t think so and want to allocate it to a specific node, such as a node where a lot of I/O is deployed on SSD. CPU computing is deployed on the computing host

In this case, you can use lable to create a label

kubectl lable node k8s-node1 disktype=ssd
Copy the code

You want to see all the lable

kubectl get node --show-lables
Copy the code

You can also view it through the container configuration file