Is it possible to combine small Kubernetes configurations to a big one

6/27/2018

I have a nested maven project structure, several of the Maven Artefacts contains also Kubernetes configurations, when I do the complete deployment of the projects, I want to combine all Kubernetes configuration and run it centrally.

It is something like Spring Application Context 'import' statements, of course I can take this small configurationx and copy/paste to one big file but then I have to maintain changes at 2 different places, which I don't want to...

I can't find an 'import' mechanism similar to Spring one in Kubernetes documentation, I can write something with Maven and Groovy, to combine all these small configuration files to one big one, but that some direction I really don't want to go.

Code Snippet from a configuration would be something like this..

kind: Deployment
apiVersion: apps/v1beta2
metadata:
 name: apimanagementstore-deployment
 namespace: api-management
spec:
  replicas: 1
  selector:
   matchLabels:
    k8s-app: api-management-store
  template:
   metadata:
    labels:
     k8s-app: api-management-store
   spec:
    containers:
    - name: apimanagementstore
      image: localhost:5000/api_management_store
      ports:
      - containerPort: 8383
        protocol: TCP

---
#------------ Service ----------------#

kind: Service
apiVersion: v1
metadata:
 labels:
  k8s-app: api-management-store
 name: api-management-store
 namespace: api-management
spec:
 ports:
  - port: 8383
    targetPort: 8383
 selector:
  k8s-app: api-management-store

 

I have several snippets (they all lie under a seperate Maven Project) like this and I want to combine those to one big one.

-- posthumecaver
kubernetes

1 Answer

6/27/2018

There is no option to use something like include in Kubernetes right now. Maybe in the future, they will add such an option.

You are right that you can create one big file and use '---' delimiters for each new configuration.

However, you also have another option: use -f key, for example:

kubectl apply -f ./file1 ./file2 ./file3 etc 

For more details please refer to Kubernetes documentation

-- VKR
Source: StackOverflow