Working with Manifest files

As much fun it is to work with Kubernetes in our terminal, in real world szenarios it makes life harder. For the sake of speed, reusalibily and consistancy, working with configuration files is recommended.

Manifest files are files in YAML or JSON format describing the desired state of your Kubernetes setup. So we can tell Kubernetes what we want and it handles the details of getting there for us. Also, other engineers in the team can later understand what exactly has been configured.

So lets get started with our first Manifest file. 🎉

In order to avoid confusion due to too many containers, lets first clean up our cluster. We can use kubectl commands for this, but Docker Desktop makes our life easier. So

  1. Open the Docker Desktop app and navigate to the settings (via the gearwheel on the top right).

  2. Klick on “Reset Kubernetes Cluster” and confirm you really want to reset.

While waiting for Docker Desktop to remove all resources we have set up to far in our cluster, we can start working on our Manifest.

Go to your terminal and create a new folder via

mkdir hello-world-app

CD into the folder and create a Manifest file:

cd hello-world-app
touch manifest.yaml

Add the following configuration to your manifest.yaml file:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello-world
  labels:
    app: hello-world-app
spec:
  replicas: 2
  selector:
    matchLabels:
      app: hello-world-app
  template:
    metadata:
      labels:
        app: hello-world-app
    spec:
      containers:
        - name: hello-world-app
          image: vtrhh/hello-world-app
          resources:
            requests:
              cpu: "100m"
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 3000

---
apiVersion: v1
kind: Service
metadata:
  name: hello-world
spec:
  selector:
    app: hello-world-app
  ports:
    - port: 3000
      targetPort: 3000
      protocol: TCP
  type: LoadBalancer

⚠️ If you are a linux user, please use the the following in line 19:

          image: vtrhh/hello-world-app:amd64

Apply your Manifest file via:

kubectl apply -f manifest.yaml

Kubernetes creates our deployment as well as our service and as specified, the deployment will start 2 containers running our application.

Our Service defines port 3000 as entry point for the outside world, so let’s have a look in our browser at http://localhost:3000. And there is our app :)

We can now play around with the deployment configurations in our Manifest file, e.g. changing the number of replicas or set the image of our container definition to “vtrhh/hello-world-app:v2” (or to “vtrhh/hello-world-app:v2-amd64” for Linux users). Please remember to always apply your changes via:

kubectl apply -f manifest.yaml

We can check on our new configurations in our browser or via running

kubectl get pods

in our terminal.