How to Access the Application after the kubernetes deployment

1/16/2020

I'm new to kubernetes tool, i'm trying to deploy the Angular application using docker + kubernetes, here the below Jenkins script.

stage('Deploy') {
       container('kubectl') {        
            withCredentials([kubeconfigFile(credentialsId: 'KUBERNETES_CLUSTER_CONFIG', variable: 'KUBECONFIG')]) {
            def kubectl
               kubectl = "kubectl --kubeconfig=${KUBECONFIG} --context=demo"
               echo 'deployment to PRERELEASE!'
               sh "kubectl config get-contexts"
               sh "kubectl -n demo get pods"
               sh  "${kubectl} apply -f ./environment/pre-release -n=pre-release"
               } 
            }
            }
    }

Please find the below jenkins outputs

/home/jenkins/agent/workspace/DevOps-CI_future-master-fix
[Pipeline] stage
[Pipeline] { (Deploy)
[Pipeline] container
[Pipeline] {
[Pipeline] withCredentials
Masking supported pattern matches of $KUBECONFIG
[Pipeline] {
[Pipeline] echo
deploy to deployment!!
[Pipeline] echo
deploy to PRERELEASE!
[Pipeline] sh
+ kubectl config get-contexts
CURRENT   NAME                          CLUSTER      AUTHINFO           NAMESPACE
*         demo                          kubernetes   kubernetes-admin   demo
          kubernetes-admin@kubernetes   kubernetes   kubernetes-admin   
[Pipeline] sh
+ kubectl -n demo get pods
NAME                                                      READY   STATUS    RESTARTS   AGE
worker-f99adee3-dedd-46ca-bc0d-6b24391e5865-qkd47-mwl3v   5/5     Running   0          26s
[Pipeline] sh
+ kubectl '--kubeconfig=****' '--context=demo' apply -f ./environment/pre-release '-n=pre-release'
deployment.apps/frontend-deploy unchanged
service/frontend unchanged
[Pipeline] }
[Pipeline] // withCredentials
[Pipeline] }
[Pipeline] // container
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] }
[Pipeline] // podTemplate
[Pipeline] End of Pipeline
Finished: SUCCESS

Now the questions is after the deployment i am not able to see the pods and deployment in both machine master machine using below command, can you please some one help me how to access the application after the successful deployment .

kubectl get pods
kubectl get services
kubectl get deployments
-- Anonymuss
jenkins
kubernetes

2 Answers

1/16/2020

You are creating the resources in a namespace called pre-release using -n option when you run the following command.

kubectl '--kubeconfig=****' '--context=demo' apply -f ./environment/pre-release '-n=pre-release'
deployment.apps/frontend-deploy unchanged

You need to to list the resources in the same namespace.

kubectl get pods -n pre-release
kubectl get services -n pre-release
kubectl get deployments -n pre-release

By default kubectl will do the requested operation in default namespace. If you want to set your current namespace to pre-release so that you need not append -n pre-release with every kubectl command, you can run the following command:

kubectl config set-context --current --namespace=pre-release
-- Shashank V
Source: StackOverflow

1/16/2020

You're setting the namespace to pre-release when running "${kubectl} apply -f ./environment/pre-release -n=pre-release".

To get pods in this namespace, use: kubectl get pods -n pre-release.

Namespaces are a way to separate different virtual clusters inside your single physical Kubernetes cluster. See https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/ for more detail.

-- AMargheriti
Source: StackOverflow