microk8s 클러스터 구성

기본적으로 kubeadm 을 사용하여 kubernetes 환경을 구성해왔다.

k8s-v1.25-Crio-Auto-Installation.sh
GitHub Gist: instantly share code, notes, and snippets.

클러스터가 많을 경우에는 kubespray, terraform 으로 설정하고 있으나, 기본적으로는 가벼운 기능만 사용하기 때문에 k3s, microk8s 등에 관심이 있었다.

생각난 김에 microk8s 로 kubernetes 를 설정해본다.

MicroK8s - MicroK8s How To guides | MicroK8s
MicroK8s is the simplest production-grade upstream K8s. Lightweight and focused. Single command install on Linux, Windows and macOS. Made for devops, great for edge, appliances and IoT. Full high availability Kubernetes with autonomous clusters.

microk8s install

sudo snap install microk8s --classic --channel=1.28/stable
sudo usermod -a -G microk8s $USER
sudo mkdir -p $HOME/.kube
sudo chown -f -R $USER $HOME/.kube
sudo su - $USER

(option) microk8s versions

taking@kubernetes-01:~$ snap info microk8s
...
channels:
  1.28/stable:           v1.28.3  2023-11-12 (6089) 185MB classic
  1.28/candidate:        v1.28.6  2024-01-28 (6429) 185MB classic
  1.28/beta:             v1.28.6  2024-01-28 (6429) 185MB classic
  1.28/edge:             v1.28.7  2024-02-14 (6503) 186MB classic
  latest/stable:         v1.29.0  2024-01-25 (6364) 168MB classic
  latest/candidate:      v1.29.1  2024-01-20 (6425) 168MB classic
  latest/beta:           v1.29.1  2024-01-20 (6425) 168MB classic
  latest/edge:           v1.29.2  2024-02-14 (6524) 169MB classic
  dqlite/stable:         –                                
  dqlite/candidate:      –                                
  dqlite/beta:           –                                
  dqlite/edge:           v1.16.2  2019-11-07 (1038) 189MB classic
  1.29-strict/stable:    v1.29.0  2023-12-14 (6370) 168MB -
  1.29-strict/candidate: v1.29.1  2024-01-31 (6424) 168MB -
  1.29-strict/beta:      v1.29.1  2024-01-31 (6424) 168MB -
  1.29-strict/edge:      v1.29.2  2024-02-15 (6529) 169MB -
  1.29/stable:           v1.29.0  2023-12-14 (6364) 168MB classic
  1.29/candidate:        v1.29.1  2024-01-29 (6470) 168MB classic
  1.29/beta:             v1.29.1  2024-01-29 (6470) 168MB classic
  1.29/edge:             v1.29.2  2024-02-14 (6520) 169MB classic
  1.28-strict/stable:    v1.28.3  2023-11-13 (6091) 185MB -
...

microk8s service

# addon lists - https://microk8s.io/docs/addons
#                   cert-manager, dashboard, gpu, hostpath-storage
#                   ingress, metallb, metrics-server, rbac, rook-ceph
#                   registry

## Deploys CoreDNS
microk8s enable dns

## Installs the Helm 3 package
microk8s enable helm3

## Enables the Community addons Repository
microk8s enable community

## Deploys the linkerd service mesh
microk8s enable linkerd

## Deploys the metrics-server
microk8s enable metrics-server

microk8s settings

(Alias)

cat <<'EOF'>> $HOME/.bashrc
echo alias kc='microk8s kubectl'
EOF

source $HOME/.bashrc

kc get nodes

(Config)

microk8s.kubectl config view --raw > $HOME/.kube/config

(kubectl binary)

sudo tee /usr/local/bin/kubectl <<'EOF'
#!/bin/bash
exec /snap/bin/microk8s.kubectl $@
EOF

sudo chmod a+x /usr/local/bin/kubectl

microk8s - Add Node

microk8s add-node

(추가) k9s

Releases · derailed/k9s
🐶 Kubernetes CLI To Manage Your Clusters In Style! - derailed/k9s
wget https://github.com/derailed/k9s/releases/download/v0.31.8/k9s_linux_amd64.deb
sudo dpkg -i k9s_linux_amd64.deb
k9s

Press `?` to see the comment.

Press `:` to see deploy, statefulset, and more.

boom!

microk8s reset

taking@kubernetes-01:~$ microk8s reset
Elevated permissions is needed for this operation. Please run this command with sudo.
taking@kubernetes-01:~$ sudo microk8s reset
isabling all addons
Disabling addon : community/argocd
Disabling addon : community/cilium
Disabling addon : community/dashboard-ingress
Disabling addon : community/easyhaproxy
Disabling addon : community/fluentd
Disabling addon : community/gopaddle
Disabling addon : community/inaccel
Disabling addon : community/istio
Disabling addon : community/jaeger
Disabling addon : community/kata
Disabling addon : community/keda
...
All addons are disabled.
Deleting the CNI
Cleaning resources in namespace kube-system
Cleaning resources in namespace kube-public
Cleaning resources in namespace kube-node-lease
Cleaning resources in namespace default
Removing CRDs
Removing PriorityClasses
Removing StorageClasses
Restarting cluster
Stopped.
Setting up the CNI
taking@kubernetes-01:~$
sudo unlink /usr/local/bin/kubectl
sudo rm -rf $HOME/.local/bin/kubectl
sudo rm -rf $HOME/.local/share/k9s $HOME/.local/state/k9s $HOME/.config/k9s/ $HOME/.kube/

sudo snap remove microk8s
You've successfully subscribed to taking
Great! Next, complete checkout to get full access to all premium content.
Error! Could not sign up. invalid link.
Welcome back! You've successfully signed in.
Error! Could not sign in. Please try again.
Success! Your account is fully activated, you now have access to all content.
Error! Stripe checkout failed.
Success! Your billing info is updated.
Error! Billing info update failed.