Deploying Magento project using GKE on jenkins

3/17/2021

I've recently used google Kubernetes engine to deploy my magento project and i successfully deployed it. and my next step was in each git push my jenkins pipeline will start building and update the project in my kubernetes cluster. i've been looking for tutorials but i got no documentation about how to run kubectl in jenkins with my GKE credentials. if anyone is familiar with this kind of task and have any reference please help me.

-- nessHaf
google-kubernetes-engine
jenkins
kubernetes
magento

1 Answer

3/31/2021

Actually you're asking for this question

how to run kubectl in jenkins with my GKE credentials

In a research of how you can manage it I found this tutorial about Setting up CI/CD for GKE with Jenkins which contains the steps in order to build an update the project. You can also take a look for whole tutorial, might help you with your project.<br> But we're going to check the part where it says Jenkins Job Build; you'll find the authentication method and getting the credentials for cluster:

#To activate creds for the first time, can also be done in Jenkins machine directly and get credentials for kubectl

gcloud auth activate-service-account account_name --key-file [KEY_FILE]

#Get credentials for cluster

gcloud container clusters get-credentials <cluster-name> --zone <zone-name> --project <project-name>

And also, deploying it to the project:

#To create new deployment

kubectl create deployment <deployment-name> --image=gcr.io/<project-name>/nginx:${version}

#For rolling update

kubectl set image deployment/<app_name> nginx=gcr.io/<project-name>/<appname>/nginx:${version} --record
-- Sergio NH
Source: StackOverflow