Skip to content

Commit

Permalink
k3s/longhorn: deploy using helm instead of kubectl
Browse files Browse the repository at this point in the history
If we use helm to deploy Longhorn, we don't need to manually parse tags from
the github API to figure out what the latest released version is - it will
simply install the latest version by default.

Signed-off-by: Tim Serong <[email protected]>
  • Loading branch information
tserong committed Apr 20, 2023
1 parent 077ec60 commit a3f5bf1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 28 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -581,11 +581,10 @@ install the latest stable version of Longhorn:
$ sesdev create k3s --deploy-longhorn
```

To deploy a specific version of Longorn, use the `--longhorn-version` option
to specify a tag name from https://github.com/longhorn/longhorn/tags, e.g.:
To deploy a specific version of Longorn, use the `--longhorn-version` option:

```
$ sesdev create k3s --deploy-longhorn --longhorn-version=v1.4.1
$ sesdev create k3s --deploy-longhorn --longhorn-version=1.4.1
```

Currently Longhorn deployments will only use _one_ disk. If more are
Expand Down
2 changes: 1 addition & 1 deletion sesdev/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,7 @@ def caasp4(deployment_id, **kwargs):
@click.option("--deploy-longhorn", is_flag=True, default=False,
help="Deploy Longhorn on k3s")
@click.option("--longhorn-version", default=None,
help='Longhorn version to install, e.g. "v1.4.1" (defaults to latest stable)')
help='Longhorn version to install, e.g. "1.4.1" (defaults to latest stable)')
@click.option("--k3s-version", default=None,
help='k3s version to install (defaults to latest stable)')
def k3s(deployment_id, **kwargs):
Expand Down
34 changes: 10 additions & 24 deletions seslib/templates/k3s/provision.sh.j2
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ helm version
# by default, which of course won't work.
echo "export KUBECONFIG=/etc/rancher/k3s/k3s.yaml" >> /etc/profile.local

# The earlier addition of KUBECONFIG to /etc/profile.local won't help
# us in this current session, so also need to set it explicitly here.
export KUBECONFIG=/etc/rancher/k3s/k3s.yaml

{% if k3s_deploy_ses %}

mkdir -p ~/cluster
Expand All @@ -99,9 +103,6 @@ tar -xzf rook-ceph-*.tgz

kubectl create namespace rook-ceph

# The earlier addition of KUBECONFIG to /etc/profile.local won't help
# us in this current session, so need to set it explicitly here.
export KUBECONFIG=/etc/rancher/k3s/k3s.yaml
helm install -n rook-ceph rook-ceph ./rook-ceph/

echo "Waiting for the rook operator"
Expand All @@ -123,30 +124,15 @@ kubectl create -f rook-ceph/examples/toolbox.yaml

{% if k3s_deploy_longhorn %}

{% if longhorn_version %}
longhorn_version={{ longhorn_version }}
{% else %}
longhorn_version=$(
curl -sL \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version:2022-11-28" \
https://api.github.com/repos/longhorn/longhorn/releases | \
jq -r '.[].tag_name' | \
grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | \
sort --version-sort --reverse | \
head -n 1
)
{% endif %}

curl -sSfL https://raw.githubusercontent.com/longhorn/longhorn/${longhorn_version}/scripts/environment_check.sh | bash

curl -sSLO https://raw.githubusercontent.com/longhorn/longhorn/${longhorn_version}/deploy/longhorn.yaml

# Make longhorn create default disks on all nodes that aren't the master
sed -i '/default-setting\.yaml: |-/a \ \ \ \ create-default-disk-labeled-nodes: true' longhorn.yaml
kubectl label node -l 'node-role.kubernetes.io/master!=true' node.longhorn.io/create-default-disk=true

kubectl apply -f longhorn.yaml
helm repo add longhorn https://charts.longhorn.io
helm repo update
helm install longhorn longhorn/longhorn \
--namespace longhorn-system \
--create-namespace {{ "--version {}".format(longhorn_version) if longhorn_version }} \
--set defaultSettings.createDefaultDiskLabeledNodes=true

# On k3s this just gives a traefik ingress for the UI with no authentication
echo "
Expand Down

0 comments on commit a3f5bf1

Please sign in to comment.