Is there any tool to automate K8s manifests creation?

12/12/2021

I find it "a bit" boring to create K8s manifests for services that I want to deploy. Typically, for an app, a set of manifests as follows is needed:

  • deployment
  • service
  • ingress
  • configMap
  • secret

I think there must be some tool that automates the generation of such templates, probably some CLI program that goes through a series of questions-and-answers to generate final manifests. I would imagine that it could also be a bit framework-specific, so it'd be able to generate configMaps based on .NET's appsetting.json or node's .env files.

I tries to find something like that on Google, but possibly I'm using wrong keywords. Is there anything as I described?

-- mnj
automation
kubernetes

1 Answer

12/12/2021

Solution 1

Kubernetes supports generating manifests for some resource types. Here is the full list: https://kubernetes.io/docs/reference/kubectl/conventions/#generators

You can get the usage of each resource by;

kubectl create <resource-name> -h

Then you can use;

kubectl create --dry-run=client -o yaml <resource-name> [ARGS]

Such as for deployment;

kubectl create --dry-run=client -o yaml deployment NAME --image=image

eg:

$ kubectl create --dry-run=client -o yaml deploy nginx-deploy --image nginx

apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    app: nginx-deploy
  name: nginx-deploy
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx-deploy
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: nginx-deploy
    spec:
      containers:
      - image: nginx
        name: nginx
        resources: {}
status: {}

Solution 2

If you need more sophisticated solution, you can have a look at Helm, Kustomize and Ansible Operator.

Some further information for each:

Helm:
https://helm.sh/docs/intro/quickstart

Kustomize:
https://kustomize.io

Ansible Operator:
https://sdk.operatorframework.io/docs/building-operators/ansible/tutorial

-- Akif
Source: StackOverflow