为了简化开发环境,我在WSL Ubuntu 虚拟机上安装了一个microk8s环境,接着在项目开发中,想用kubernetes-maven-plugin部署一个服务到k8s上,但出现错误:

[WARNING] Error reading service account token from: [/var/run/secrets/kubernetes.io/serviceaccount/token]. Ignoring.
[WARNING] F8: Cannot access cluster for detecting mode: Unknown host kubernetes.default.svc

看来plugin默认的k8s主机是kubernetes.default.svc,一时又找不着在哪儿修改这个主机名,于是,我就在/etc/hosts里加上这个域名,让它指向127.0.0.1,再试一下,又出现一个问题:

[ERROR] Failed to execute goal org.eclipse.jkube:kubernetes-maven-plugin:1.16.1:deploy (default-cli) on project webdemo: Execution default-cli of goal org.eclipse.jkube:kubernetes-maven-plugin:1.16.1:deploy failed: An error has occurred.: Failed to connect to kubernetes.default.svc/127.0.0.1:443: Connection refused -> [Help 1]

这下域名问题解决了,又发现端口443不行,于是查询一下

$  kubectl cluster-info

Kubernetes control plane is running at https://127.0.0.1:16443
CoreDNS is running at https://127.0.0.1:16443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

原来端口是16443,然后一顿狂搜,也没找到结果,后来在microk8s找到办法了:https://microk8s.io/docs/working-with-kubectl

然后执行如下命令:

cd $HOME
mkdir .kube
cd .kube
microk8s config > config

再执行一下部署命令:

 mvn k8s:resource k8s:deploy

终于正常了。

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐