Quickly Install Kubernetes

This document describes how to quickly deploy a Kubernetes cluster with the help of easzup: Depending on your scenario, you can choose one of the following two deployment modes:

Kubernetes All-in-one Installation Method

Download File

  • Use Kato to speed up the download tool script easzup 2.1.0 version. Different releases of easzup affect the version of kubernetes that can be installed. For specific information, please check easzup version
wget https://registry.gitlab.com/gridworkz/kato/pkg/easzup && chmod +x easzup
  • Use tool scripts to download other files, including offline mirrors, binary files, etc., and save them in the /etc/ansible directory
./easzup -D

Configure Keyless Login

ssh-keygen -t rsa -b 2048 -N '' -f ~/.ssh/id_rsa
ssh-copy-id $IP # $IP is the address of all nodes including itself, enter yes and root password as prompted

Orchestrating k8s installation on the ansible console

Run kubeasz as a container, see document

./easzup -S

Install aio cluster with default configuration

docker exec -it kubeasz easzctl start-aio

Copy the kubectl tool to /usr/bin/kubectl

When you need to expand a node node, after configuring the corresponding node to log in without a key, perform the following operations to add the node node

docker exec -it kubeasz easzctl add-node $NEW_NODE_IP

Verify the Installation Result

If kubectl prompts: command not found, exit and log in again with ssh, the environment variable will take effect

$ kubectl version # Verify the cluster version 
$ kubectl get componentstatus # Verify the status of components such as scheduler/controller-manager/etcd
$ kubectl get node # Verify that the node is ready (Ready)
$ kubectl get pod --all-namespaces # Verify the cluster pod status, the network plug-in, coredns, metrics-server, etc. have been installed by default
$ kubectl get svc --all-namespaces # Verify cluster service status

Finish Kubernetes installation, Start Kato installation

HA Installation of Kubernetes

The node configuration required for a highly available cluster is as follows:

RoleQuantityDescription
Deploy the node1Run the ansible/easzctl script, you can reuse the master, it is recommended to use a separate node
etcd nodes3Note that etcd cluster needs 1,3,5,7…odd number of nodes, generally the master node is reused
master node2High availability cluster with at least 2 master nodes
node node3The node running the application load, you can increase the machine configuration/number of nodes as needed

Install dependent tools on each node

Ubuntu 16.04 please execute the following script:

# The scripts in the document are executed by the root user by default
apt-get update && apt-get upgrade -y && apt-get dist-upgrade -y
# Install python2
apt-get install python2.7
# Ubuntu16.04 may need to configure the following soft connections
ln -s /usr/bin/python2.7 /usr/bin/python

CentOS 7 please execute the following script:

# The scripts in the document are executed by the root user by default
yum update
# Install python
yum install python -y

Configure Password-free Login

Perform the following operations on the deployment node:

ssh-keygen -t rsa -b 2048 -N '' -f ~/.ssh/id_rsa
ssh-copy-id $IPs #$IPs is all node addresses including itself, enter yes and root password as prompted

Orchestrating k8s Installation on the Ansible Console

Speed ​​up downloading tool script easzup 2.1.0 version through Kato

wget https://registry.gitlab.com/gridworkz/kato/pkg/easzup && chmod +x easzup

Use script tools to download files such as offline mirrors, which are stored in the /etc/ansible directory

./easzup -D

Configure cluster parameters

cd /etc/ansible && cp example/hosts.multi-node hosts

After copying the cluster configuration template to the specified location, you must follow the template format and modify the /etc/ansible/hosts file according to your node plan, otherwise the cluster cannot be installed. The file includes the host list and part of the cluster configuration

# The number of etcd cluster nodes should be an odd number such as 1, 3, 5... etc. It cannot be set to an even number
# Variable NODE_NAME is the unique name of etcd node in etcd cluster, it cannot be the same
# etcd node host list
[etcd] 
192.168.1.1   NODE_NAME=etcd1
192.168.1.2   NODE_NAME=etcd2
192.168.1.3   NODE_NAME=etcd3

# kubernetes master node host list
[kube-master]
192.168.1.1
192.168.1.2

# kubernetes node node host list
[kube-node]
192.168.1.3
192.168.1.4

# [Optional] Harbor service, docker mirror repository
#'NEW_INSTALL': Set to yes to install the harbor service; set to no to not install the harbor service
#'SELF_SIGNED_CERT': set to no you need to put the harbor.pem and harbor-key.pem files in the down directory
[harbor]
#192.168.1.8 HARBOR_DOMAIN="harbor.yourdomain.com" NEW_INSTALL=no SELF_SIGNED_CERT=yes

# [Optional] External load balancing node host list
[ex-lb]
#192.168.1.6 LB_ROLE=backup EX_APISERVER_VIP=192.168.1.250 EX_APISERVER_PORT=8443
#192.168.1.7 LB_ROLE=master EX_APISERVER_VIP=192.168.1.250 EX_APISERVER_PORT=8443

# [Optional] Cluster ntp server list
[chrony]
#192.168.1.1

[all: vars]
# --------- Main Variables ---------------
# Optional kubernetes cluster runtime: docker, containerd
CONTAINER_RUNTIME="docker"

# kubernetes network plug-in: calico, flannel, kube-router, cilium, kube-ovn
CLUSTER_NETWORK="flannel"

# kube-proxy service proxy mode:'iptables' or'ipvs'
PROXY_MODE="ipvs"

# K8S Service CIDR, cannot overlap with the host network
SERVICE_CIDR="10.68.0.0/16"

# Cluster CIDR (Pod CIDR), cannot overlap with the host network
CLUSTER_CIDR="172.20.0.0/16"

# Node port range
NODE_PORT_RANGE="20000-40000"

# Cluster DNS domain name
CLUSTER_DNS_DOMAIN="cluster.local."

# -------- Additional Variables (don't change the default value right now) ---
# Binary file directory
bin_dir="/opt/kube/bin"

# Certificate file directory
ca_dir="/etc/kubernetes/ssl"

# Deployment directory (kubeasz workspace)
base_dir="/etc/ansible"

Containerized running kubeasz

./easzup -S

Install kubernetes cluster using ansible

docker exec -it kubeasz ansible-playbook /etc/ansible/90.setup.yml

When you need to expand a node node, after configuring the corresponding node to log in without a key, perform the following operations to add the node node

docker exec -it kubeasz easzctl add-node $NEW_NODE_IP

Finish Kubernetes installation, Start Kato installation