Quick Start Guide for Kubernetes Deployment¶
0. Introduction¶
After successfully deploying Kubernetes by following this document, the following tasks are completed by default
Feature Component Coverage
-
Kubernetes 1.24.2 High Availability Deployment
-
CoreDNS Component Installation
-
node-local-dns Component Installation
-
ingress-nginx Component Installation
-
metrics-server Component Installation
-
openebs-provisioner Component Driver Installation
Resource List
1. "Minimum Configuration" is suitable for POC scenarios, for functional verification only, not for production environments.
2. For production deployment, evaluate based on the actual data volume ingested. The more data ingested, the higher the storage and specification requirements for TDengine and OpenSearch.
| Purpose | Resource Type | Minimum Spec | Recommended Spec | Quantity | Notes |
|---|---|---|---|---|---|
| Kubernetes Master | Physical Server|VM | 4C8GB 100GB | 8C16GB 100GB | 3 | Version: 1.24.2 Note: If using VMs, increase resource specs accordingly. Reuse one master node as the deployment node. |
| Kubernetes Worker | Physical Server|VM | 4C8GB 100GB | 8C16GB 100GB | 4 | K8s cluster worker nodes, hosting Guance applications, K8s components, and infrastructure services (MySQL 5.7.18, Redis 6.0.6) |
| Guance Proxy Service | Physical Server|VM | 2C4GB 100GB | 4C8GB 200GB | 1 | Used to deploy an Nginx reverse proxy server, proxying to the ingress edge node. Note: For security reasons, do not expose the cluster edge node directly. |
| Guance Network File System Service | Physical Server|VM | 2C4GB 200G | 4C8GB 1TB High-Performance Disk | 1 | Deploy network file system and network storage service, default NFS. (If an existing NFS service is available, this machine can be omitted.) |
| DataWay | Physical Server|VM | 2C4GB 100GB | 4C8GB 100GB | 1 | Used to deploy DataWay |
| OpenSearch | Physical Server|VM | 4C8GB 1TB | 8C16G 1TB | 3 | OpenSearch version: 2.2.1 Note: Password authentication must be enabled. Install the matching version of the analysis-ik tokenizer plugin. |
| TDengine | Physical Server|VM | 4C8GB 500GB | 8C16G 1TB | 3 | TDengine version: 2.6.0.18 |
| Other | Mail Server/SMS | - | - | 1 | SMS gateway, mail server, alert channel |
| Registered Wildcard Domain | - | - | 1 | Main domain must be registered | |
| SSL/TLS Certificate | Wildcard Domain Certificate | Wildcard Domain Certificate | 1 | Ensures site security |
1. Prerequisites¶
Important
- Upload the base environment offline resource package to all cluster nodes, and extract it to the /etc directory on the server.
- The deployment node and other cluster nodes must have SSH passwordless login configured (including the deployment node itself).
- Upload the Guance platform offline resource package to all cluster nodes, and import it into the container runtime environment (containerd).
1.1 Passwordless Login Setup Reference¶
# Log in to the deployment node and execute the following commands
# Generate a key pair
[root@k8s-node01 ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:vruHbsWUUL5M9k0dg15zhIX5Y9MZVJ+enf0JhzF5lP0 root@k8s-node02
The key's randomart image is:
+---[RSA 2048]----+
| .. o@B|
| .. .**B|
| .+..+o+X|
| +oo +*=E|
| Soo .oo==|
| . o o o|
| .o ..|
| o.. |
| o=+ |
+----[SHA256]-----+
# $IP is the address of all nodes, including the deployment node itself. Follow the prompts to enter 'yes' and the root password.
ssh-copy-id $IP
# Set a Python soft link for each node. Not required by default; execute only if using certain Python 3 versions.
# ssh $IP ln -s /usr/bin/python3 /usr/bin/python
2. Deployment Preparation¶
2.1 Downloading Resource Packages¶
Base environment offline resource package download link: Download
2.2 Offline Resource Package Structure¶
Brief description of the offline package contents
/etc/kubeaszis the main kubeasz directory/etc/kubeasz/examplecontains example configuration files/etc/kubeasz/clusterscontains configuration files for created clusters/etc/kubeasz/guancecontains Guance-related charts, yaml files, etc./etc/kubeasz/bincontains binary files for k8s/etcd/docker/cni, etc./etc/kubeasz/downcontains offline container image packages required for cluster installation/etc/kubeasz/down/packagescontains system base software required for cluster installation
3. Installing the Cluster¶
3.1 Important Notes¶
Important
-
Ensure consistent timezone settings and time synchronization across all nodes.
-
All commands in this document require root privileges unless otherwise specified.
-
Start the installation on a clean system. Do not use a system that has previously had kubeadm or other Kubernetes distributions installed.
-
Before executing the one-click installation, configure and verify the custom cluster configuration files, especially
/etc/kubeasz/clusters/xxx/hostsand/etc/kubeasz/clusters/xxx/config.yaml. -
Modify hostnames for easy identification (optional).
3.2 Cluster Role Planning¶
Node configuration for a high-availability cluster:
| Role | Quantity | Description |
|---|---|---|
| Deploy Node | 1 | Runs ansible/ezctl commands; typically reuses the first master node. |
| etcd Node | 3 | Note: The etcd cluster requires an odd number of nodes (1, 3, 5, ...). Typically reuse master nodes. |
| Master Node | 3 | A high-availability cluster requires at least 2 master nodes. |
| Worker Node | N | Nodes that run application workloads. Can increase machine specs or node count as needed. |
Note
By default, the container runtime and kubelet will use disk space under /var. If the disk partition is not standard, you can set the container runtime and kubelet data directories in example/config.yml before creating the cluster configuration: CONTAINERD_STORAGE_DIR, DOCKER_STORAGE_DIR, KUBELET_ROOT_DIR.
3.3 Deployment Steps¶
3.3.1 Orchestrating K8s Installation on the Deployment Node¶
Log in to the deployment node server.
Navigate to the /etc/kubeasz directory and execute the following commands:
# Install Docker service on the deployment machine.
# Start the local registry.
# Load the image packages required for the offline environment and push them to the registry.
./ezdown -D
./ezdown -X
For more parameters regarding ezdown, run ezdown to view them.
Tip
If it cannot run, navigate to the /etc/kubeasz directory and execute ./ezdown -h to view help.
3.3.2 Creating a Cluster Configuration Instance¶
# Run the kubeasz container
./ezdown -S
# Create a new cluster named 'guancecloud'
# The cluster name can be customized as needed. A corresponding directory will be created.
docker exec -it kubeasz ezctl new guancecloud
# Example output:
2022-10-19 10:48:23 DEBUG generate custom cluster files in /etc/kubeasz/clusters/guancecloud
2022-10-19 10:48:23 DEBUG set version of common plugins
2022-10-19 10:48:23 DEBUG cluster k8s-01: files successfully created.
2022-10-19 10:48:23 INFO next steps 1: to config '/etc/kubeasz/clusters/guancecloud/hosts'
2022-10-19 10:48:23 INFO next steps 2: to config '/etc/kubeasz/clusters/guancecloud/config.yml'
Then modify the cluster configuration files as prompted:
# Modify the hosts file based on the cluster role planning
'/etc/kubeasz/clusters/xxx/hosts'
# Other major cluster-level configuration options can be modified in the config.yml file. [Using defaults is recommended unless you are very familiar with the parameters being modified.]
'/etc/kubeasz/clusters/xxx/config.yml'
Example configuration file contents:
Note
For custom configuration items, refer to the example configuration file.
Example Configuration File
# config.yaml
############################
# prepare
############################
# Optional: offline installation of system software packages (offline|online)
# Default for offline environment: "offline"
INSTALL_SOURCE: "offline"
# Optional: apply system security hardening (github.com/dev-sec/ansible-collection-hardening)
OS_HARDEN: false
############################
# role:deploy
############################
# default: CA will expire in 100 years
# default: certs issued by the CA will expire in 50 years
CA_EXPIRY: "876000h"
CERT_EXPIRY: "438000h"
# kubeconfig configuration parameters
CLUSTER_NAME: "cluster1"
CONTEXT_NAME: "context-{{ CLUSTER_NAME }}"
# k8s version
K8S_VER: "__k8s_ver__"
############################
# role:etcd
############################
# Setting a different WAL directory can avoid disk I/O contention and improve performance.
# It is recommended to change to a directory with more disk space, based on actual conditions.
ETCD_DATA_DIR: "/var/lib/etcd"
ETCD_WAL_DIR: ""
############################
# role:runtime [containerd,docker]
############################
# ------------------------------------------- containerd
# [.]Enable container registry mirroring
ENABLE_MIRROR_REGISTRY: true
# [containerd]Base container image
SANDBOX_IMAGE: "easzlab.io.local:5000/easzlab/pause:__pause__"
# [containerd]Container persistent storage directory
# It is recommended to change to a directory with more disk space, based on actual conditions.
CONTAINERD_STORAGE_DIR: "/var/lib/containerd"
# ------------------------------------------- docker
# [docker]Container storage directory
# It is recommended to change to a directory with more disk space, based on actual conditions.
# Only the deployment machine will have Docker installed.
DOCKER_STORAGE_DIR: "/var/lib/docker"
# [docker]Enable Restful API
ENABLE_REMOTE_API: false
# [docker]Trusted HTTP registry
INSECURE_REG: '["http://easzlab.io.local:5000"]'
############################
# role:kube-master
############################
# k8s cluster master node certificate configuration. You can add multiple IPs and domain names (e.g., public IP and domain).
MASTER_CERT_HOSTS:
- "10.1.1.1"
- "k8s.easzlab.io"
#- "www.test.com"
# Pod CIDR length on worker nodes (determines the maximum number of pod IPs per node).
# If flannel uses the --kube-subnet-mgr parameter, it will read this setting to assign pod CIDRs to each node.
# https://github.com/coreos/flannel/issues/847
NODE_CIDR_LEN: 24
############################
# role:kube-node
############################
# Kubelet root directory
# It is recommended to change to a directory with more disk space, based on actual conditions.
KUBELET_ROOT_DIR: "/var/lib/kubelet"
# Maximum number of pods per node
MAX_PODS: 110
# Configure the amount of resources reserved for kube components (kubelet, kube-proxy, dockerd, etc.)
# See templates/kubelet-config.yaml.j2 for values.
KUBE_RESERVED_ENABLED: "no"
# It is not recommended to enable system-reserved without thorough consideration, unless you have long-term monitoring and understand the system's resource usage.
# As the system runs, you may need to increase resource reservations. See templates/kubelet-config.yaml.j2 for values.
# System reservation settings are based on a 4c/8g VM with minimal system services. For high-performance physical machines, you can increase reservations appropriately.
# Additionally, during cluster installation, resource usage by components like apiserver can be high temporarily. It is recommended to reserve at least 1G of memory.
SYS_RESERVED_ENABLED: "no"
############################
# role:network [flannel,calico,cilium,kube-ovn,kube-router]
############################
# ------------------------------------------- flannel
# [flannel]Set flannel backend: "host-gw", "vxlan", etc.
FLANNEL_BACKEND: "vxlan"
DIRECT_ROUTING: false
# [flannel] flanneld_image: "quay.io/coreos/flannel:v0.10.0-amd64"
flannelVer: "__flannel__"
flanneld_image: "easzlab.io.local:5000/easzlab/flannel:{{ flannelVer }}"
# ------------------------------------------- calico
# [calico]Setting CALICO_IPV4POOL_IPIP="off" can improve network performance. See docs/setup/calico.md for constraints.
CALICO_IPV4POOL_IPIP: "Always"
# [calico]Set the host IP used by calico-node. BGP neighbors establish connections through this IP. Can be specified manually or discovered automatically.
IP_AUTODETECTION_METHOD: "can-reach={{ groups['kube_master'][0] }}"
# [calico]Set calico network backend: brid, vxlan, none
CALICO_NETWORKING_BACKEND: "brid"
# [calico]Set whether calico uses route reflectors.
# If the cluster size exceeds 50 nodes, it is recommended to enable this feature.
CALICO_RR_ENABLED: false
# CALICO_RR_NODES configures the nodes for route reflectors. If not set, master nodes are used by default.
# CALICO_RR_NODES: ["192.168.1.1", "192.168.1.2"]
CALICO_RR_NODES: []
# [calico]Update to support calico versions: [v3.3.x] [v3.4.x] [v3.8.x] [v3.15.x]
calico_ver: "__calico__"
# [calico]calico major version
calico_ver_main: "{{ calico_ver.split('.')[0] }}.{{ calico_ver.split('.')[1] }}"
# ------------------------------------------- cilium
# [cilium]Image version
cilium_ver: "__cilium__"
cilium_connectivity_check: true
cilium_hubble_enabled: false
cilium_hubble_ui_enabled: false
# ------------------------------------------- kube-ovn
# [kube-ovn]Select OVN DB and OVN Control Plane node. Default: first master node.
OVN_DB_NODE: "{{ groups['kube_master'][0] }}"
# [kube-ovn]Offline image tar package
kube_ovn_ver: "__kube_ovn__"
# ------------------------------------------- kube-router
# [kube-router]Public clouds have restrictions; generally, ipinip must be enabled. For private environments, can be set to "subnet".
OVERLAY_TYPE: "full"
# [kube-router]NetworkPolicy support toggle
FIREWALL_ENABLE: true
# [kube-router]kube-router image version
kube_router_ver: "__kube_router__"
busybox_ver: "1.28.4"
############################
# role:cluster-addon
############################
# CoreDNS auto-install
dns_install: "yes"
corednsVer: "__coredns__"
ENABLE_LOCAL_DNS_CACHE: true
dnsNodeCacheVer: "__dns_node_cache__"
# Set local DNS cache address
LOCAL_DNS_CACHE: "169.254.20.10"
# Metrics Server auto-install
metricsserver_install: "yes"
metricsVer: "__metrics__"
# Dashboard auto-install
dashboard_install: "no"
dashboardVer: "__dashboard__"
dashboardMetricsScraperVer: "__dash_metrics__"
# Prometheus auto-install
prom_install: "no"
prom_namespace: "monitor"
prom_chart_ver: "__prom_chart__"
# NFS Provisioner auto-install
# If an existing NFS is available, must be set to "yes" and configure correct server information.
nfs_provisioner_install: "no"
nfs_provisioner_namespace: "kube-system"
nfs_provisioner_ver: "__nfs_provisioner__"
nfs_storage_class: "managed-nfs-storage"
nfs_server: "192.168.1.10"
nfs_path: "/data/nfs"
# network-check auto-install
network_check_enabled: false
network_check_schedule: "*/5 * * * *"
############################
# role:harbor
############################
# harbor version, full version number
HARBOR_VER: "__harbor__"
HARBOR_DOMAIN: "harbor.easzlab.io.local"
HARBOR_TLS_PORT: 8443
# if set 'false', you need to put certs named harbor.pem and harbor-key.pem in directory 'down'
HARBOR_SELF_SIGNED_CERT: true
# install extra component
HARBOR_WITH_NOTARY: false
HARBOR_WITH_TRIVY: false
HARBOR_WITH_CLAIR: false
HARBOR_WITH_CHARTMUSEUM: true
# ingress-nginx related configuration
ingress_nginx_install: "yes"
ingressnginxVer: v1.4.0
certgenVer: v20220916-gd32f8c343
Host Configuration
Host Configuration Example
# 'etcd' cluster should have odd member(s) (1,3,5,...)
# Must replace IPs according to actual planning
[etcd]
192.168.1.1
192.168.1.2
192.168.1.3
# master node(s)
# Must replace IPs according to actual planning
[kube_master]
192.168.1.1
192.168.1.2
# work node(s)
# Must replace IPs according to actual planning
[kube_node]
192.168.1.3
192.168.1.4
# [optional] harbor server, a private docker registry
# 'NEW_INSTALL': 'true' to install a harbor server; 'false' to integrate with existed one
[harbor]
#192.168.1.8 NEW_INSTALL=false
# [optional] loadbalance for accessing k8s from outside
[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] ntp server for the cluster
[chrony]
#192.168.1.1
[all:vars]
# --------- Main Variables ---------------
# Secure port for apiservers
SECURE_PORT="6443"
# Cluster container-runtime supported: docker, containerd
# if k8s version >= 1.24, docker is not supported
CONTAINER_RUNTIME="containerd"
# Network plugins supported: calico, flannel, kube-router, cilium, kube-ovn
# It is recommended to use the default value, or change to "flannel"
CLUSTER_NETWORK="calico"
# Service proxy mode of kube-proxy: 'iptables' or 'ipvs'
PROXY_MODE="ipvs"
# K8S Service CIDR, not overlap with node(host) networking
# Must not conflict with host IP range
SERVICE_CIDR="10.68.0.0/16"
# Cluster CIDR (Pod CIDR), not overlap with node(host) networking
# Must not conflict with host IP range
CLUSTER_CIDR="172.20.0.0/16"
# NodePort Range
NODE_PORT_RANGE="30000-32767"
# Cluster DNS Domain
CLUSTER_DNS_DOMAIN="cluster.local"
# -------- Additional Variables (don't change the default value right now) ---
# Binaries Directory
bin_dir="/opt/kube/bin"
# Deploy Directory (kubeasz workspace)
base_dir="/etc/kubeasz"
# Directory for a specific cluster
cluster_dir="{{ base_dir }}/clusters/_cluster_name_"
# CA and other components cert/key Directory
ca_dir="/etc/kubernetes/ssl"
3.3.3 One-Click Deployment¶
After confirming the above operations are correct, execute the following commands for quick deployment:
Tip
# One-click installation command, equivalent to executing: docker exec -it kubeasz ezctl setup xxx all
# xxx represents the name of the created cluster
dk ezctl setup guancecloud all
# Or step-by-step installation. Use `dk ezctl help setup` to view step-by-step installation help.
# dk ezctl setup guancecloud 01
# dk ezctl setup guancecloud 02
# dk ezctl setup guancecloud 03
# dk ezctl setup guancecloud 04
# After the command completes, the tasks should not have any errors.
TASK [cluster-addon : 准备 DNS的部署文件] *********************************************
changed: [10.200.14.144]
TASK [cluster-addon : 创建coredns部署] *********************************************
changed: [10.200.14.144]
TASK [cluster-addon : 准备dnscache的部署文件] *****************************************
changed: [10.200.14.144]
TASK [cluster-addon : 创建dnscache部署] ********************************************
changed: [10.200.14.144]
TASK [cluster-addon : 准备 metrics-server的部署文件] **********************************
changed: [10.200.14.144]
TASK [cluster-addon : 创建 metrics-server部署] *************************************
changed: [10.200.14.144]
TASK [cluster-addon : 准备 nfs-provisioner 配置目录] *********************************
changed: [10.200.14.144]
TASK [cluster-addon : 准备 nfs-provisioner部署文件] **********************************
changed: [10.200.14.144] => (item=nfs-provisioner.yaml)
changed: [10.200.14.144] => (item=test-pod.yaml)
TASK [cluster-addon : 创建 nfs-provisioner部署] ************************************
changed: [10.200.14.144]
TASK [cluster-addon : 准备 openebs-provisioner 配置目录] *****************************
changed: [10.200.14.144]
TASK [cluster-addon : 准备 openebs-provisioner 部署文件] *****************************
changed: [10.200.14.144] => (item=openebs-provisioner.yaml)
TASK [cluster-addon : 创建 openebs-provisioner 部署] *******************************
changed: [10.200.14.144]
TASK [cluster-addon : 准备 ingress-nginx 配置目录] ***********************************
changed: [10.200.14.144]
TASK [cluster-addon : 准备 ingress-nginx 部署文件] ***********************************
changed: [10.200.14.144] => (item=ingress-nginx.yaml)
TASK [cluster-addon : 创建 ingress-nginx 部署] *************************************
changed: [10.200.14.144]
PLAY RECAP *********************************************************************
10.200.14.144 : ok=110 changed=99 unreachable=0 failed=0 skipped=172 rescued=0 ignored=0
10.200.14.145 : ok=117 changed=106 unreachable=0 failed=0 skipped=199 rescued=0 ignored=0
10.200.14.146 : ok=93 changed=83 unreachable=0 failed=0 skipped=148 rescued=0 ignored=0
localhost : ok=33 changed=30 unreachable=0 failed=0 skipped=11 rescued=0 ignored=0
Important
-
All returned information must show success. Otherwise, reset the system and reinstall.
-
To clean up the cluster:
docker exec -it kubeasz ezctl destroy xxx, where xxx is the cluster name. -
Reboot the nodes to ensure residual virtual network interfaces, routes, etc., are cleared.
Example of Successful Output
PLAY RECAP *********************************************************************
10.200.14.144 : ok=110 changed=99 unreachable=0 failed=0 skipped=172 rescued=0 ignored=0
10.200.14.145 : ok=117 changed=106 unreachable=0 failed=0 skipped=199 rescued=0 ignored=0
10.200.14.146 : ok=93 changed=83 unreachable=0 failed=0 skipped=148 rescued=0 ignored=0
localhost : ok=33 changed=30 unreachable=0 failed=0 skipped=11 rescued=0 ignored=0
For more parameters regarding ezctl, run ezctl to view them. If it cannot run, navigate to the /etc/kubeasz directory and execute ./ezctl to view help.
4. Verifying the Installation¶
4.1 Cluster Component Status¶
Cluster Components
Confirm that all returned results have no ERROR.
4.2 Cluster Node Status¶
Cluster Nodes
Confirm that all node statuses are Ready.
4.3 Default Cluster Pod Status¶
Initial Cluster Pods
[root@k8s-node01 ~]# kubectl get pods -A
NAMESPACE NAME READY STATUS RESTARTS AGE
ingress-nginx ingress-nginx-admission-create-sh5gb 0/1 Completed 0 22h
ingress-nginx ingress-nginx-admission-patch-dhsvl 0/1 Completed 0 22h
ingress-nginx ingress-nginx-controller-6d799ccc9c-rhgx5 1/1 Running 0 22h
kube-system calico-kube-controllers-5c8bb696bb-srlmd 1/1 Running 0 22h
kube-system calico-node-4rwfj 1/1 Running 0 22h
kube-system calico-node-lcm44 1/1 Running 0 22h
kube-system calico-node-nbc5w 1/1 Running 0 22h
kube-system calico-node-qfnw2 1/1 Running 0 22h
kube-system coredns-84b58f6b4-zgkvb 1/1 Running 0 22h
kube-system kubernetes-dashboard-5fc74cf5c6-kcpc7 1/1 Running 0 22h
kube-system metrics-server-69797698d4-nqfqf 1/1 Running 0 22h
kube-system node-local-dns-7w2kt 1/1 Running 0 22h
kube-system node-local-dns-gb4zp 1/1 Running 0 22h
kube-system node-local-dns-mw9pt 1/1 Running 0 22h
kube-system node-local-dns-zr5d9 1/1 Running 0 22h
Confirm that all pod statuses are Running and READY is 1/1.
4.4 Verify Cluster Info¶
Cluster Information
[root@k8s-node01 ~]# kubectl cluster-info
Kubernetes control plane is running at https://127.0.0.1:6443
CoreDNS is running at https://127.0.0.1:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
KubeDNSUpstream is running at https://127.0.0.1:6443/api/v1/namespaces/kube-system/services/kube-dns-upstream:dns/proxy
kubernetes-dashboard is running at https://127.0.0.1:6443/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
4.5 Verify Cluster Resource Usage¶
Cluster Resource Usage
Confirm that cluster resource usage is returned successfully.
5. Common Issues¶
Tips
During the verification phase, if you encounter kubectl: command not found, log out and re-SSH into the server. The environment variables should take effect.
If the helm command is not found, log out and re-SSH into the server, check the environment variables, and execute the helm command to verify.