Unique service names for gitlab auto devops

6/30/2019

While using gitlab auto devops I notice each project being created in its own namespace, defining the service name as production-auto-deploy.

$kubectl get services --all-namespaces

NAMESPACE                NAME                                     TYPE           CLUSTER-IP       EXTERNAL-IP      PORT(S)                      AGE
app-13094854             production-auto-deploy                   ClusterIP      10.245.23.224    <none>           5000/TCP                     11h
app-13094854             production-postgres                      ClusterIP      10.245.202.205   <none>           5432/TCP                     11h
config-server-13051179   production-auto-deploy                   ClusterIP      10.245.138.49    <none>           5000/TCP                     40m
default                  kubernetes                               ClusterIP      10.245.0.1       <none>           443/TCP                      11h
gitlab-managed-apps      ingress-nginx-ingress-controller         LoadBalancer   10.245.200.23    206.189.243.26   80:30888/TCP,443:30962/TCP   11h
gitlab-managed-apps      ingress-nginx-ingress-controller-stats   ClusterIP      10.245.104.211   <none>           18080/TCP                    11h
gitlab-managed-apps      ingress-nginx-ingress-default-backend    ClusterIP      10.245.202.171   <none>           80/TCP                       11h
gitlab-managed-apps      tiller-deploy                            ClusterIP      10.245.31.107    <none>           44134/TCP                    11h
kube-system              kube-dns                                 ClusterIP      10.245.0.10      <none>           53/UDP,53/TCP,9153/TCP       11h
some-microservice-13093883          production-auto-deploy                   ClusterIP      10.245.97.62     <none>           5000/TCP                     11h
some-microservice-13093883          production-postgres                      ClusterIP      10.245.245.253   <none>           5432/TCP                     11h

Can this service name be customized? For example I want it to include the project name thus mapping production-auto-deploy -> app-production-auto-deploy and some-microservice-production-auto-deploy.

The reason I want these service names to be unique is because I am evaluating spring-cloud-kubernetes and I need unique service names for ribbon discovery using feign clients.

Additionally I am wondering why each project is given its own namespace, is this some kind of best-practice? Can auto devops be configured to deploy all projects in the same namespace?

-- Wouter
gitlab
gitlab-ci
kubernetes
spring-cloud-kubernetes

1 Answer

7/1/2019

Can this service name be customized?

Yes, it can be, by using custom helm chart.

In simplification, service name is generated from two variables (Release name + Chart name)

printf "%s-%s" .Release.Name $name | trimSuffix "-app" ...

By default Auto DevOps uses its own helm chart, source code available here.

And by changing the 'name' inside Chart.yaml file (which contains chart's metadata), you can influence the final service name.

There is also another way to customize service name: by using overrides values to 'helm upgrade' command inside 'Deploy.gitlab-ci.yml' template with '--set nameOverride=<CUSTOM_SVC_NAME>'

Additionally I am wondering why each project is given its own namespace, is this some kind of best-practice? Can auto devops be configured to deploy all projects in the same namespace?

By default Auto Deploy uses this technique and naming convention for K8S namespaces during apps deployment (as described here), and there is no way to change it according official documentation.

You can try at your own risk to override it with use of custom project variable: KUBE_NAMESPACE

-- Nepomucen
Source: StackOverflow