kubernetes-maven-plugin部署到microk8s出现问题

为了简化开发环境,我在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

终于正常了。

相关推荐
运维开发故事2 天前
基于 Arthas 的多集群在线诊断系统设计与实现
kubernetes
Patrick_Wilson4 天前
从「改个端口」到 502:Next.js on k8s 的容器端口、Service 映射与 env 覆盖
docker·kubernetes·next.js
探索云原生4 天前
K8s 1.36 这个 GA 特性,把 initContainer 拉模型的 hack 干掉了
ai·云原生·kubernetes
云恒要逆袭5 天前
运行你的第一个Docker容器
后端·docker·容器
Java之美6 天前
一次k8s升级引发的DevicePlugin注册失败
云原生·kubernetes
程序员老赵6 天前
10 分钟部署 OpenCode:Docker 一键安装,浏览器打开就能用 AI 写代码(附完整命令与排错)
docker·容器·ai编程
武子康9 天前
调查研究-183 Apple container:Mac 上用轻量 VM 跑 Linux 容器,Swift 会改写本地容器体验吗?
docker·容器·apple
小宇宙Zz12 天前
Maven依赖冲突
java·服务器·maven
2601_9618752412 天前
决战申论100题2026|最新|范文
linux·容器·centos·debian·ssh·fabric·vagrant