Custom Kubernetes manifest

Kubernetes manifests are used to create, modify and delete Kubernetes resources such as pods, deployments, services or ingresses.

Microtica enables you to define custom Kubernetes manifests and apply them automatically through Microtica Portal and get the full visibility of the deployed resources from Microtica Kubernetes dashboard.

For Microtica to be able to process the custom manifest you need to add a file named as kube.config in the root path of your source code.

The kube.config contains the specification of Kubernetes resources to be applied in the cluster.

Here is an example of a custom Kubernetes manifest:

kube.config

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-nginx
spec:
  selector:
    matchLabels:
      run: my-nginx
  replicas: 2
  template:
    metadata:
      labels:
        run: my-nginx
    spec:
      containers:
      - name: my-nginx
        image: nginx
        ports:
        - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: my-nginx
  labels:
    run: my-nginx
spec:
  ports:
  - port: 80
    protocol: TCP
  selector:
    run: my-nginx

The above manifest when applied through Microtica, will create two Kubernetes resources, a deployment and a service.

In the manifest you can define any type of resources either built-in or custom resources.

Make sure that resources defined in the manifest and their respective versions are already available on the cluster you deploy the service, otherwise the service deployment will fails with errors.

#When to use custom manifests

To deploy a Kubernetes service with Microtica, you don’t need to worry about the integration with Kubernetes nor to write any custom Kubernetes spec to describe the deployment, replica sets, service etc. this is already provided by default.

You can take your existing Docker image and deploy to a Kubernetes cluster with no additional coding or writing custom deployment scripts.

You can use custom manifests when:

  • your service requires a specify configuration for scaling
  • custom liveness probes
  • custom ingresses
  • using custom Kubernetes resources
  • deploying full solution that runs on Kubernetes (e.g. Ambassador API gateway)

#Manifest change detection

When applying manifests with tools such as kubectl you need to manually remove the resources that ware removed from the manifest, the apply function will not do that automatically.

Microtica automates the process of adding, modifying, deleting resources on subsequent deployments by keeping track of the current deployed spec on your cluster so when you do the next deployment Microtica does comparison of resources and automatically removes the resources that does not exist in the spec being deployed.

#Manifest templating

Kubernetes does not provide a built-in support for templating so you need to use additional tools to achieve that.

Microtica provides a built-in support for Kubernetes manifest templating when you need to deploy a dynamic and reusable manifests.

You can reference environment variables in the manifest by using {{variable-name}} syntax.

kube.config

apiVersion: v1
kind: Service
metadata:
  name: "{{SERVICE_NAME}}"
  labels:
    run: "{{SERVICE_NAME}}"
spec:
  ports:
  - port: "{{PORT}}"
    protocol: TCP
  selector:
    run: "{{SERVICE_NAME}}"

In this case, we are referencing the environment variables provided while deploying the service. Variables will be replaced before the manifest is being applied on Kubernetes.

Usage syntax

Always put variables in quotation marks to avoid any deployment errors.