V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
wsgzao
V2EX  ›  Kubernetes

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

  •  
  •   wsgzao · 329 天前 · 1199 次点击
    这是一个创建于 329 天前的主题,其中的信息可能已经有所发展或是发生改变。

    前言

    有一段时间没好好整理 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/

    • kubectl
    • kind
    • minikube
    • kubeadm

    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/

    • kubeadm
    • kOps
    • Kubespray

    https://kubespray.io/

    MicroK8s 介绍

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

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

    • 以快照包的形式交付:这些是用于桌面、云和 IoT 的应用程序包,易于安装,并通过自动更新进行保护,并且可以安装在任何支持 snap 的 Linux 发行版上。这使得 MicroK8 非常适合在构成物联网的各种硬件上运行。
    • 严格的限制:这确保了与底层操作系统的完全隔离,以及一个严格安全的生产级 Kubernetes 环境,所有这些都在一个小的占用空间内,非常适合边缘网关。
    • 生产级附加组件IstioKnativeCoreDNSPrometheusJaegerLinkerdCiliumHelm可作为附加组件使用,这些附加组件易于设置,只需几行命令, 支持快速 Enable/Disable 。
    • Kubeflow 还可以作为 MicroK8s 的附加组件,用于改进人工智能 ( AI ) 和机器学习 ( ML ) 功能。

    凭借其降低复杂性的能力,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 学习环境

    6 条回复    2023-06-07 22:51:24 +08:00
    mypchas6fans
        1
    mypchas6fans  
       329 天前
    学习了。另外官网这张比较图有一点点小问题,k3s 现在也支持 s390x 的,虽然极少有人用到 s390x 的机器就是了
    zed1018
        2
    zed1018  
       329 天前
    MicroK8s 好不好我不知道,但是 snap 在国内根本没法好好使用,之前研究这个东西的时候也不能 mirror ,不知道现在行不行
    zed1018
        3
    zed1018  
       329 天前   ❤️ 3
    相反 k3s 现在通过 rancher.cn 提供了镜像的脚本和二进制,起码能顺利的安装
    zhangzEric
        4
    zhangzEric  
       329 天前 via iPhone
    Kind 也挺好用的
    luomao
        5
    luomao  
       329 天前
    我现在用 k3s 感觉挺不错,之前买的两个学生服务器能排上点用场
    LanLiang
        6
    LanLiang  
       294 天前
    当然是使用 Kind 来搭建测试环境的 kubernetes 啦,https://liangyuanpeng.com/post/run-k8s-with-kind/
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3163 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 13:03 · PVG 21:03 · LAX 06:03 · JFK 09:03
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.