Kubernetes: Difference between revisions

From Chorke Wiki
Jump to navigation Jump to search
No edit summary
 
(40 intermediate revisions by the same user not shown)
Line 38: Line 38:
==Install==
==Install==
===Minikube===
===Minikube===
<source lang="powershell">
<syntaxhighlight lang="powershell">
Get-ComputerInfo OsName,OsVersion,OsBuildNumber
Get-ComputerInfo OsName,OsVersion,OsBuildNumber
choco install docker-desktop -y
choco install docker-desktop -y
Line 50: Line 50:
minikube start --v=7
minikube start --v=7
kubectl get nodes
kubectl get nodes
</source>
</syntaxhighlight>


===Kind===
===Kind===
<source lang="powershell">
<syntaxhighlight lang="powershell">
choco install kubernetes-cli -y
choco install kubernetes-cli -y
choco install kind -y
choco install kind -y
Line 63: Line 63:
# kind delete cluster --name k8s-ns12-pc04
# kind delete cluster --name k8s-ns12-pc04
kubectl cluster-info --context kind-k8s-ns12-pc04
kubectl cluster-info --context kind-k8s-ns12-pc04
</source>
</syntaxhighlight>


<source lang="properties">
<syntaxhighlight lang="properties">
cat <<EOF > kind-config.yaml
cat <<EOF > kind-config.yaml
kind: Cluster
kind: Cluster
Line 74: Line 74:
- role: worker
- role: worker
EOF
EOF
</source>
</syntaxhighlight>


===K3s===
===K3s===
<source lang="powershell">
<syntaxhighlight lang="powershell">
choco install multipass -y
choco install multipass -y
multipass launch -n node1
multipass launch -n node1
Line 94: Line 94:
multipass exec node1 -- bash -c "curl -sfL https://get.k3s.io | sh -"
multipass exec node1 -- bash -c "curl -sfL https://get.k3s.io | sh -"
multipass exec node1 -- sudo kubectl get nodes
multipass exec node1 -- sudo kubectl get nodes
</source>
</syntaxhighlight>
 
==Ubuntu==
 
sudo apt remove docker docker-engine docker.io containerd runc
sudo apt install ca-certificates curl gnupg lsb-release
 
<syntaxhighlight lang="json">
sudo su
cat << \EOF >> /etc/docker/daemon.json
{
    "exec-opts": [
        "native.cgroupdriver=systemd"
    ],
    "log-driver": "json-file",
    "log-opts": {
        "max-size": "100m"
    },
    "storage-driver": "overlay2"
}
EOF
exit
</syntaxhighlight>
 
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
 
curl    https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
cat << EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/ kubernetes-xenial main
EOF
 
sudo apt update && sudo apt install -y apt-transport-https curl
sudo apt install -y docker-ce=5:20.10.16~3-0~ubuntu-focal\
  kubelet=1.24.0-00 kubeadm=1.24.0-00 kubectl=1.24.0-00
sudo apt-mark hold docker-ce kubelet kubeadm kubectl
sudo apt install docker-compose
 
echo "net.bridge.bridge-nf-call-iptables=1" |\
  sudo tee -a /etc/sysctl.conf
sudo sysctl --system
sudo sysctl -p
 
sudo kubeadm init --pod-network-cidr=10.21.0.0/16
 
'''docker config'''
sudo usermod -aG docker $USER
newgrp docker
mkdir -p $HOME/.docker
sudo chown $(id -u):$(id -g) $HOME/.docker -R
sudo chmod g+rwx $HOME/.docker -R
 
'''kube config'''
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
 
'''network overlay'''
kubectl apply -f\
  https://docs.projectcalico.org/v3.14/manifests/calico.yaml
 
'''join worker nodes'''
kubeadm token create --print-join-command
kubectl get nodes
 
'''evil most things for docker0 bridge'''
sudo apt remove netscript-2.4
sudo apt purge netscript-2.4
sudo apt autoremove
 
==Minikube==
<syntaxhighlight lang="bash">
sudo mkdir -p /opt/cli/minikube-linux-amd64/bin
curl -sLO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /opt/cli/minikube-linux-amd64/bin/minikube
sudo update-alternatives --install /usr/local/bin/minikube minikube\
/opt/cli/minikube-linux-amd64/bin/minikube 1980
rm -rf minikube-linux-amd64
</syntaxhighlight>
 
<syntaxhighlight lang="bash">
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
cat << EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/ kubernetes-xenial main
EOF
sudo apt install kubectl
</syntaxhighlight>
 
<syntaxhighlight lang="bash">
minikube start
:'
😄  minikube v1.25.2 on Ubuntu 22.04
✨  Automatically selected the docker driver. Other choices: none, ssh
👍  Starting control plane node minikube in cluster minikube
🚜  Pulling base image ...
💾  Downloading Kubernetes v1.23.3 preload ...
    > preloaded-images-k8s-v17-v1...: 505.68 MiB / 505.68 MiB  100.00% 4.60 MiB
    > gcr.io/k8s-minikube/kicbase: 379.06 MiB / 379.06 MiB  100.00% 2.47 MiB p/
🔥  Creating docker container (CPUs=2, Memory=6900MB) ...
🐳  Preparing Kubernetes v1.23.3 on Docker 20.10.12 ...
    ▪ kubelet.housekeeping-interval=5m
    ▪ Generating certificates and keys ...
    ▪ Booting up control plane ...
    ▪ Configuring RBAC rules ...
🔎  Verifying Kubernetes components...
    ▪ Using image gcr.io/k8s-minikube/storage-provisioner:v5
🌟  Enabled addons: storage-provisioner, default-storageclass
🏄  Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default
'
</syntaxhighlight>
 
<syntaxhighlight lang="bash">
kubectl get po -A
minikube kubectl -- get po -A
:'
NAMESPACE    NAME                              READY  STATUS    RESTARTS        AGE
kube-system  coredns-64897985d-thxhw            1/1    Running  0              8m14s
kube-system  etcd-minikube                      1/1    Running  0              8m26s
kube-system  kube-apiserver-minikube            1/1    Running  0              8m26s
kube-system  kube-controller-manager-minikube  1/1    Running  0              8m26s
kube-system  kube-proxy-xqfl2                  1/1    Running  0              8m13s
kube-system  kube-scheduler-minikube            1/1    Running  0              8m26s
kube-system  storage-provisioner                1/1    Running  1 (7m43s ago)  8m25s
'
</syntaxhighlight>


==Knowledge==
==Knowledge==
<source lang="powershell">
cat /proc/cgroups
sudo apt install upx-ucl
dpkg --print-architecture
 
apt-cache madison kubelet
apt-cache madison kubeadm
apt-cache madison kubectl
apt-cache madison docker-ce
 
journalctl -fu docker
journalctl -u kubelet
sudo rm -rf /root/.kube
rm -rf /home/${USER}/.kube
sudo rm -rf /etc/kubernetes
sudo rm -rf /var/lib/kubelet
sudo rm /etc/containerd/config.toml
 
sudo systemctl daemon-reload
systemctl restart containerd
sudo systemctl restart docker
sudo systemctl enable  docker
 
<syntaxhighlight lang="bash">
# sudo ifup docker0
# sudo ifdown docker0
# sudo apt install netscript
# sudo apt install cgroup-tools
sudo systemctl restart NetworkManager
sudo systemctl restart systemd-resolved
</syntaxhighlight>
 
sudo systemctl daemon-reload
sudo kubeadm reset --ignore-preflight-errors --v=5
 
sudo apt purge docker-ce kubelet kubeadm kubectl
sudo apt autoremove docker-ce kubelet kubeadm kubectl
sudo apt-mark unhold docker-ce kubelet kubeadm kubectl
 
<syntaxhighlight lang="powershell">
choco -v
choco -v
wsl -l -v
wsl -l -v
Line 103: Line 267:
Restart-Service LxssManager
Restart-Service LxssManager
Get-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V
Get-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V
</source>
Disable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V
#Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All
</syntaxhighlight>


<source lang="bash">
<syntaxhighlight lang="bash">
apt install -y conntrack
apt install -y conntrack
apt install -yqq daemonize dbus-user-session fontconfig
apt install -yqq daemonize dbus-user-session fontconfig
</source>
</syntaxhighlight>


<source lang="bash">
<syntaxhighlight lang="bash">
docker --help
docker --help
docker version
docker version
Line 128: Line 294:
kubectl patch node $NODENAME -p '{"metadata":{"finalizers":[]}}' --type=merge
kubectl patch node $NODENAME -p '{"metadata":{"finalizers":[]}}' --type=merge
kubectl -n kubernetes-dashboard describe secret $(kubectl -n kubernetes-dashboard get secret | grep admin-user | awk '{print $1}')
kubectl -n kubernetes-dashboard describe secret $(kubectl -n kubernetes-dashboard get secret | grep admin-user | awk '{print $1}')
</source>
</syntaxhighlight>


==References==
==References==
{|
| valign="top" |
* [https://learnk8s.io/installing-docker-kubernetes-windows Getting started Kubernetes on Windows]
* [https://learnk8s.io/installing-docker-kubernetes-windows Getting started Kubernetes on Windows]
* [https://kubernetes.io/blog/2020/05/21/wsl-docker-kubernetes-on-the-windows-desktop/ Kubernetes on the Windows Desktop]
* [https://kubernetes.io/blog/2020/05/21/wsl-docker-kubernetes-on-the-windows-desktop/ Kubernetes on the Windows Desktop]
* [https://kubernetes.io/docs/tasks/tools/install-kubectl-windows/ Install <code>kubectl</code> on Windows]
* [https://github.com/k3s-io/k3s K3s Lightweight Kubernetes]
* [https://github.com/k3s-io/k3s K3s Lightweight Kubernetes]
* [https://kubernetes.io/docs/tasks/tools/install-kubectl/ Install and Set Up kubectl]
* [https://kubernetes.io/docs/tasks/tools/install-kubectl/ Install and Set Up kubectl]
* [https://kubernetes.io/docs/tutorials/kubernetes-basics/ Learn Kubernetes Basics]
* [https://kubernetes.io/docs/tutorials/kubernetes-basics/ Learn Kubernetes Basics]
* [https://brennerm.github.io/posts/minikube-vs-kind-vs-k3s.html Minikube vs. kind vs. k3s]
* [https://www.docker.com/blog/what-is-containerd-runtime/ What is <code>containerd</code>]
* [https://minikube.sigs.k8s.io/docs/start/ MiniKube start]
* [https://minikube.sigs.k8s.io/docs/start/ MiniKube start]
* [https://kubernetes.io/docs/concepts/overview/what-is-kubernetes/ Kubernetes]
* [https://kubernetes.io/docs/concepts/overview/what-is-kubernetes/ Kubernetes]
| valign="top" |
* [https://kubernetes.io/docs/tasks/access-application-cluster/web-ui-dashboard/ Deploy the Kubernetes Dashboard]
* [https://stackoverflow.com/questions/44698283/ Completely uninstall Kubernetes]
* [https://adamtheautomator.com/kubernetes-dashboard/ Set Up Kubernetes Dashboard]
* [https://docs.chocolatey.org/en-us/choco/commands/uninstall Chocolatey Uninstall Package]
* [https://community.chocolatey.org/packages/minikube Chocolatey Install Minikube]
* [https://community.chocolatey.org/packages/vagrant Chocolatey Install Vagrant]
* [https://stackoverflow.com/questions/40082608/ Delete interface <code>docker0</code>]
* [https://community.chocolatey.org/packages/k3sup Chocolatey Install K3sup]
* [https://community.chocolatey.org/packages/kind Chocolatey Install Kind]
* [https://community.chocolatey.org/packages/k3d Chocolatey Install K3d]
| valign="top" |
* [https://stackoverflow.com/questions/66016567/ Uninstall Minikube from Ubuntu]
* [https://kubernetes.io/docs/tutorials/stateless-application/ K8s Stateless Applications]
* [https://kubernetes.io/docs/tutorials/stateful-application/ K8s Stateful Applications]
* [[K8s/CSI Hostpath Driver|K8s » CSI Hostpath Driver]]
* [https://kubernetes.io/docs/home/ Kubernetes Documents]
* [https://ubuntu.com/tutorials/how-to-kubernetes-cluster-on-raspberry-pi#4-installing-microk8s Installing MicroK8s]
* [[Minikube]]
* [[Kubectl]]
* [[Helm]]
* [[K8s]]
|}

Latest revision as of 09:04, 1 August 2024

Preferred Kubernetes environments are Minikube, Kind and K3s. It's depends on your use case.

  1. Minikube: Getting started with Fully Kubernetes environment
  2. Kind: Kubernetes environment for clusters and more than a single node
  3. K3s: Kubernetes environment for a low spec machine that uses fewer resources
Nature Minikube Kind K3s
Runtimes VM Container Native
CPU Architectures AMD64 AMD64 AMD64, ARMv7, ARM64
Container Runtimes Docker, CRI-O, containerd, gvisor Docker Docker, containerd
Startup Time 5:19 / 3:15 2:48 / 1:06 0:15 / 0:15
Memory 2GB 8GB (Windows, MacOS) 512 MB
Root Access Required
Multi-Cluster
Multi-Node
Project Home Minikube Kind K3s

Install

Minikube

Get-ComputerInfo OsName,OsVersion,OsBuildNumber
choco install docker-desktop -y
choco install minikube -y

# minikube start --driver=hyperv
# minikube start --driver=none
minikube start

minikube delete
minikube start --v=7
kubectl get nodes

Kind

choco install kubernetes-cli -y
choco install kind -y

# kind create cluster
# kind delete cluster

kind create cluster --name k8s-ns12-pc04
# kind delete cluster --name k8s-ns12-pc04
kubectl cluster-info --context kind-k8s-ns12-pc04
cat <<EOF > kind-config.yaml
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: worker
- role: worker
EOF

K3s

choco install multipass -y
multipass launch -n node1
multipass list

multipass set local.driver=hyperv
multipass set local.driver=virtualbox

Get-NetConnectionProfile
Set-NetConnectionProfile -InterfaceIndex 13 -NetworkCategory Private

multipass list
cat C:\Windows\System32\drivers\etc\hosts.ics

multipass delete --purge --all
multipass exec node1 -- bash -c "curl -sfL https://get.k3s.io | sh -"
multipass exec node1 -- sudo kubectl get nodes

Ubuntu

sudo apt remove docker docker-engine docker.io containerd runc
sudo apt install ca-certificates curl gnupg lsb-release
sudo su
cat << \EOF >> /etc/docker/daemon.json
{
    "exec-opts": [
        "native.cgroupdriver=systemd"
    ],
    "log-driver": "json-file",
    "log-opts": {
        "max-size": "100m"
    },
    "storage-driver": "overlay2"
}
EOF
exit
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
curl    https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
cat << EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/ kubernetes-xenial main
EOF
sudo apt update && sudo apt install -y apt-transport-https curl
sudo apt install -y docker-ce=5:20.10.16~3-0~ubuntu-focal\
 kubelet=1.24.0-00 kubeadm=1.24.0-00 kubectl=1.24.0-00
sudo apt-mark hold docker-ce kubelet kubeadm kubectl
sudo apt install docker-compose
echo "net.bridge.bridge-nf-call-iptables=1" |\
 sudo tee -a /etc/sysctl.conf
sudo sysctl --system
sudo sysctl -p
sudo kubeadm init --pod-network-cidr=10.21.0.0/16
docker config
sudo usermod -aG docker $USER
newgrp docker

mkdir -p $HOME/.docker
sudo chown $(id -u):$(id -g) $HOME/.docker -R
sudo chmod g+rwx $HOME/.docker -R
kube config
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
network overlay
kubectl apply -f\
 https://docs.projectcalico.org/v3.14/manifests/calico.yaml
join worker nodes
kubeadm token create --print-join-command
kubectl get nodes
evil most things for docker0 bridge
sudo apt remove netscript-2.4
sudo apt purge netscript-2.4
sudo apt autoremove

Minikube

sudo mkdir -p /opt/cli/minikube-linux-amd64/bin
curl -sLO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /opt/cli/minikube-linux-amd64/bin/minikube
sudo update-alternatives --install /usr/local/bin/minikube minikube\
 /opt/cli/minikube-linux-amd64/bin/minikube 1980
rm -rf minikube-linux-amd64
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
cat << EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/ kubernetes-xenial main
EOF
sudo apt install kubectl
minikube start
:'
😄  minikube v1.25.2 on Ubuntu 22.04
✨  Automatically selected the docker driver. Other choices: none, ssh
👍  Starting control plane node minikube in cluster minikube
🚜  Pulling base image ...
💾  Downloading Kubernetes v1.23.3 preload ...
    > preloaded-images-k8s-v17-v1...: 505.68 MiB / 505.68 MiB  100.00% 4.60 MiB
    > gcr.io/k8s-minikube/kicbase: 379.06 MiB / 379.06 MiB  100.00% 2.47 MiB p/
🔥  Creating docker container (CPUs=2, Memory=6900MB) ...
🐳  Preparing Kubernetes v1.23.3 on Docker 20.10.12 ...
    ▪ kubelet.housekeeping-interval=5m
    ▪ Generating certificates and keys ...
    ▪ Booting up control plane ...
    ▪ Configuring RBAC rules ...
🔎  Verifying Kubernetes components...
    ▪ Using image gcr.io/k8s-minikube/storage-provisioner:v5
🌟  Enabled addons: storage-provisioner, default-storageclass
🏄  Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default
'
kubectl get po -A
minikube kubectl -- get po -A
:'
NAMESPACE     NAME                               READY   STATUS    RESTARTS        AGE
kube-system   coredns-64897985d-thxhw            1/1     Running   0               8m14s
kube-system   etcd-minikube                      1/1     Running   0               8m26s
kube-system   kube-apiserver-minikube            1/1     Running   0               8m26s
kube-system   kube-controller-manager-minikube   1/1     Running   0               8m26s
kube-system   kube-proxy-xqfl2                   1/1     Running   0               8m13s
kube-system   kube-scheduler-minikube            1/1     Running   0               8m26s
kube-system   storage-provisioner                1/1     Running   1 (7m43s ago)   8m25s
'

Knowledge

cat /proc/cgroups
sudo apt install upx-ucl
dpkg --print-architecture
apt-cache madison kubelet
apt-cache madison kubeadm
apt-cache madison kubectl
apt-cache madison docker-ce
journalctl -fu docker
journalctl -u kubelet
sudo rm -rf /root/.kube
rm -rf /home/${USER}/.kube
sudo rm -rf /etc/kubernetes
sudo rm -rf /var/lib/kubelet
sudo rm /etc/containerd/config.toml
sudo systemctl daemon-reload 
systemctl restart containerd
sudo systemctl restart docker
sudo systemctl enable  docker
# sudo ifup docker0
# sudo ifdown docker0
# sudo apt install netscript
# sudo apt install cgroup-tools
sudo systemctl restart NetworkManager
sudo systemctl restart systemd-resolved
sudo systemctl daemon-reload
sudo kubeadm reset --ignore-preflight-errors --v=5
sudo apt purge docker-ce kubelet kubeadm kubectl
sudo apt autoremove docker-ce kubelet kubeadm kubectl
sudo apt-mark unhold docker-ce kubelet kubeadm kubectl
choco -v
wsl -l -v
wsl --list --verbose
Restart-Service LxssManager
Get-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V
Disable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V
#Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All
apt install -y conntrack
apt install -yqq daemonize dbus-user-session fontconfig
docker --help
docker version

kubectl proxy
kubectl --help
kubectl version

kubectl get nodes
kubectl cluster-info
kubectl cluster-info dump
kubectl cluster-info --context kind-kind

kubectl get all --all-namespaces
kubectl get all --namespace kubernetes-dashboard

kubectl patch node $NODENAME -p '{"metadata":{"finalizers":[]}}' --type=merge
kubectl -n kubernetes-dashboard describe secret $(kubectl -n kubernetes-dashboard get secret | grep admin-user | awk '{print $1}')

References