Sunstone - simple templates for Kubernetes and beyond
Tags: showdev, kubernetes, devops, productivity
Published: 2019-11-19 16:33:36

---
title: Sunstone - simple templates for Kubernetes and beyond
published: true
description: Sunstone allows to render templates without CLI, use simple curl, wget or any other HTTP client
tags: showdev, kubernetes, devops, productivity
cover_image: https://thepracticaldev.s3.amazonaws.com/i/x6837933n10yvyjsp73z.png
---

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](https://about.sunstone.dev) 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](https://dotscience.com/) 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
   ```

Kubernetes deployment page in [dotscience.com deployers page](https://cloud.dotscience.com/deployers):

![Deployer install via Sunstone](https://thepracticaldev.s3.amazonaws.com/i/ydp85bocyutqafmjityh.png)

## 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:

```yaml
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    

```

(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>
```

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:

```yaml
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    
```

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:

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

...
```

`kubectl` allows to install directly from this URL:

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



## 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:

```bash
kubectl apply -f https://sunstone.dev/keel
```

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

Clicking "Install" on any:

![Install button on Sunstone generates linsk](https://thepracticaldev.s3.amazonaws.com/i/bnr6lv0xhhykgkrnq1yw.png)

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

![Entering variables updates the render link](https://thepracticaldev.s3.amazonaws.com/i/aec0tw523sl76mrhx5og.gif)

# Next steps

* Check out Sunstone template docs: https://about.sunstone.dev/examples/#latest-docker-semver-tag
* Not yet documented, but you can check out private repositories (requires login with GitHub just for authentication, no access to repos): https://apps.sunstone.dev/private-repositories
* Accompanying GitHub action to automatically update your private alias on Sunstone when you push to that repo: https://github.com/marketplace/actions/sunstone-template-update


# 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.