# Tips on Using Templating with K3s in KURL

**URL:** <https://community.replicated.com/t/tips-on-using-templating-with-k3s-in-kurl/931>\
**Category:** Packaging an application\
**Tags:** kots, kurl, troubleshoot, k3s, distribution\
**Created:** [August 22, 2022, 11:52am UTC](https://community.replicated.com/t/tips-on-using-templating-with-k3s-in-kurl/931 "2022-08-22T11:52:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fernando\_Cremer](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.replicated.com/fernando_cremer/32/436_2.png) [@Fernando\_Cremer](https://community.replicated.com/u/Fernando_Cremer)\
**Post date:** [August 22, 2022, 11:52am UTC](https://community.replicated.com/t/tips-on-using-templating-with-k3s-in-kurl/931/1 "2022-08-22T11:52:19Z")

</div>

As you may know, we recently started to look at supporting [k3s](https://k3s.io/) and [rke2](https://docs.rke2.io/) to our [kURL](https://kurl.sh/) open source project.

We recently switched our [labs](https://github.com/replicatedhq/kots-field-labs) to use K3s and I was curious how the [Distribution](https://docs.replicated.com/reference/template-functions-license-context#sequence) license context template function and the [Kubernetes Distribution](https://troubleshoot.sh/docs/analyze/distribution/) analyzer would work in this scenario.

First, I used the following kURL spec:

```nohighlight
apiVersion: kurl.sh/v1beta1
kind: Installer
metadata:
  name: 'myapp'
spec: 
  k3s: 
    version: "v1.23.3+k3s1"
  registry: 
    version: "latest"
  kotsadm: 
    version: "latest"
    uiBindPort: 30880
    disableS3: true

```

To test the [Distribution](https://docs.replicated.com/reference/template-functions-license-context#sequence) license context template function, I added the following [label](https://docs.replicated.com/reference/custom-resource-config#label) config item:

```nohighlight
apiVersion: kots.io/v1beta1
kind: Config
metadata:
  name: example-config
spec:
  groups:
    - name: example_settings
      title: My Example Config
      description: Configuration to serve as an example for creating your own. See [https://kots.io/reference/v1beta1/config/](https://kots.io/reference/v1beta1/config/) for configuration docs. In this case, we provide example fields for configuring an Ingress object.
      items:
      - name: dist
        type: label
        title: "You are Deploying to 'repl{{ Distribution}}'"

```

Here is the result:

 ![Screen Shot 2022-08-21 at 10.20.04 PM](https://canada1.discourse-cdn.com/flex030/uploads/replicated/original/1X/d265f9a6e57fcc60e418678355e9e1c1798b998f.png)

As you can see, the [Distribution](https://docs.replicated.com/reference/template-functions-license-context#sequence) license context template function resolves to `k3s`.

Next, what if I want to make sure my application is NOT deployed to k3s? For this we look at the [Kubernetes Distribution](https://troubleshoot.sh/docs/analyze/distribution/) analyzer.

I first added this preflight spec:

```nohighlight
apiVersion: troubleshoot.sh/v1beta2
kind: Preflight
metadata:
  name: example-preflight-checks
spec:
  analyzers:
    - distribution:
        outcomes:
          - fail:
              when: "== docker-desktop"
              message: The application does not support Docker Desktop clusters.
          - fail:
              when: "== microk8s"
              message: The application does not support MicroK8s clusters.
          - fail:
              when: "== minikube"
              message: The application does not support minikube clusters.
          - pass:
              when: "== kurl"
              message: kURL is a supported distribution.      
          - fail:
              when: "== k3s"
              message: K3S is a supported distribution.      
          - pass:
              when: "== eks"
              message: EKS is a supported distribution.
          - pass:
              when: "== gke"
              message: GKE is a supported distribution.
          - pass:
              when: "== aks"
              message: AKS is a supported distribution.
          - warn:
              message: Unable to determine the distribution of Kubernetes.

```

The above preflight ends up passing:

 ![Screen Shot 2022-08-21 at 10.21.01 PM](https://canada1.discourse-cdn.com/flex030/uploads/replicated/original/1X/5f605192bd6b7355d8317ea0282246103684d2b9.png)

However, if you put K3s first like so:

```nohighlight
apiVersion: troubleshoot.sh/v1beta2
kind: Preflight
metadata:
  name: example-preflight-checks
spec:
  analyzers:
    - distribution:
        outcomes:
          - fail:
              when: "== docker-desktop"
              message: The application does not support Docker Desktop clusters.
          - fail:
              when: "== microk8s"
              message: The application does not support MicroK8s clusters.
          - fail:
              when: "== minikube"
              message: The application does not support minikube clusters.         
          - fail:
              when: "== k3s"
              message: K3S is a supported distribution.
          - pass:
              when: "== kurl"
              message: kURL is a supported distribution.       
          - pass:
              when: "== eks"
              message: EKS is a supported distribution.
          - pass:
              when: "== gke"
              message: GKE is a supported distribution.
          - pass:
              when: "== aks"
              message: AKS is a supported distribution.
          - warn:
              message: Unable to determine the distribution of Kubernetes.

```

This time we see the result we were looking for (I forgot to update the message):

 ![Screen Shot 2022-08-22 at 7.48.15 AM](https://canada1.discourse-cdn.com/flex030/uploads/replicated/original/1X/fd358bc944f81eab3bb7d6b4714cb633b45d61da.png)

Based on these results, looks like when we use the `analyzer` it returns `true` for both `KURL` and `k3s`. Also, based on the results, you can see that the order each `outcome` matters. The reason is that as the [docs](https://troubleshoot.sh/docs/analyze/outcomes/) state:

`Outcomes are evaluated in order until one returns true for the analyzer. Once an outcome returns true, no additional outcomes are evaluated for the analyzer. This allows you to write outcomes as you would a "select" or "switch" statement when programming. If there is no when attribute on an outcome, it will always return true when executed and be the displayed result.`

So in our case, since we wanted to fail on k3s (regardless of how it was deployed) we put it before any distribution we would pass, like KURL). A good reminder when working with analyzers in general with multiple conditions to be evaluated for an outcome.

---

<div class="post-metadata">

**Author:** ![Fernando\_Cremer](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.replicated.com/fernando_cremer/32/436_2.png) [@Fernando\_Cremer](https://community.replicated.com/u/Fernando_Cremer)\
**Post date:** [August 22, 2022, 7:10pm UTC](https://community.replicated.com/t/tips-on-using-templating-with-k3s-in-kurl/931/2 "2022-08-22T19:10:27Z")

</div>

Worth noting that if you would like to determine if the k3s cluster was deployed by Kurl or not, you still have the [IsKurl](https://docs.replicated.com/reference/template-functions-static-context#iskurl) Static Context. For example, if we add another label to our Config like this:

```nohighlight
apiVersion: kots.io/v1beta1
kind: Config
metadata:
  name: example-config
spec:
  groups:
    - name: example_settings
      title: My Example Config
      description: Configuration to serve as an example for creating your own. See [https://kots.io/reference/v1beta1/config/](https://kots.io/reference/v1beta1/config/) for configuration docs. In this case, we provide example fields for configuring an Ingress object.
      items:
      - name: dist
        type: label
        title: "You are Deploying to 'repl{{ Distribution}}'"
      - name: is-kurl
        type: label
        title: "Provided to you by kURL"
        when: 'repl{{ IsKurl }}'

```

It will be rendered like this:

 ![Screen Shot 2022-08-22 at 3.10.18 PM](https://canada1.discourse-cdn.com/flex030/uploads/replicated/original/1X/e6d0033a03e487519df9f2139f05396544b1f55e.png)
