MicroK8s vs K3s vs minikube 本地 k8s 学习环境快速搭建

361 天前
 wsgzao

前言

有一段时间没好好整理 k8s 本地开发环境了,Kubernetes 官方文档曾几何时已经支持中文语言切换且更新及时,感谢背后的开源社区协作者们。本文主要记录 k8s 本地开发环境快速搭建选型方案,毕竟现在公有云托管型 Kubernetes 越来越成熟,更重要的是怎么灵活运用云原生的理念提升基础架构管理水平。

更新历史

2023 年 03 月 07 日 - 初稿

阅读原文 - https://wsgzao.github.io/post/microk8s/


Kubernetes 环境安装工具

k8s 安装工具对比

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/

https://kubespray.io/

MicroK8s 介绍

我们已经知道,Kubernetes 是基于容器的应用程序的首选编排平台,可以自动部署和扩展这些应用程序,并简化维护操作。但是,Kubernetes 也有其自身的复杂性挑战。那么,企业如何利用容器化来解决物联网的复杂性,而不会最终导致 Kubernetes 更加复杂呢?

Canonical 的MicroK8s是一个功能强大的,云原生计算基金会认证的 Kubernetes发行版。以下是一些关键原因,我觉得,为什么它已经成为一个强大的企业边缘计算平台:

凭借其降低复杂性的能力,MicroK8s 将加速物联网和边缘部署。将物联网设备视为分布式容器化应用程序,使开发人员能够专注于应用程序而不是基础架构,并使运营团队的生活更轻松。

MicroK8s 允许您将 Kubernetes 安装群集在一起,以便它们可以形成单个群集,并将工作负载放在一个或多个这些节点上。 简而言之,Kubernetes 是:

在本文中,我们将介绍可以在边缘,物联网和设备上运行的轻量级 Kbernetes 引擎MicroK8。microk8s 是一个非常轻量级的 k8s 发行版,小巧轻量安装快速是他的特点,microk8s 是使用 snap 包安装的,所以他在 Ubuntu 上的体验是最好的,毕竟 microk8s 是 Canonical 公司开发的产品。

MicroK8s 安装使用

https://microk8s.io/docs/install-macos

Install Homebrew

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
  1. Download the MicroK8s installer
    brew install ubuntu/microk8s/microk8s

  2. Run the installer or switch the version of Kubernetes

    microk8s install
    microk8s install --channel=1.26
    microk8s install --channel=1.24
    
  3. 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
  1. Turn on the services you want
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.

  1. Start using Kubernetes!
    microk8s kubectl get all --all-namespaces

  2. Access the Kubernetes dashboard
    microk8s dashboard-proxy

  3. 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

容器镜像加速和 k8s 实用工具推荐

左耳朵科学上网

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 在本地环境快速上手实践

https://kuboard.cn/learning/

参考文章

K3d vs k3s vs Kind vs Microk8s vs Minikube

Minikube vs. kind vs. k3s - What should I use?

Minikube vs. kind vs. k3s vs k3d vs MicroK8s

轻量高可用的 K8s 集群搭建方案:MicroK8s

Microk8s 安装与使用指南

比 Minikube 更快,使用 Kind 快速创建 K8S 学习环境

1282 次点击
所在节点    Kubernetes
6 条回复
mypchas6fans
360 天前
学习了。另外官网这张比较图有一点点小问题,k3s 现在也支持 s390x 的,虽然极少有人用到 s390x 的机器就是了
zed1018
360 天前
MicroK8s 好不好我不知道,但是 snap 在国内根本没法好好使用,之前研究这个东西的时候也不能 mirror ,不知道现在行不行
zed1018
360 天前
相反 k3s 现在通过 rancher.cn 提供了镜像的脚本和二进制,起码能顺利的安装
zhangzEric
360 天前
Kind 也挺好用的
luomao
360 天前
我现在用 k3s 感觉挺不错,之前买的两个学生服务器能排上点用场
LanLiang
326 天前
当然是使用 Kind 来搭建测试环境的 kubernetes 啦,https://liangyuanpeng.com/post/run-k8s-with-kind/

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/937187

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX