Install Kubernetes Cluster Using Kubespray
Ansible Node (Kubespray Node): Minimal installed Ubuntu 22.04 LTS (192.168.139.149)
1 Controller Node: Minimal Installed Rocky Linux 9 (192.168.139.160)
2 Worker Nodes: Minimal Installed Rocky Linux 9 (192.168.139.161/162)
?
Minimum system requirements for kubespray
Master Node: 2 GB RAM, 2 CPU and 20 GB free disk space
Worker Nodes: 2 GB RAM, 2 CPU, 20 GB free disk space
Ansible Node: 2 GB RAM, 1CPU and 20 GB disk space
Internet connectivity on each node
Regular with sudo admin rights
Step 1) Configure Kubespray Node
Login to your Ubuntu 22.04 system and install ansible:
# apt update -y
# apt install git python3 python3-pip -y
# cd kubespray
# pip install -r requirements.txt
# ansible --version
Create the hosts inventory, run below commands and don’t forget to replace IP address that suits to your deployment:
# cp -rfp inventory/sample inventory/mycluster
# declare -a IPS=(192.168.139.160 192.168.139.161 192.168.139.162)
# CONFIG_FILE=inventory/mycluster/hosts.yaml python3 contrib/inventory_builder/inventory.py ${IPS[@]}
?
Modify the inventory file, set control node and 2 worker nodes:
# vi inventory/mycluster/hosts.yaml
?
Review and modify the following parameters in file “inventory/mycluster/group_vars/k8s_cluster/k8s-cluster.yml”
领英推荐
To enable addons like?kuberenetes dashboard?and?ingress controller, set the parameters as enabled in the file “inventory/mycluster/group_vars/k8s_cluster/addons.yml”
dashboard_enabled: true
ingress_nginx_enabled: true
ingress_nginx_host_network: true
?
Step 2) Copy SSH-keys from ansible node to all other nodes
# ssh-keygen
# ssh-copy-id [email protected]
# ssh-copy-id [email protected]
# ssh-copy-id [email protected]
?
Step 3) Disable Firewall and Enable IPV4 forwarding
# cd kubespray
# ansible all -i inventory/mycluster/hosts.yaml -m shell -a "sudo systemctl stop firewalld && sudo systemctl disable firewalld"
Run following ansible commands to enable IPv4 forwarding and disable swap on all the nodes:
# ansible all -i inventory/mycluster/hosts.yaml -m shell -a "echo 'net.ipv4.ip_forward=1' | sudo tee -a /etc/sysctl.conf"
# ansible all -i inventory/mycluster/hosts.yaml -m shell -a "sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab && sudo swapoff -a"
?
Step 4) Start Kubernetes deployment
Now, we are all set to start Kubernetes cluster deployment, run following ansible playbook from ansible node:
# cd kubespray
# ansible-playbook -i inventory/mycluster/hosts.yaml --become --become-user=root cluster.yml
Now monitor the deployment, it may take 20 to 30 minutes depending on internet speed and hardware resources.
Step 5) Access Kubernetes cluster
Login to master node, switch to root user, run kubectl commands from there:
# kubectl get nodes
# kubectl get pods -A
?
?
?
?
?
?
DevOps Junior’s
5 个月Good Job ??
DevOps Engineer @Kapital Bank | CKA, RHCSA, LPI
9 个月?ox sa?ol Ali Huseynov ! ?nan?ram ki k8s ?yr?nm?k v? CKA almaq h?v?sind? olan insanlara b?yük d?st?k olacaq .
Operations Expert at KAtech CJSC
9 个月https://youtu.be/gXJBqQdtPOU