DEV Community

Cover image for Sunstone - simple templates for Kubernetes and beyond
Karolis
Karolis

Posted on

Sunstone - simple templates for Kubernetes and beyond

Sunstone is an easy to use, no-CLI solution to create templates that work with plain curl. It's targeted at users that need some templating functionality but don't want to use tools like Helm that need their own registries, directory structures and update mechanisms.

Currently Sunstone is targeted at Kubernetes users but there's actually no restriction or issues when using it with any other tools (it doesn't really care whether templates are Kubernetes manifests or Docker Compose files or anything else).

Project goals:

  • Users host templates on their own infrastucture that is reachable from Sunstone (GitHub, GitLab, S3, NGINX static file server).
  • Easy to use and open alias system where users can share their own templates. We could potentially allow hub yaml manifest to point to other hubs and discover aliases from them.
  • When fetch is not possible, user can create and update private repo in the Sunstone via curl or a specialized Docker container (currently works as a GitHub action but a standalone instructions will be available) that can be included as a CI step.
  • Dead simple installation instructions for your docs. For example, to install a Dotscience ML model deployment operator for your user account, it's as simple as:
   kubectl apply -f https://sunstone.dev/dotscience?token=my-super-secret-token
Enter fullscreen mode Exit fullscreen mode

Kubernetes deployment page in dotscience.com deployers page:

Deployer install via Sunstone

Example 1: Remote template

Here we have a template hosted on GitHub at: https://github.com/sunstone-dev/example/blob/master/deployment.yaml. Contents are:

apiVersion: apps/v1
kind: Deployment
metadata: 
  name: pushwf  
  labels: 
    name: "pushwf"
spec:
  replicas: 1
  revisionHistoryLimit: 5
  selector:
    matchLabels:
      app: pushwf
  template:
    metadata:
      name: pushwf
      labels:
        app: pushwf
    spec:     
      containers:                    
        - image: keelhq/push-workflow-example:{{ .version | latestRegistrySemver "keelhq/push-workflow-example" }}
          imagePullPolicy: Always
          name: pushwf
          ports:
            - containerPort: {{ .port | default 8500 }}
          livenessProbe:
            httpGet:
              path: /
              port: {{ .port | default 8500 }}
            initialDelaySeconds: 10
            timeoutSeconds: 5    

Enter fullscreen mode Exit fullscreen mode

(raw link is: https://raw.githubusercontent.com/sunstone-dev/example/master/deployment.yaml)

Have a look at {{ .version | latestRegistrySemver "keelhq/push-workflow-example" }}, this latestRegistrySemver template tag will actually go to that registry and retrieve the latest semver tag from the registry :) No need to update your docs when a new semver image tag is released!

Now, to render a template we need to know that Sunstone template generator API works like this:

https://sunstone.dev/<URL to link but without https>?<first arg>=<value>&<second arg>=<value>
Enter fullscreen mode Exit fullscreen mode

So, to render our example template with default values, use:

https://sunstone.dev/raw.githubusercontent.com/sunstone-dev/example/master/deployment.yaml

Result should look like:

apiVersion: apps/v1
kind: Deployment
metadata: 
  name: pushwf  
  labels: 
    name: "pushwf"
spec:
  replicas: 1
  revisionHistoryLimit: 5
  selector:
    matchLabels:
      app: pushwf
  template:
    metadata:
      name: pushwf
      labels:
        app: pushwf
    spec:     
      containers:                    
        - image: keelhq/push-workflow-example:0.11.0-alpha
          imagePullPolicy: Always
          name: pushwf
          ports:
            - containerPort: 8500
          livenessProbe:
            httpGet:
              path: /
              port: 8500
            initialDelaySeconds: 10
            timeoutSeconds: 5    
Enter fullscreen mode Exit fullscreen mode

If you add ?port=999 to the URL:

https://sunstone.dev/raw.githubusercontent.com/sunstone-dev/example/master/deployment.yaml?port=9999

Endpoint will show you different container port:

...
    ports:
            - containerPort: 8500
          livenessProbe:
            httpGet:

...
Enter fullscreen mode Exit fullscreen mode

kubectl allows to install directly from this URL:

https://sunstone.dev/raw.githubusercontent.com/sunstone-dev/example/master/deployment.yaml?port=9999
Enter fullscreen mode Exit fullscreen mode

Example 2: Using aliases

Constructing whole URL is usually quite difficult to remember, that's why we have a public aliases "hub" that allows everyone to map their own shorter aliases to remote repositories. Hub repository can be found here: https://github.com/sunstone-dev/hub. If you would like to contribute your own template, just fork it and submit a pull request.

To install from alias, it becomes as simple as:

kubectl apply -f https://sunstone.dev/keel
Enter fullscreen mode Exit fullscreen mode

And you can also view all public aliases here: https://apps.sunstone.dev/dashboard

Clicking "Install" on any:

Install button on Sunstone generates linsk

Entering into variable fields will automatically generate your template render URL:

Entering variables updates the render link

Next steps

Tech stack

  • Golang for the backend (API, templating)
  • Vue.js
  • Database - Firestore on GCP
  • Running on GKE

P.S.

Sunstone templating API will be Open Source (still need to do some work to separate it from the current multi-tenant service) so you will be able to just host it anywhere. It might be possible to also run it via Cloud Run or similar services.

Discussion (0)