Skip to main content

Installation

K8s 用戶端 CLI

Kubectl

K8s 用戶端程式

curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl

# Use snap
sudo snap install kubectl

設定檔位置:設定方式:

    ~/.kube/config export KUBECONFIG=/path/to/config 
    Helm
    # Use snap
    sudo snap install helm

     

    K3s

    curl -sfL https://get.k3s.io | sh -

    After running this installation:

    • The K3s service will be configured to automatically restart after node reboots or if the process crashes or is killed
    • Additional utilities will be installed, including kubectl, crictl, ctr, k3s-killall.sh, and k3s-uninstall.sh
    • A kubeconfig file will be written to /etc/rancher/k3s/k3s.yaml and the kubectl installed by K3s will automatically use it
    sudo cp /etc/rancher/k3s/k3s.yaml ~
    sudo chown <your-id> k3s.yaml
    export KUBECONFIG=~/k3s.yaml
    kubectl config view
    Install additional agent node
    • The value to use for K3S_TOKEN is stored at /var/lib/rancher/k3s/server/node-token on your server node.
    curl -sfL https://get.k3s.io | K3S_URL=https://myserver:6443 K3S_TOKEN=mynodetoken sh -

    Microk8s

    Installation

    sudo snap install microk8s --classic

    Verify

    root@k8s-vm:~# microk8s version
    MicroK8s v1.32.9 revision 8511
    
    root@k8s-vm:~# snap list
    Name      Version   Rev    Tracking       Publisher   Notes
    core20    20251031  2686   latest/stable  canonical✓  base
    microk8s  v1.32.9   8511   1.32/stable    canonical✓  classic
    snapd     2.73      25935  latest/stable  canonical✓  snapd
    
    root@k8s-vm:~# microk8s status
    microk8s is running
    high-availability: no
      datastore master nodes: 127.0.0.1:19001
      datastore standby nodes: none
    addons:
      enabled:
        dns                  # (core) CoreDNS
        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
        cis-hardening        # (core) Apply CIS K8s hardening
        community            # (core) The community addons repository
        dashboard            # (core) The Kubernetes dashboard
        gpu                  # (core) Alias to nvidia add-on
        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
        nvidia               # (core) NVIDIA hardware (GPU and network) support
        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
        rook-ceph            # (core) Distributed Ceph storage using Rook
        storage              # (core) Alias to hostpath-storage add-on, deprecated

    Setting up an alias for microk8s kubectl

    alias kubectl="microk8s kubectl"

    Microk8s Commands

    # Start a Microk8s cluster
    sudo microk8s start
    
    # Stop a Microk8s cluster
    sudo microk8s stop
    
    # Reset your Microk8s cluster
    sudo microk8s reset
    
    # Enabling the Microk8s dashboard
    sudo microk8s enable dashboard
    
    # Adding a node to your microk8s Kubernetes cluster
    microk8s add-node
    
    # Joining a node
    microk8s join <your master node and token string>
    

    Upgrading your Microk8s cluster

    # First, drain your Kubernetes node:
    microk8s kubectl drain <your node> --ignore-daemonsets --delete-emptydir-data --force
    
    # Upgrade your Microk8s node
    sudo snap refresh microk8s --channel=1.32/stable
    
    # Check the version of your Microk8s nodes:
    microk8s.kubectl get no
    
    # Finally, uncordon your node:
    microk8s kubectl uncordon <node>

    Enable addons

    • metrics-server : 效能指標,使用 Lens 管理工具的 Overview 需要。