How to create Kubernetes manifests
In part 1 of this series we have created a container image that includes a Vue application. This part now describes how that container can be deployed in a Kubernetes environment. For a detailed description of what kubernetes does and why we use it see the relevant explanation here.
Similar to how containers should not be fine-tuned to our infrastructure and could be reused by others, the manifests that are created in this guide are also intended to be general.
Goal
After following this guide, you will have a series of Kubernetes manifests that describe how the application is deployed.
Prerequisites
This guide assumes that you already have a working container image for your application. Additionally your app should only respond to HTTP traffic without requiring any backing services like databases or persistent storage.
1) Create a deployment
First we create a deployment which manages the lifecycle of our container.
To do that create the file .k8s/deployment.yml
in your app folder.
Reading the Kubernetes documentation about describing objects and about deployments as well as referencing the list of available deployment manifest fields will help you understand how the manifest file is structured and what the used fields do.
Info
We generally prefer to keep files that are not directly part of the application source code and which are only
required as part of kubernetes manifests inside the .k8s
folder.
2) Create a service
In addition to the deployment our app also needs a service to route traffic to the created containers.
The relevant Kubernetes documentation is the one about services and the list of available service manifest fields.
.k8s/service.yml | |
---|---|
3) Bundle manifests together
At this point all strictly required manifests exist, but we still want to bundle them together so that they can be applied as one.
To do that, we create a kustomization.yml
file.
It is the configuration file of kustomize, and you should see the kustomization reference about the used fields.
kustomization.yml | |
---|---|
What this file achieves is the following:
- Bundle the manifests together
- Add the label defined via
commonLabels
to all resources as well as all relevant resource selectors