开启 Kubernetes
注意: 网络正常的情况下可以直接开启,若不能访问 gcr.io
等镜像中心,请提前使用 docker load -i
命令手动导入所需镜像。
点击 Settings -> Kubernetes
勾选 Enable Kubernetes
并点击 Apply & Restart
开启 Kubernetes。
使用 kubectl 访问 Kubernetes
安装
因 WSL 2 中的 snap 工具不可用,故在此使用 curl
命令安装。
curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/darwin/amd64/kubectl
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl
复制代码
访问
使用 kubectl
查看 Kubernetes 集群信息。
❯ kubectl cluster-info
Kubernetes master is running at https://kubernetes.docker.internal:6443
KubeDNS is running at https://kubernetes.docker.internal:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
复制代码
额外操作
登录 hub
直接登录会报错
❯ docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: vflong
Password:
Error saving credentials: error storing credentials - err: exec: "docker-credential-desktop.exe": executable file not found in $PATH, out: ``
复制代码
解决方式是删除默认的配置 .docker/config.json
❯ cd .docker
❯ ls
config.json
❯ cat config.json
{"credsStore":"desktop.exe"}%
❯ mv config.json config.json.backup
复制代码
登录
❯ docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: vflong
Password:
WARNING! Your password will be stored unencrypted in /home/feilong/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
复制代码
推送 gcr 镜像至 hub
# 打 tag
❯ for image in $(docker images --filter=reference='k8s.gcr.io/*:*' --format "{{.Repository}}:{{.Tag}}"); do
echo "docker tag ${image} $(echo ${image} | awk -F/ '{print "vflong/" $NF}')" | bash
done
# 推送
❯ docker images --filter=reference='vflong/*:*' --format "docker push {{.Repository}}:{{.Tag}}" | bash
复制代码
评论