johnniang
你好, 我在使用3.2.1 版本devops 更新集群 deploy 时候得到这个错误, 使用 withCredentials([ kubeconfigContent( )])
提示kubeconfig certificate-authority-data: 内容过长 , 使用 withCredentials([ kubeconfigFile()]) 提示请输入用户名密码,
还有一个疑问, 我的集群里这个kubeconfig 生成的和社区视频里老师所生成的不一样, 少了一节
我的环境是 aws eks, 2台 8c16g 使用官方在线安装方式安装的
期待你的回复
jenkinsfile
pipeline {
agent {
node {
label 'nodejs'
}
}
stages {
stage('拉取代码') {
agent none
steps {
container('nodejs') {
git(url: 'http://gitlab.net/frontend/h5-pages.git', branch: 'master', credentialsId: 'github-id', changelog: true, poll: false)
sh 'ls -al'
}
}
}
stage('项目编译') {
agent none
steps {
container('nodejs') {
sh 'ls'
}
}
}
stage('构建镜像') {
agent none
steps {
container('nodejs') {
sh 'ls -al'
sh 'find / -name kubectl'
sh 'kubectl version --short --client'
sh 'docker build -t $APP_NAME-$BRANCH_NAME-$BUILD_NUMBER:latest -f devops/Dockerfile .'
}
}
}
stage('推送镜像') {
agent none
steps {
container('nodejs') {
withCredentials([usernamePassword(credentialsId : env.DOCKER_CREDENTIAL_ID ,passwordVariable : 'DOCKER_PASSWORD' ,usernameVariable : 'DOCKER_USERNAME' ,)]) {
sh 'echo "$DOCKER_PASSWORD" | docker login $REGISTRY -u "$DOCKER_USERNAME" --password-stdin'
sh 'docker tag $APP_NAME-$BRANCH_NAME-$BUILD_NUMBER:latest $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME-$BRANCH_NAME:$APP_NAME-$BRANCH_NAME-$BUILD_NUMBER '
sh 'docker push $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME-$BRANCH_NAME:$APP_NAME-$BRANCH_NAME-$BUILD_NUMBER '
echo '删除本地镜像'
sh 'docker rmi $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME-$BRANCH_NAME:$APP_NAME-$BRANCH_NAME-$BUILD_NUMBER'
sh 'docker rmi $APP_NAME-$BRANCH_NAME-$BUILD_NUMBER:latest'
}
}
}
}
stage('部署到gray环境') {
steps {
container('nodejs') {
sh 'kubectl version --short --client'
withCredentials([kubeconfigContent(credentialsId : 'kubeconfig-id' ,variable : 'KUBECONFIG' ,)]) {
sh 'envsubst < devops/deploy/deployment.yaml | kubectl apply -f -'
}
}
}
}
}
environment {
DOCKER_CREDENTIAL_ID = 'dockerhub-id'
KUBECONFIG_CREDENTIAL_ID = 'kubeconfig-id'
REGISTRY = 'docker.io'
DOCKERHUB_NAMESPACE = 'docker-hub-id'
APP_NAME = 'h5-page'
BRANCH_NAME = 'gray'
}
}
异常
+ envsubst
+ kubectl apply -f -
W0410 09:09:59.431892 290 loader.go:221] Config not found: apiVersion, v1
clusters,
- cluster,
certificate-authority-data, https, //10.100.0.1, 443
name, local
contexts,
- context,
cluster, local
namespace, default
user, project-regular
name, project-regular@local
current-context, project-regular@local
kind, Config
preferences, {}
users, null
error: error loading config file " LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSU**********
server": open LS0tLS1CRUdJTiBDRVJUSUZJ**********
server: file name too long
script returned exit code 1
kubeconfig
apiVersion: v1
clusters:
- cluster:
certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUMvakNDQWVhZ0***********
server: https://10.100.0.1:443
name: local
contexts:
- context:
cluster: local
namespace: default
user: project-regular
name: project-regular@local
current-context: project-regular@local
kind: Config
preferences: {}
users: null