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.

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay