Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Installation and deployment of Kubernetes Cluster

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Kubernetes Overview:

Kubernetes is an open source application used to manage containerized applications on multiple hosts in the cloud platform. The goal of Kubernetes is to make the deployment of containerized applications simple and efficient (powerful). Kubernetes provides a mechanism for application deployment, planning, updating, and maintenance.

Kubernetes was founded and managed by Google in 2014 and is an open source version of Google's large-scale container management technology Borg for more than 10 years.

Functions that can be achieved through kubernetes:

Rapid deployment of applications, rapid expansion of applications seamlessly docking new application functions to save resources and optimize the use of hardware resources

Our goal is to promote an ecosystem of components and tools to reduce the burden of applications running in public or private clouds.

Characteristics of kubernetes:

Portable: support public cloud, private cloud, hybrid cloud, multiple cloud (multi-cloud) extensible: modular, plug-in, mountable, combinable automation: automatic deployment, automatic restart, automatic replication, automatic scaling / extension

Why use containers? Summary of container advantages:

Quickly create / deploy applications: container images are easier to create than VM virtual machines. Continuous development, integration, and deployment: provide reliable and frequent container image build / deployment, using fast and easy rollback (due to image immutability). Separation of development and running: create container images during the build or release phase to decouple the application from the infrastructure. Development, test, and production environment consistency: consistency that runs locally or externally (production environment). Cloud platform or other operating system: can run in Ubuntu, RHEL, CoreOS, on-prem, Google Container Engine, or any other environment. Loosely coupled, distributed, resilient, and microserviced: applications are divided into smaller, independent components that can be dynamically deployed and managed. Resource isolation Resource Utilization: more efficient

What can kubernetes do?

Containerized applications can be run on Kubernetes clusters of physical or virtual machines, and Kubernetes can provide a "container-centric infrastructure" to meet some common needs of running applications in a production environment, such as:

Multiple processes (running as containers) work together. (Pod) replication of Distributing secrets application health detection application instances mounted on the storage system Pod auto-scaling / extension Naming and discovering load balancing rolling update resource monitoring log access debugging application provides authentication and authorization

Kubernetes Chinese official website:

Https://kubernetes.io/zh/

Kubernetes Chinese Community:

Https://www.kubernetes.org.cn/doc-11

Prepare to build a kubernetes cluster environment:

3 dockerhost hosts (centos7)

Master: 172.16.1.30

Node01:172.16.1.31

Node02:172.16.1.32

Note: each host has a minimum memory of 2GB and a minimum dual-core cpu. Each host must install docker environment, turn off the firewall (usually kubernetes is running within the company), disable selinux, and ensure time synchronization.

We now install kubernetes using the automated deployment software (kubeadm) officially developed by kubernetes to install kubernetes more quickly.

Clear the iptables rule and reload the docker (all nodes need action):

[root@master ~] # iptables-F [root@master ~] # systemctl daemon-reload [root@master ~] # systemctl restart docker

(1) modify the hostname:

[root@sqm-docker01 ~] # hostnamectl set-hostname master [root@sqm-docker01 ~] # bash [root@sqm-docker02 ~] # hostnamectl set-hostname node01 [root@sqm-docker02] # bash [root@sqm-docker03 ~] # hostnamectl set-hostname node02 [root@sqm-docker03 ~] # bash

(2) ssh, domain name resolution, secret-free login:

Configure domain name resolution: [root@master ~] # vim / etc/hosts

# # copy the hosts file to other nodes:

[root@master ~] # scp / etc/hosts root@172.16.1.31:/etc/hosts [root@master ~] # scp / etc/hosts root@172.16.1.32:/etc/hosts secret-free login: [root@master ~] # ssh-keygen-t rsa # generate key

Copy the key to another node:

[root@master ~] # ssh-copy-id node01

[root@master ~] # ssh-copy-id node02

(3) disable swap (kubernetes feature)

Note: all nodes must be disabled, otherwise you cannot join the cluster.

[root@master] # swapoff-a # is effective temporarily

Permanently disable swap: (modify boot loading configuration file) [root@master ~] # vim / etc/fstab

You can reload to make it effective: [root@master ~] # mount-an install kubernetes:

Log in to Alibaba's open source image site and download the yum source:

Write a custom repo file: (all three nodes need to be deployed)

[root@master yum.repos.d] # pwd/etc/yum.repos.d [root@master yum.repos.d] # vim kubernetes.repo

View available repo sources: [root@master yum.repos.d] # yum repolist

# # generate cache locally:

[root@master yum.repos.d] # yum makecache

# # copy repo file to node01 and node02:

[root@master yum.repos.d] # scp kubernetes.repo node01:/etc/yum.repos.d/ [root@master yum.repos.d] # scp kubernetes.repo node02:/etc/yum.repos.d/

Next, do the same on both nodes.

(2) enable iptables bridging (all three nodes need to be deployed)

[root@master ~] # vim / etc/sysctl.d/k8s.conf # customize the conf file in this directory / / add the following configuration item: net.bridge.bridge-nf-call-iptables = 1net.bridge.bridge-nf-call-ip6tables = 1Accord / reload the file to make it effective: [root@master ~] # sysctl-p / etc/sysctl.d/k8s.conf net.bridge.bridge-nf-call-iptables = 1net.bridge.bridge-nf-call-ip6tables = 1

Note: if the file cannot be found, we need to load a module:

[root@master ~] # modprobe br_netfilter

Copy the configuration file to node01 and node02 for deployment.

(3) enable route forwarding (all three nodes need to be deployed)

[root@master ~] # echo net.ipv4.ip_forward = 1 > / etc/sysctl.conf [root@master ~] # sysctl-p # load the file to make it effective net.ipv4.ip_forward = 1

Similarly, copy the configuration file to node01 and node02 for deployment.

(4) operate on the master node:

# modify the configuration file of yum and cache the following rpm package to be downloaded: [root@master ~] # vim / etc/yum.conf

Download:

[root@master ~] # yum-y install kubelet-1.15.0-0 kubeadm-1.15.0-0 kubectl-1.15.0-0

Check whether the rpm package is cached after download: [root@master ~] # cd / var/cache/yum/x86_64/7/kubernetes/packages

# # add the service to boot:

[root@master ~] # systemctl enable kubelet.service

Initialize the cluster (download image):

However, due to the limitations of the domestic network environment, we cannot download the image directly from docker Mirror Station. At this time, we need to manually download the image from Google Mirror Station and rename it. Here we use script to implement it.

Part of the script is as follows:

# you can refer to this format for download:

[root@master ~] # cat k8s.sh

#! / bin/bash

Docker pull mirrorgooglecontainers/kube-apiserver:v1.14.1

Docker pull mirrorgooglecontainers/kube-controller-manager:v1.14.1

Docker pull mirrorgooglecontainers/kube-scheduler:v1.14.1

Docker pull mirrorgooglecontainers/kube-proxy:v1.14.1

Docker pull mirrorgooglecontainers/pause:3.1

Docker pull mirrorgooglecontainers/etcd:3.3.10

Docker pull coredns/coredns:1.3.1

I have already downloaded it here. I just need to import the image of the figure and shadow:

[root@master ~] # mkdir images

[root@master ~] # cd images/

Import image command: docker load-- input

# # initializing the cluster:

[root@master images] # kubeadm init-kubernetes-version=v1.15.0-pod-network-cidr=10.244.0.0/16-service-cidr=10.96.0.0/12-ignore-preflight-errors=Swap

Parameter explanation:

-- kubernetes-version: specify the current kubernetes version number (view version: kubelet-- version)

-- pod-network: specifies the pod network segment, and kubernetes specifies the network by default.

-- ignore: ignore all errors

Note: if the information after successful initialization is overwritten and want to reinitialize, you can first execute the kubeadm reset command to reset, and then reinitialize.

When you initialize after you have executed the reset command, the following error may be reported:

Error reporting refers to an error in the database, so we need to delete the directory and reinitialize it:

[root@master ~] # rm-rf / var/lib/etcd

# # create a directory and grant permissions according to the above prompts:

[root@master ~] # mkdir-p $HOME/.kube [root@master ~] # sudo cp-I / etc/kubernetes/admin.conf $HOME/.kube/config [root@master ~] # sudo chown $(id-u): $(id-g) $HOME/.kube/config

# # View nodes:

You can see that the state of the master is not ready (NotReady). This state is due to the lack of an attachment flannel, and the Pod cannot communicate without the network.

# deploy the cross-host network of docker container:

/ / download the yml file locally: [root@master ~] # wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

/ / execute the yml file: [root@master ~] # kubectl apply-f kube-flannel.yml

/ / View the configured yml file:

(5) the above is the installation and deployment of the master node, and then the installation of the node.

# download node01 and node02 respectively (no need to install kubectl):

[root@node01 ~] # yum-y install kubelet-1.15.0-0 kubeadm-1.15.0-0

[root@node02 ~] # yum-y install kubelet-1.15.0-0 kubeadm-1.15.0-0

# add the service to boot after downloading: [root@node01 ~] # systemctl enable kubelet.service [root@node02 ~] # systemctl enable kubelet.service

Node01: (import local image)

[root@node01 ~] # mkdir images [root@node01 ~] # cd images/

# # copy these images to node02 for installation:

[root@node01 images] # scp * node02:/root/images

# # View node02 image after import:

(6) add node01 and node02 nodes to the cluster:

Execute the following command to join the cluster (the cluster is generated at initialization, and the value is different each time)

Kubeadm join 172.16.1.30 6443-token 6udpmi.u4msx9vgkqfr1i1l-discovery-token-ca-cert-hash sha256:4fdbbb94d5d7087a6c27d441df2f89d21e9ca035f0386ed963a195656794619a

The node02 node does the same thing.

# # when node01 and node02 join the cluster, view the node information on master:

Make sure that there is information about other nodes and that the status is ready.

Note: if the state is NotReady, then there is a network problem. If you do not deploy a cross-host network, you need to execute the cross-host network that deployed the docker container above.

At this point, the kubernetes cluster has been built-

The next optimization operation is as follows: (1) change the tab distance: [root@master ~] # vim. Vimrcset tabstop=2 [root@master ~] # source .vimrc (2) / / kubect command automatic completion: [root@master ~] # yum install-y bash-completion [root@master ~] # source / usr/share/bash-completion/bash_completion [root@master ~] # source > ~ / .bashrc (3) / view running pod resources (one of the resource objects) -n:namespace kube-system (namespace included with kubernetes) [root@master ~] # kubectl get pods-n kube-system

This completes the deployment of kubernetes cluster content.

-this is the end of this article. Thank you for reading-

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report