<p>I'm trying to deploy my docker image into kubernetes cluster in first time, i have two nodes master and worker nodes both are up and running status.</p>

<p>I have created namesapace pre-release environment to deploy my changes on it, during jenkins build, i am getting below error.</p>

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

<p>Jenkins stage </p>

<pre><code>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"
                }   
            }
        }
      }
</code></pre>

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

</code></pre>

<pre><code>CURRENT   NAME                          CLUSTER      AUTHINFO           NAMESPACE
*         K8sCluster-CC-pre-release     kubernetes   kubernetes-admin   K8sCluster-CC-pre-release
</code></pre>

<p>can you please someone help me on this ?</p>

Anonymuss
<p>The reason is <code>K8sCluster-CC-pre-release</code> context does not exist in your kubeconfig file. You can run <code>kubectl config view -o jsonpath='{.current-context}'</code> to check current context and use that context.</p>
