DEV Community

Daniel Mita
Daniel Mita

Posted on

Building and Deploying a New API (Part 3)

Previous Post

Time to get into Kubernetes! I'm going to go through this process manually at first, in order to familiarize myself with some of the details, before I start involving tools such as Terraform and Helm.

I've explored Caddy in the past, and I'm highly fond of its automatic HTTPS and straightforward syntax, so part of this setup is going to be configuring Caddy to be used as a reverse proxy:

demo-api.dango.space, localhost {
        respond / "Hello, World!"
        respond /health-check 204
        reverse_proxy localhost:8080
}
Enter fullscreen mode Exit fullscreen mode

This will need to be available to our Caddy container. To do this we'll use the command kubectl create configmap. The Caddyfile can be used with the from-file flag and we can use the output flag to create our configmap.yaml file.

In our deployment.yaml file, we'll be adding the Caddy container.

- name: caddy
  image: caddy:2.9-alpine
  ports:
    - containerPort: 80
    - containerPort: 443
  volumeMounts:
    - name: caddyfile-volume
      mountPath: /etc/caddy/Caddyfile
      subPath: Caddyfile

    - name: caddy-data
      mountPath: /data
Enter fullscreen mode Exit fullscreen mode

The data directory needs to be persisted, so a PersistentVolume and PersistentVolumeClaim have been created to handle this.

In a later post I'll be taking a look at moving this over to an ingress controller.

Our demo-api image has been added to the deployment.yaml, and the ports opened up in our service.yaml. We have a cluster created on Digital Ocean, so we'll run kubectl apply to provision our resources. We'll obtain our external IP address with kubectl get services, add a new record to our domain, and we should be good to go!

https://demo-api.dango.space/

The state of the repository as of this post can be found here.

A link to the next part will be available once it is written.

Image of AssemblyAI

Automatic Speech Recognition with AssemblyAI

Experience near-human accuracy, low-latency performance, and advanced Speech AI capabilities with AssemblyAI's Speech-to-Text API. Sign up today and get $50 in API credit. No credit card required.

Try the API

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay