-
Clone the kubespray repo
git clone https://github.com/kubernetes-sigs/kubespray cd kubespray -
(optional) Install pip if not yet installed
sudo apt install python3-pip -
Install required components
sudo pip install -r requirements.txt
In case of error error: externally-managed-environment use pip's argument --break-system-packages:
sudo pip install --break-system-packages -r requirements.txt
-
Copy example and create new inventory for Ansible
cp -rfp inventory/sample inventory/mycluster -
Declare your nodes IP addresses
declare -a IPS=(192.168.10.81 192.168.10.82 192.168.10.83) -
Prepare inventory
CONFIG_FILE=inventory/mycluster/hosts.yaml python3 contrib/inventory_builder/inventory.py ${IPS[@]} -
(optional) if an error
No module named 'ruamel'occured, install missing package and try again to create the inventory.pip3 install ruamel.yamlor add argument
--break-system-packagesor you can use directlyaptto install the package:sudo apt install python3-ruamel.yaml -
Edit file
inventory/mycluster/group_vars/k8s_cluster/k8s-cluster.ymlwhere in line 70 (kube_network_plugin) changecalicotocilium(here description about network addons compatibility and why we change Calico to another plugin) -
Edit file
inventory/mycluster/hosts.yamlwhere line 19 should be commented, because we do not want to have 2 master nodes.# node2 -
Run the Ansible playbook to create the cluster
ansible-playbook -K -i inventory/mycluster/hosts.yaml --become --become-user=root cluster.ymlArgument
-Kallows you to input the password -
(optional) if something goes wrong you can reset your installation:
ansible-playbook -K -i inventory/mycluster/hosts.yaml --become --become-user=root reset.yml -
Copy kube config to local machine. File location is
<MasterNodeIpAddress>:/root/.kube/config -
Edit this file and in line 5 replace IP address with IP of your master node (node1).
-
Copy kube config to default location
~/.kube/config(folder may not yet exist) or set env variableKUBECONFIGwith file location:export KUBECONFIG=~/config -
(optional) install kubectl
https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
kubectl version --client
-
Now you should be able to run command on your k8s cluster. For example:
kubectl get node
kubectl run hostinfo --image=finconreply/hostinfo
kubectl expose pod hostinfo --port 8080 --target-port 8080
kubectl create deployment hostinfo --image=finconreply/hostinfo --replicas 3
kubectl expose deployment hostinfo --port 8080 --target-port 8080
kubectl port-forward svc/hostinfo 38000:8080
kubectl delete service hostinfo
kubectl delete deployment hostinfokubectl create -f deployment.yaml
kubectl create -f service.yaml
kubectl port-forward svc/hostinfo 38000:8080
kubectl delete -f service.yaml
kubectl delete -f deployment.yaml