K8S
What is K8S?
K8s is an open source tool developed by Google that provides cluster deployment and management for containerized applications.
The name Kubernetes comes from the Greek word meaning "helmsman" or "pilot" and there are 8 characters between k and s, so it is called k8s and Google open sourced Kubernetes in 2014.
K8s main features
High availability, no downtime, automatic disaster recovery
Grayscale update does not affect normal business operation
Roll back historical versions with one click
Convenient scaling and expansion (application scaling, machine addition and subtraction), providing load balancing
There is a perfect ecology
Different deployment options
Traditional Deployment
The application is deployed directly on the physical machine. The machine resource allocation is not well controlled. When problems arise, most of the machine's resources may be occupied by a certain application, causing other applications to fail to run normally and application isolation cannot be achieved.
Virtualized Deployment
Running multiple virtual machines on a single physical machine. Each virtual machine is a complete and independent system, which consumes a lot of performance.
Container Deployment
All containers share the host system, lightweight virtual machine performance loss is small, resource isolation, CPU and memory allocation on demand
When is K8S needed?
When your application only runs on one machine, a docker+docker-compose is ok.
When your application runs on 3-4 machines, you can still configure the running environment + load balancer independently.
But when your machines gradually increase to dozens, k8s can show its skills, allowing you to easily manage thousands of machines.
K8s can provide you with centralized management of cluster machines and applications. Adding machines, version upgrades, and version rollbacks can all be solved with one command. Non-stop grayscale updates ensure high availability, high performance, and high scalability.
K8S architecture diagram
Master (master node)
The control platform does not require high performance and does not run tasks. Usually one is enough. You can also create multiple masters to improve the availability of the cluster.
Work (work node)
It can be a virtual machine or a physical computer. Tasks are run in it. The performance of the machine needs to be good. There are usually multiple clusters that can be continuously expanded. Each working node is managed by the master node.
concept pod
Pod is the smallest unit of K8s scheduling and management. A pod can contain one or more containers. Each pod has its own virtual IP. A working node can have multiple pods. The main node automatically schedules the pod to which node to run based on the load.
Kubernetes components
Kube-apiserver API server, exposing the Kubernetes API
The Etcd key-value database can be used as a backend database to save all Kubernetes cluster data.
Kube-scheduler schedules pods to run on which node
Ku-controller cluster controller
Cloud-controller interacts with cloud service providers
Install Kubernetes cluster
Minikube
It’s just a k8s cluster simulator. A cluster with only one node has only master and worker for testing together.
Directly use the cloud platform Kubernetes
Visual construction only requires a few simple steps to create a cluster.
Advantages: Simple installation, complete ecology, load balancer, storage, etc. are all configured for you and can be done with simple operations.
Bare metal installation
At least two machines are required (one master node and one worker node). You need to install the Kubernetes components and configure them yourself, which is a bit troublesome. You can rent servers from various cloud vendors on time and at a low cost, then destroy them after use.
Disadvantages: Troublesome configuration, lack of ecological support such as load balancer, cloud storage
Minikube installation
>Simple installation supports various platforms. Docker needs to be installed in advance.
# Start the cluster
Minikube start
# View nodes kubectl is a command tool used to interact with k8s clusters
Kubectl get node
# Stop the cluster
Minikube stop
# Clear the cluster
Minikube delete –all
#Install the cluster visual web UI console
Minikube dashboard