Kubenetes install
Deployment Tools
Docker Desktop
Including a local Kubernetes cluster for Docker users. Enable kubenetes in settings
curl.exe -LO "https://dl.k8s.io/release/v1.29.2/bin/windows/amd64/kubectl.exe"
& add path to envkubectl config current-context
// view current kubenetes cluster
Minikube
Single- and multi-node local Kubernetes cluster, recommended for a learning environment deployed on a single host.
minikube start -p minikube
minikube status
minikube version
minikube stop
minikube profile list
minikube node list -p minikube
minikube delete -p minikube
minikube addons list
minikube addons enable ingress
## customize the VM isolation driver, container runtime, profile name
minikube start --kubernetes-version=v1.23.3 \
--driver=podman --profile minipod
minikube start --nodes=2 --kubernetes-version=v1.24.4 \
--driver=docker --profile doubledocker
minikube start --driver=virtualbox --nodes=3 --disk-size=10g \
--cpus=2 --memory=4g --kubernetes-version=v1.25.1 --cni=calico \
--container-runtime=cri-o -p multivbox
minikube start --driver=docker --cpus=6 --memory=8g \
--kubernetes-version="1.24.4" -p largedock
minikube start --driver=virtualbox -n 3 --container-runtime=containerd \
--cni=calico -p minibox
## Completion is a helpful post installation configuration to enable the minikube command to respond to typical auto-completion mechanisms
sudo apt install bash-completion
source /etc/bash_completion
source <(minikube completion bash)
# If needed, also run the following command:s
minikube completion bash
linux install
Creating a Kubernetes (K8s) cluster with two computers involves several steps. Below is a general procedure to set up a basic Kubernetes cluster using two nodes. In this example, we’ll refer to the two computers as Node1 and Node2.
Prerequisites:
- Two computers with a compatible Linux distribution (e.g., Ubuntu, CentOS) installed.
- Docker installed on both computers.
- Swap disabled on both computers.
Procedure:
-
Install kubectl: Install
kubectl
on both Node1 and Node2. Kubectl is the command-line tool for interacting with a Kubernetes cluster.# On Ubuntu sudo apt-get update && sudo apt-get install -y kubectl # On CentOS sudo yum install -y kubectl
-
Install kubeadm, kubelet, and kubectl: Install Kubernetes components on both Node1 and Node2.
# On both nodes sudo apt-get update && sudo apt-get install -y apt-transport-https curl sudo curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add - sudo echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list sudo apt-get update sudo apt-get install -y kubelet kubeadm kubectl sudo apt-mark hold kubelet kubeadm kubectl # Avoid automatic updates
-
Initialize the master node (Node1): On Node1, run the following command to initialize the Kubernetes master.
sudo kubeadm init --pod-network-cidr=192.168.0.0/16
After the initialization is complete, follow the on-screen instructions to copy the
kubeadm join
command. -
Configure kubectl on the master node: On Node1, set up the kubeconfig file for
kubectl
.mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config
-
Install a network plugin: Choose a network plugin that suits your needs. In this example, we’ll use Calico.
kubectl apply -f https://docs.projectcalico.org/v3.18/manifests/calico.yaml
-
Join the worker node (Node2) to the cluster: On Node2, run the
kubeadm join
command obtained from the master node initialization step.sudo kubeadm join <master-node-ip>:<master-node-port> --token <token> --discovery-token-ca-cert-hash sha256:<hash>
Replace
<master-node-ip>
,<master-node-port>
,<token>
, and<hash>
with the values specific to your setup. -
Verify the cluster: On Node1, run the following command to verify that both nodes are part of the cluster.
kubectl get nodes
Both nodes should be in the
Ready
state.
Congratulations! You now have a basic Kubernetes cluster with two computers. Keep in mind that this is a simplified setup, and in a production environment, you may need to consider additional configurations and security measures.
Build a kubenetes cluster
# master 1 VM, slave 1 VM, slave 2 VM
# turn off swap
sudo swapoff -a
# edit /etc/fstab comment out swap line
sudo vim /etc/fstab
# install docker
sudo apt install docker.io -y
sudo apt install apt-transport-https curl -y
# add repository key
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add
sudo apt-add-repository "deb http://apt.kubernetes.io/ kubernetes-xenial main"
sudo apt update
sudo apt install kubeadm kubelet kubectl kubenetes-cni -y
# exec following line only on master node
# there will be `kubeadmin join link after command finishes`, copy and paste
# to the other slave VM
sudo kubeadm init
# on slate VM, execute
kubeadm join <ip:port> --token <string> --discovery-token-ca-cert-hash sha:256:<string>
# on master 1
kubectl get nodes
# The connection to the server localhost:8080 was refused - did you specify the right host or port?
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
kubectl get nodes
# NAME STATUS ROLES AGE VERSION
# master NotReady control-plane 9m21s v1.24.3
# slave1 NotReady <none> 2m1s v1.24.3
# slave2 NotReady <none> 114s v1.24.3
# deploy network config
kubectl apply -f https://docs.projectcalico.org/mainifests/calico.yaml
# NAME STATUS ROLES AGE VERSION
# master Ready control-plane 22m v1.24.3
# slave1 Ready <none> 14m v1.24.3
# slave2 Ready <none> 14m v1.24.3
## ingress-nginx
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.10.0/deploy/static/provider/cloud/deploy.yaml
kubectl -n ingress-nginx get pod -o yaml
kubectl get service ingress-nginx-controller --namespace=ingress-nginx
## https://kubernetes.github.io/ingress-nginx/deploy/