使用docker-compose启动k3s

获取源码

git clone git@github.com:rancher/k3s.git

启动

cd k3s
K3S_TOKEN=${RANDOM}${RANDOM}${RANDOM} docker-compose up -d

使kubectl引用配置信息

export KUBECONFIG=./kubeconfig.yaml

试着获取节点。

kubectl get nodes

输出

NAME           STATUS   ROLES    AGE   VERSION
65e2440e6916   Ready    <none>   11m   v1.19.4+k3s1
774f7268c91f   Ready    master   11m   v1.19.4+k3s1

安装仪表盘

GITHUB_URL=https://github.com/kubernetes/dashboard/releases
VERSION_KUBE_DASHBOARD=$(curl -w '%{url_effective}' -I -L -s -S ${GITHUB_URL}/latest -o /dev/null | sed -e 's|.*/||')
kubectl create -f https://raw.githubusercontent.com/kubernetes/dashboard/${VERSION_KUBE_DASHBOARD}/aio/deploy/recommended.yaml
 echo 'apiVersion: v1                                                                                                                                                                    
kind: ServiceAccount
metadata:
  name: admin-user
  namespace: kubernetes-dashboard' | kubectl apply -f -
echo 'apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: admin-user
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
- kind: ServiceAccount
  name: admin-user
  namespace: kubernetes-dashboard' | kubectl apply -f -

获取令牌

kubectl -n kubernetes-dashboard describe secret admin-user-token | grep "^token"

启动代理并访问仪表盘。

kubectl proxy
http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/
image.png

请提供您的参考文献(请提供参考文献)

    • rancher/k3s: Lightweight Kubernetes

 

    Rancher Docs: Kubernetes Dashboard
广告
将在 10 秒后关闭
bannerAds