How to deploy multiple environment in Google Cloud Platform with Kubernetes and Gitlab CI/CD?

8/20/2018

I would like to deploy my projects (api rest, webapp, backoffice etc...) in several environments (dev, staging and production) with gitlab-ci, Kubernetes and Google Kubernetes Engine.

All projects are separated in gitlab repositories

I have 2 branch on gitlab : master and develop. Master must be deploy in staging and production environment Develop must be deploy in dev environment

I read multiple tutorials and blogs since 2 days but I didn't found what is the best approach to manage several environments with kubernetes.

I have to create 3 clusters in GKE (dev, staging, production) ? or I have to create just 1 cluster and use namespace to manage my environments ? or others solutions ?

1 / Create 3 clusters In gitlab-ci (free account), how can I deploy dev branch on dev cluster, master branch on staging/production cluster ? what will be the config to do it ? Can I set a specific cluster in gitlab-ci.yml ? How ? (kubectl config use-context ?

2 / Create 1 cluster and 3 namespace (dev,staging, production) I don't think that is the best approach for security and performance reason, right ?

Thanks

-- mikael
gitlab-ci
google-cloud-platform
google-kubernetes-engine
kubernetes

2 Answers

8/21/2018

I would like to deploy my projects (api rest, webapp, backoffice etc...) in several environments (dev, staging and production) with gitlab-ci, Kubernetes and Google Kubernetes Engine.

For each of those projects, I would be hosting them as individual git repository inorder to be able to deploy them individually.

I have 2 branch on gitlab : master and develop. Master must be deploy in staging and production environment Develop must be deploy in dev environment

In Kubernetes you would use namespaces to isolate different environments, each api would call other apis from same namespace. In Jenkins you can create multi-branch project to deploy each of these branches accordingly. YOu can also inject some kind of environment variable so each api know which environment it belongs to and for example, you can use resources like Datastore accordinly for example, Foo.Production.Kind1 vs Foo.Development.Kind1

1 / Create 3 clusters In gitlab-ci (free account), how can I deploy dev branch on dev cluster, master branch on staging/production cluster ? what will be the config to do it ?

2 / Create 1 cluster and 3 namespace (dev,staging, production) I don't think that is the best approach for security and performance reason, right ?

You can either 3 gcp Projects each for specific environment if costs are no issue (keep the same script across) or you could follow the above approach with just one cluster and distinguish them based on namespace and environment variables.

Has more details here: https://cloud.google.com/solutions/continuous-delivery-jenkins-kubernetes-engine

-- skjagini
Source: StackOverflow

2/4/2019

Q. I have to create 3 clusters in GKE (dev, staging, production) ? or I have to create just 1 cluster and use namespace to manage my environments ? or others solutions ?

Ans: Use one cluster and name namesapce them like dev, staging, production and it will be easy to manage .

-- Akhil gcp
Source: StackOverflow