【发布时间】:2019-03-17 18:41:34
【问题描述】:
我正在尝试创建一个在 git 中提交后触发的管道。我已经使用 kvm2 驱动程序安装了 minikube。但是我不确定是否一切都设置好了。 Jenkins 之前已经安装过,它不能在 kubernetes 上运行。
下面是我的 Jenkinsfile。
pipeline {
environment {
....
}
agent any
stages {
stage ('Clone') {
....
}
stage('Build') {
....
}
stage(‘Containerize’) {
.... build images with docker
}
stage('Deploy Image') {
.... push images on Docker hub
}
stage('Deploy Application') {
steps {
// Create namespace if it doesn't exist
sh("kubectl get ns development || kubectl create ns development")
....
}
}
}
}
我还将 Kubernetes 配置为云。我已将 kubernetes URL 添加为 ./kube/config 中的一个节目
Kubernetes服务器证书作为/.minikube/ca.crt的内容
使用
sudo openssl pkcs12 -export -out kubernetes.pfx -inkey apiserver.key -in apiserver.crt -certfile ca.crt -passout pass:jenkins
我的问题是这样的:
[Pipeline] { (Deploy Application)
[Pipeline] sh
+ kubectl get ns development
The connection to the server localhost:8080 was refused - did you specify the right host or port?
这与 RBAC 有关吗?我尝试使用 kubectl create serviceaccount jenkins 使用秘密令牌并复制令牌,但是当我测试连接时它不起作用。
我不确定这是否是在 Kubernetes 上使用 管道。 请建议是否有更好的方法来部署我的微服务。
【问题讨论】:
-
我认为 Jenkins 代理不知道 K8s 配置,因此无法连接正确的 K8s API 服务器。确保您的 Jenkins 代理已正确配置。
标签: kubernetes jenkins-pipeline kubectl minikube