小编典典

Jenkins部署到K8集群

jenkins

我正在尝试第一次将docker映像部署到kubernetes集群中,我有两个节点master和worker节点都处于启动和运行状态。

我创建了namesapace预发布环境,以在jenkins构建过程中部署我的更改,但我遇到了错误。

+ kubectl '--kubeconfig=****' '--context=K8sCluster-CC-pre-release' apply -f ./environment/pre-release '-n=pre-release'
error: context "K8sCluster-CC-pre-release" does not exist

詹金斯舞台

stage('deployment') {
        container('kubectl') {

            withCredentials([kubeconfigFile(credentialsId: 'KUBERNETES_CLUSTER_CONFIG', variable: 'KUBECONFIG')]) {
            def kubectl
                if(gitBranch == "future-master-fix") {
                kubectl = "kubectl --kubeconfig=${KUBECONFIG} --context=K8sCluster-CC-pre-release"
                sh "${kubectl} apply -f ./environment/pre-release -n=pre-release"
                }   
            }
        }
      }



kubectl config set-context K8sCluster-CC-pre-release --namespace=K8sCluster-CC-pre-release --user=kubernetes-admin --cluster=kubernetes
Context "K8sCluster-CC-pre-release" created.




CURRENT   NAME                          CLUSTER      AUTHINFO           NAMESPACE
*         K8sCluster-CC-pre-release     kubernetes   kubernetes-admin   K8sCluster-CC-pre-release

你能请人帮我吗?


阅读 528

收藏
2020-07-25

共1个答案

小编典典

原因是K8sCluster-CC-pre-release上下文在您的kubeconfig文件中不存在。您可以运行kubectl config view -o jsonpath='{.current-context}'以检查当前上下文并使用该上下文。

2020-07-25