有一段时间没好好整理 k8s 本地开发环境了,Kubernetes 官方文档曾几何时已经支持中文语言切换且更新及时,感谢背后的开源社区协作者们。本文主要记录 k8s 本地开发环境快速搭建选型方案,毕竟现在公有云托管型 Kubernetes 越来越成熟,更重要的是怎么灵活运用云原生的理念提升基础架构管理水平。
2023 年 03 月 07 日 - 初稿
阅读原文 - https://wsgzao.github.io/post/microk8s/
Kubernetes 官方维护的 minikube https://github.com/kubernetes/minikube
Rancher 维护的 k3s https://github.com/rancher/k3s https://github.com/k3s-io/k3s
Ubuntu 母公司 Canonical 维护的 MicroK8s https://github.com/ubuntu/micro
MicroK8s vs K3s vs minikube https://microk8s.io/compare
https://kubernetes.io/zh-cn/docs/tasks/tools/
https://kind.sigs.k8s.io/docs/user/quick-start/
https://minikube.sigs.k8s.io/docs/start/
https://kubernetes.io/zh-cn/docs/setup/production-environment/tools/
我们已经知道,Kubernetes 是基于容器的应用程序的首选编排平台,可以自动部署和扩展这些应用程序,并简化维护操作。但是,Kubernetes 也有其自身的复杂性挑战。那么,企业如何利用容器化来解决物联网的复杂性,而不会最终导致 Kubernetes 更加复杂呢?
Canonical 的MicroK8s是一个功能强大的,云原生计算基金会认证的 Kubernetes发行版。以下是一些关键原因,我觉得,为什么它已经成为一个强大的企业边缘计算平台:
凭借其降低复杂性的能力,MicroK8s 将加速物联网和边缘部署。将物联网设备视为分布式容器化应用程序,使开发人员能够专注于应用程序而不是基础架构,并使运营团队的生活更轻松。
MicroK8s 允许您将 Kubernetes 安装群集在一起,以便它们可以形成单个群集,并将工作负载放在一个或多个这些节点上。 简而言之,Kubernetes 是:
在本文中,我们将介绍可以在边缘,物联网和设备上运行的轻量级 Kbernetes 引擎MicroK8。microk8s 是一个非常轻量级的 k8s 发行版,小巧轻量安装快速是他的特点,microk8s 是使用 snap 包安装的,所以他在 Ubuntu 上的体验是最好的,毕竟 microk8s 是 Canonical 公司开发的产品。
https://microk8s.io/docs/install-macos
Install Homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
Download the MicroK8s installer
brew install ubuntu/microk8s/microk8s
Run the installer or switch the version of Kubernetes
microk8s install
microk8s install --channel=1.26
microk8s install --channel=1.24
Check the status while Kubernetes starts
microk8s status --wait-ready
microk8s status --wait-ready
microk8s is running
high-availability: no
datastore master nodes: 127.0.0.1:19001
datastore standby nodes: none
addons:
enabled:
ha-cluster # (core) Configure high availability on the current node
helm # (core) Helm - the package manager for Kubernetes
helm3 # (core) Helm 3 - the package manager for Kubernetes
disabled:
cert-manager # (core) Cloud native certificate management
community # (core) The community addons repository
dashboard # (core) The Kubernetes dashboard
dns # (core) CoreDNS
gpu # (core) Automatic enablement of Nvidia CUDA
host-access # (core) Allow Pods connecting to Host services smoothly
hostpath-storage # (core) Storage class; allocates storage from host directory
ingress # (core) Ingress controller for external access
kube-ovn # (core) An advanced network fabric for Kubernetes
mayastor # (core) OpenEBS MayaStor
metallb # (core) Loadbalancer for your Kubernetes cluster
metrics-server # (core) K8s Metrics Server for API access to service metrics
minio # (core) MinIO object storage
observability # (core) A lightweight observability stack for logs, traces and metrics
prometheus # (core) Prometheus operator for monitoring and logging
rbac # (core) Role-Based Access Control for authorisation
registry # (core) Private image registry exposed on localhost:32000
storage # (core) Alias to hostpath-storage add-on, deprecated
microk8s enable dashboard
microk8s enable dns
microk8s enable registry
microk8s enable community
microk8s enable istio
Addon istio was not found in any repository
To use the community maintained flavor enable the respective repository:
microk8s enable community
An error occurred when trying to execute 'sudo microk8s.enable istio' with 'multipass': returned exit code 1.
Try microk8s enable --help
for a list of available services built in. The microk8s disable
command turns off a service.
Start using Kubernetes!
microk8s kubectl get all --all-namespaces
Access the Kubernetes dashboard
microk8s dashboard-proxy
Start and stop Kubernetes
Kubernetes is a collection of system services that talk to each other all the time. If you don’t need them running in the background then you will save battery/resources by stopping them. the microk8s start
and microk8s stop
commands will do the work for you.
# 使用 Lens 管理 microk8s
microk8s config > ~/.kube/config
# 修改 microk8s 里面 DNS 服务
microk8s kubectl -n kube-system edit configmap/coredns
# 配置 microk8s 内置 docker 的 registry.mirrors
https://microk8s.io/docs/registry-private
# 手动访问仪表板,不依赖 microk8s dashboard-proxy 命令
# 获取 token 密钥
token=$(microk8s kubectl -n kube-system get secret | grep default-token | cut -d " " -f1)
microk8s kubectl -n kube-system describe secret $token
# 映射端口到外部网卡
microk8s kubectl port-forward -n kube-system --address=0.0.0.0 service/kubernetes-dashboard 10443:443
# 浏览器访问
https://127.0.0.1:10443
左耳朵科学上网
https://github.com/haoel/haoel.github.io
Pull gcr.io's image for hub.docker.com tools
https://github.com/OpsDocker/pullk8s
DaoCloud 加速三剑客
镜像加速: https://github.com/DaoCloud/public-image-mirror
二进制文件加速: https://github.com/DaoCloud/public-binary-files-mirror
Helm 加速: https://github.com/DaoCloud/public-helm-charts-mirror
kubeconfig 多配置文件切换工具推荐
https://wsgzao.github.io/post/kubeconfig/
使用 krew 安装 node-shell 轻松修改 k8s 宿主机 root 密码
https://wsgzao.github.io/post/krew/
基于 microk8s 结合 kuboard 使用 kubectl 在本地环境快速上手实践
K3d vs k3s vs Kind vs Microk8s vs Minikube
Minikube vs. kind vs. k3s - What should I use?
1
mypchas6fans 2023-05-04 12:51:26 +08:00
学习了。另外官网这张比较图有一点点小问题,k3s 现在也支持 s390x 的,虽然极少有人用到 s390x 的机器就是了
|
2
zed1018 2023-05-04 12:56:32 +08:00
MicroK8s 好不好我不知道,但是 snap 在国内根本没法好好使用,之前研究这个东西的时候也不能 mirror ,不知道现在行不行
|
3
zed1018 2023-05-04 12:57:13 +08:00 3
相反 k3s 现在通过 rancher.cn 提供了镜像的脚本和二进制,起码能顺利的安装
|
4
zhangzEric 2023-05-04 13:27:18 +08:00 via iPhone
Kind 也挺好用的
|
5
luomao 2023-05-04 15:12:57 +08:00
我现在用 k3s 感觉挺不错,之前买的两个学生服务器能排上点用场
|
6
LanLiang 2023-06-07 22:51:24 +08:00
当然是使用 Kind 来搭建测试环境的 kubernetes 啦,https://liangyuanpeng.com/post/run-k8s-with-kind/
|