[雲端] K8s / env / K3s === ###### tags: `雲端 / K8s` ###### tags: `雲端`, `K8s`, `K3s` <br> ![](https://i.imgur.com/vsCp0RX.png =20%x) ![](https://i.imgur.com/zT1uueg.png =35%x) [TOC] <br> ## 何謂 K3S - ==K8S 的輕量版(lightweight)== - GitHub - https://github.com/rancher/k3s <br> ## [K3S 的起源](https://www.ithome.com.tw/news/129110) - ### 目的 - 為了 Rio 的容器解決方案 - ### 解決方法 - Rio 需要在 K8S 上運作 - 所以在 Rio 解決方案中,放入了完整的 K8S 叢集 - ### 持續改良 - 起因 - 發現 Rio 佔用太多記憶體 - 解決方案 - 刪除不必要的 K8S 元件,持續做實驗探索 - **最終成果** - 因移除 K8S 的老舊以及 Alpha 測試功能,能大幅降低 K8S 的大小 - 從 Rio 專案中,獨立出 K3S - K3S 是 ==40MB== 的二進位檔 - 包含運作 K8S 的所有資源 - 符合 CNCF 標準 <br> ## K3S 的名稱由來? - [Kubes = K3S](https://github.com/rancher/k3s/issues/55) - KUSO 一下 ``` k3s = k + ( len("ubernete") - len("heavy")) + s = k + (8 - 5) + s = k + 3 + s = k3s ``` ``` k8s ,把 8 砍一半,變成 3 表示 k3s 是輕量版? ``` <br> ## K3S 核心元件 - **K8S 核心元件** - Runtime, iptables、socat、du 等 - Containerd . . . . . . . . . . . . (管理完整的容器生命週期) - Flannel . . . . . . . . . . . . . . . (管理跨主機 docker 網路) - CoreDNS . . . . . . . . . . . . . ([CNCF 孵化畢業的開源 DNS 專案](https://k2r2bai.com/2019/09/24/ironman2020/day09/)) - Traefik Ingress 控制器 . . . ([實現負載平衡?](https://ithelp.ithome.com.tw/articles/10196261)) - 基於主機連接埠的服務負載平衡器 - \------------------------------------------------------------ 利用這些元件,打造出符合 CNCF 標準的叢集 <br> ## K3s 之安裝 - [Get Started](https://k3s.io/) ``` chmod +x k3s sudo k3s server & # Kubeconfig is written to /etc/rancher/k3s/k3s.yaml sudo k3s kubectl get node ``` - ```docker rm -f $(docker ps -aq)``` <br> ## K3D - ### 何謂 K3D - ==k3s in docker== - GitHub - https://github.com/rancher/k3d - 官網 - https://k3d.io/ - ### Hello World - https://github.com/rancher/k3d#k3s-in-docker - https://asciinema.org/a/330413 ``` $ k3d create cluster demo --workers 3 $ k3d list +-------------+------------------------------------+---------+---------+ | NAME | IMAGE | STATUS | WORKERS | +-------------+------------------------------------+---------+---------+ | k3s-default | docker.io/rancher/k3s:v1.17.3-k3s1 | running | 3/3 | +-------------+------------------------------------+---------+---------+ $ k3d get-kubeconfig /home/diatango_lin/.config/k3d/k3s-default/kubeconfig.yaml $ echo $KUBECONFIG /home/diatango_lin/.config/k3d/k3s-default/kubeconfig.yaml ``` - ### [k3d create](https://ithelp.ithome.com.tw/articles/10218724) - case1 ```bash $ k3d create INFO[0000] Created cluster network with ID 3b2f3fe00cbcdf64e39801c24dd3402158000ec75bd13b7912bb6aa41086ae84 INFO[0000] Created docker volume k3d-k3s-default-images INFO[0000] Creating cluster [k3s-default] INFO[0000] Creating server using docker.io/rancher/k3s:v1.17.3-k3s1... INFO[0001] SUCCESS: created cluster [k3s-default] INFO[0001] You can now use the cluster with: export KUBECONFIG="$(k3d get-kubeconfig --name='k3s-default')" kubectl cluster-info ``` ```bash $ echo $KUBECONFIG /home/diatango_lin/.config/k3d/k3s-default/kubeconfig.yaml ``` - case2 ```bash $ k3d create FATA[0000] Couldn't create network Error response from daemon: could not find an available, non-overlapping IPv4 address pool among the defaults to assign to the network ``` - 可能解法1(尚未驗證) - [TLS 证书错误,以下错误表明证书可能不匹配](https://k8smeetup.github.io/docs/setup/independent/troubleshooting-kubeadm/) - [会自动从 kubeadm 创建的集群获取 master 的默认管理员凭证(/etc/kubernetes/admin.conf)](https://k8smeetup.github.io/docs/admin/kubeadm/) - 可能解法2 ``` k3d list k3d stop k3s-default k3d delete k3s-default k3d list ``` 在重建就好了?? [![](https://i.imgur.com/RwJzTeN.png)](https://i.imgur.com/RwJzTeN.png) <br> ## 教學資源 - [[HackMD] K8S 筆記](https://hackmd.io/4WCTdFoCS56DYlVd9yZ5ow#系列文章) - [[Youtube] Intro to k3s Lightweight Kubernetes Online training](https://youtu.be/FrGpJNI8na4?t=256) <br> ## 參考資料 - [[Day05]K3d (K3s In Docker) 如何安裝](https://ithelp.ithome.com.tw/articles/10218724) - [6000个边缘Kubernetes节点驱动城市80万次智能停车,如何成为可能?](https://segmentfault.com/a/1190000018484513) - [邊緣運算之容器管理工具 - K3s 之介紹與玩耍](https://bestsamina.github.io/posts/2019-10-10-k3s-intro-and-play/) - [Rancher釋出K3s!史上最輕量K8s發行版,賦能邊緣計算](https://www.itread01.com/content/1551328803.html) - [What’s the difference between k3s vs k8s](https://www.civo.com/blog/k8s-vs-k3s) - [[K3s] 邊緣運算落伍了! 3分鐘看懂Edge Intelligence邊緣智能(上集)](https://www.youtube.com/watch?v=RHVgRk8P97s&feature=youtu.be&t=113s) ![](https://i.imgur.com/SJ4xasK.png) - Containerized Computing Environment 容器化計算環境 - Computing Resource Management 計算資源管理 - Easy to build a high performance/availability microservices 易於建構高效能/高可用性的微服務