How to Create an Authenticated API using zK8s

Alex
4 min readApr 21, 2023

--

In this tutorial, we will show you how to create and deploy a microservice API with secure HTTPS setup that includes authenticated access within 5 minutes.

Step 1. Define the Cluster.

I chose microservice as the cluster class and for the component base name and workload base name I choose to call them both api.

Step 2. Create a Deployment

I added a deployment and then set the replica count to 1. Next, I gave the container name api, and added the docker image name zeusfyi/microservice:latest. This docker image has two routes, one at “/health”, and the other at “/demo”. You can find the code for this on our GitHub page.

I added the docker startup command and args, added a resource requirement of 100m vCPUs and 100Mi memory and then added the http-api port at 9090.

Step 3. Add the Service file

You only need to add the service file since the UI will populate this for you from your docker file definitions in your StatefulSet or Deployment.

Step 4. Add the Ingress

Once you add the Ingress file, you just need to select which port you’d like exposed to your external API. In this tutorial we only had one port and so we’ll pick that one. You can leave the host and auth url sections as is. Your host url will get generated on demand as a https://uuid.zeus.fyi address, and by default it will grant access to the API key you can generate from the Access section of the website. If you have your own auth server then you can update this URL with your own value.

Step 5. Preview Configs and Register the Cluster

Once you’ve generated and inspected your configs you’ll be able to register the cluster definition and see the app on your app page.

Step 6. Deploy the App

Navigate to your app and click the row to visit the App deployment page.

Apps built via the UI and uploaded via API will show up in your app listing directory.

The deployment page will pre-filter appropriate servers for your workload using the vCPU and Memory requirements. Select an appropriate server and then add it with the + toggle button. You’ll then be able to deploy it.

If you don’t have any billing method setup you can still deploy up to one app as a free trial. If you don’t setup any billing within the hour it will automatically delete your app.

Once you’ve deployed your app you can see the status of it on the Clusters page.

The cm-acme solver is what is generating a valid HTTPS certificate for your API. It usually resolves within 15 minutes in most cases, and afterwards you’ll be able to send requests to it using your API key as the bearer token.

Step 7. Generate an API key if you don’t have one from the Access page.

Use this API key value as your bearer token and you’re all set!

If you’re using the demo value docker image you can curl the two endpoints below, just replace the UUID with your own value which you’ll find on the clusters page as your namespace value, and add your API key to verify you’ve set everything up correctly.

curl --location 'https://3d5c28a3-f983-4aa8-8a02-510bc2fd9c5a.zeus.fyi/health' \
--header 'Authorization: Bearer APIKEY'

Healthy

curl --location 'https://3d5c28a3-f983-4aa8-8a02-510bc2fd9c5a.zeus.fyi/demo' \
--header 'Authorization: Bearer APIKEY'

Sample Response A

Signup Below To Get Started:

You can deploy up to one cluster for free. Saving, reviewing, and building workloads is free.

https://cloud.zeus.fyi/signup

Checkout our GitHub

https://github.com/zeus-fyi/zeus

--

--

Alex

When no one can tell the difference between art, and an empty canvas, the meaning is lost.