Cloud Concept Limited Logo

Local development setup using kubernetes

docker
Neil Tomlinson
#microservices#kubernetes#skaffold#howto

Introduction

In my last post I showed a development setup with front end html and a dotnet webapi using docker compose. In this article I will build a front end single page application(SPA) with a web api back end in isolated containers. the containers will run in a local kubernetes cluster using Minikube and Skaffold. Tools required

Setting the scene

This is another post about trying to create a development setup with the least amount of friction between teams but additionally I want something that is more like a replica of the production environment.

The Tools

Kubectl

Command line used to access, configure and manage a kubernetes cluster.

Kubectl setup instructions are here: Kubectl.

MiniKube

Minikube is our local kubernetes cluster.

Minikube setup instructions are here: Minikube.

It will run the cluster in a virtual machine so we need to have a hyper visor installed; I am using KVM.

Skaffold

From the Skaffold github repo

Skaffold is a command line tool that facilitates continuous development for Kubernetes applications. You can iterate on your application source code locally then deploy to local or remote Kubernetes clusters

Skaffold setup instructions are here.

Kubernetes

From the Kubernetes(k8s) site:

Kubernetes (K8s) is an open-source system for automating deployment, scaling, and management of containerized applications

We will use kubernetes to run our containers and manage the routing of traffic to those containers.

Sample code

We can clone the sample repository.

git clone https://github.com/nptomlin/skaffold-n-tier.git

A summary of the downloaded directory looks like this:

skaffold-n-tier
├── src
│   ├── edge-api
│   │   ├── k8s
│   │   └── Dockerfile
│   ├── main-spa
│   │   ├── k8s
│   │   └── Dockerfile
│   └── ingress.yaml
└── skaffold.yaml

Directory Contents

Running

Start the cluster

Startup minikube and enable ingress.

minikube start --vm-driver kvm2
minikube addons enable ingress

Deploy the application

We can deploy the application with:

skaffold dev

Builds and runs the containers in the kubernetes and watches for file changes.

Now in a seperate terminal

minikube ip

This will show the ip of the local kubernetes cluster if this was 192.168.39.175 use it to in your browser to navigate https://192.168.39.175/

** Note

You may need to accept the https warning temporarily.

Skaffold is using kubernetes to build and run our containers

kubectl get svc

This shows our services running in the cluster.

Also we have an ingress controller which fans out / and /api calls and directs them to the service that can handle them.

To stop the application: Hit Ctrl+c in your console window.

How is this configured

We can take a look at the skafold.yaml to see how the containers are configured.

apiVersion: skaffold/v1beta7
kind: Config
build:
  artifacts:
  - image: angular-nginx
    context: src/main-spa
  - image: edge-api
    context: src/edge-api
deploy:
  kubectl:
    manifests:
    - "src/**/k8s"
    - "src/ingress.yaml"

This builds the main-spa and the edge-api and deploys the all the configuration files in the k8s directories and the ingress.yaml. ingress

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: edge-ingress
  namespace: default
spec:
  rules:
  - http:
      paths:
      - path: /api
        backend:
          serviceName: edge-api-gateway
          servicePort: 80
      - path: /
        backend:
          serviceName: angular-app-gateway
          servicePort: 80(myenv)

Next steps

My set-up is far from production ready we need to setup logging and health and health monitoring.

In production kubernetes would be a cluster with multiple nodes and so the containers that are built should be pushed to a container repository that is visible to all the nodes in the kubernetes cluster.

Additional Tools

To run the sample nothing else should be required but for local development I am using

dotnet core 2.2.105
node 10.15.3
angular cli version 7.3.5
← Back to Blog