apiVersion:k3d.io/v1alpha2 kind:Simple name:mycluster servers:1 agents:2 kubeAPI: hostPort:"6443"# same as `--api-port '6443'` ports: -port:8080:80# same as `--port '8080:80@loadbalancer'` nodeFilters: -loadbalancer -port:8443:443# same as `--port '8443:443@loadbalancer'` nodeFilters: -loadbalancer
$ k3d cluster create --config /path/to/mycluster.yaml INFO[0000] Using config file mycluster.yaml INFO[0000] Prep: Network INFO[0000] Created network 'k3d-mycluster' INFO[0000] Created volume 'k3d-mycluster-images' INFO[0001] Creating node 'k3d-mycluster-server-0' INFO[0001] Creating node 'k3d-mycluster-agent-0' INFO[0001] Creating node 'k3d-mycluster-agent-1' INFO[0001] Creating LoadBalancer 'k3d-mycluster-serverlb' INFO[0001] Starting cluster 'mycluster' INFO[0001] Starting servers... INFO[0001] Starting Node 'k3d-mycluster-server-0' INFO[0007] Starting agents... INFO[0007] Starting Node 'k3d-mycluster-agent-0' INFO[0020] Starting Node 'k3d-mycluster-agent-1' INFO[0028] Starting helpers... INFO[0028] Starting Node 'k3d-mycluster-serverlb' INFO[0029] (Optional) Trying to get IP of the docker host and inject it into the cluster as 'host.k3d.internal' for easy access INFO[0031] Successfully added host record to /etc/hosts in 4/4 nodes and to the CoreDNS ConfigMap INFO[0031] Cluster 'mycluster' created successfully! INFO[0031] --kubeconfig-update-default=false --> sets --kubeconfig-switch-context=false INFO[0031] You can now use it like this: kubectl config use-context k3d-mycluster kubectl cluster-info
接下来我们使用 kubectl 来查看集群 mucluster 中的基本信息:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
$ kubectl get nodes NAME STATUS ROLES AGE VERSION k3d-mycluster-server-0 Ready control-plane,master 29m v1.20.2+k3s1 k3d-mycluster-agent-0 Ready <none> 29m v1.20.2+k3s1 k3d-mycluster-agent-1 Ready <none> 29m v1.20.2+k3s1