使用 k3d 在Windows上安装 k3s

k3d是运行k3s的一个轻量化程序,k3s 是Rancher实验室提供的一个k8s分支。k3d 是的 k3s 的安装非常便捷,能极大提高k8s的开发与练习。

安装 kubectl

kubectl是K8s官方客户端工具,K3s是K8s得简化版本,可以用它来操作k3s。下载完成后将 kubectl.exe 加入 环境变量 path 中。

安装 k3d

k3d 即 k3s in docker ,它是将k3s以docker 服务化运行的一个工具。

下载k3d-windows-amd64后重命名为 k3d,将其添加到环境变量 path 中,使得能在CMD 中调用 k3d 。

将k3d配置在环境变量path中后,运行 k3d 结果如下

PS D:\Users\xzbd> k3d
Usage:
  k3d [flags]
  k3d [command]

Available Commands:
  cluster      Manage cluster(s)
  completion   Generate completion scripts for [bash, zsh, fish, powershell | psh]
  config       Work with config file(s)
  help         Help about any command
  image        Handle container images.
  kubeconfig   Manage kubeconfig(s)
  node         Manage node(s)
  registry     Manage registry/registries
  version      Show k3d and default k3s version

Flags:
  -h, --help         help for k3d
      --timestamps   Enable Log timestamps
      --trace        Enable super verbose output (trace logging)
      --verbose      Enable verbose output (debug logging)
      --version      Show k3d and default k3s version

Use "k3d [command] --help" for more information about a command.

使用 k3d 启动 k3s 集群

使用k3d启动三个节点的k3s集群,命令如下:

k3d cluster create k3s-server --api-port 6443 --port 0.0.0.0:8099:80@loadbalancer --servers 1 --agents 2

命名为k3s-server, --servers 1表示一个主节点,--agents 2表示两个从节点

更多细节查阅useage

运行结果

PS D:\Users\xzbd> k3d cluster create k3s-server --api-port 6443 --port 0.0.0.0:8000:80@loadbalancer --servers 1 --agents 2
INFO[0000] portmapping '0.0.0.0:8000:80' targets the loadbalancer: defaulting to [servers:*:proxy agents:*:proxy]
INFO[0000] Prep: Network
INFO[0000] Re-using existing network 'k3d-k3s-server' (69d6f03fefb239ce00c07e063784efe3081cdf3bfa1399222f6cdb42cc2c7bed)
INFO[0000] Created image volume k3d-k3s-server-images
INFO[0000] Starting new tools node...
INFO[0001] Creating node 'k3d-k3s-server-server-0'
INFO[0001] Pulling image 'ghcr.io/k3d-io/k3d-tools:5.4.4'
INFO[0004] Pulling image 'docker.io/rancher/k3s:v1.23.8-k3s1'
INFO[0116] Creating node 'k3d-k3s-server-agent-0'
INFO[0116] Creating node 'k3d-k3s-server-agent-1'
INFO[0116] Creating LoadBalancer 'k3d-k3s-server-serverlb'
INFO[0119] Pulling image 'ghcr.io/k3d-io/k3d-proxy:5.4.4'
INFO[0214] Starting Node 'k3d-k3s-server-tools'
INFO[0630] Using the k3d-tools node to gather environment information
INFO[0630] Starting new tools node...
INFO[0631] Starting Node 'k3d-k3s-server-tools'
INFO[0632] Starting cluster 'k3s-server'
INFO[0632] Starting servers...
INFO[0632] Starting Node 'k3d-k3s-server-server-0'
INFO[0638] Starting agents...
INFO[0638] Starting Node 'k3d-k3s-server-agent-1'
INFO[0638] Starting Node 'k3d-k3s-server-agent-0'
INFO[0647] Starting helpers...
INFO[0648] Starting Node 'k3d-k3s-server-serverlb'
INFO[0654] Injecting records for hostAliases (incl. host.k3d.internal) and for 5 network members into CoreDNS configmap...
INFO[0657] Cluster 'k3s-server' created successfully!
INFO[0657] You can now use it like this:
                                                                                                                   kubectl cluster-info

查看集群信息

PS D:\Users\xzbd> kubectl cluster-info
Kubernetes control plane is running at https://host.docker.internal:6443
CoreDNS is running at https://host.docker.internal:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
Metrics-server is running at https://host.docker.internal:6443/api/v1/namespaces/kube-system/services/https:metrics-server:https/proxy

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.

访问 https://host.docker.internal:6443 可以看到以下信息
使用 k3d 在Windows上安装 k3s_第1张图片

查看Docker 进程

可以使用 docker ps 查看 k3s 进程

PS D:\Users\xzbd> docker ps
CONTAINER ID   IMAGE                            COMMAND                  CREATED             STATUS             PORTS                                            NAMES
62ff3fc7917d   ghcr.io/k3d-io/k3d-tools:5.4.4   "/app/k3d-tools noop"    About an hour ago   Up About an hour                                                    k3d-k3s-server-tools
e6dfc0fb3aaf   ghcr.io/k3d-io/k3d-proxy:5.4.4   "/bin/sh -c nginx-pr…"   About an hour ago   Up About an hour   0.0.0.0:6443->6443/tcp, 0.0.0.0:8000->80/tcp     k3d-k3s-server-serverlb
6e3e73b56c06   rancher/k3s:v1.23.8-k3s1         "/bin/k3s agent"         2 hours ago         Up About an hour                                                    k3d-k3s-server-agent-1
a5c568ad1dec   rancher/k3s:v1.23.8-k3s1         "/bin/k3s agent"         2 hours ago         Up About an hour                                                    k3d-k3s-server-agent-0
50af517b4454   rancher/k3s:v1.23.8-k3s1         "/bin/k3s server --t…"   2 hours ago         Up About an hour                                                    k3d-k3s-server-server-0


已提前安装 docker , 采用 docker desktop 安装。

你可能感兴趣的:(Linux,工具使用,docker,K3S,K3D)