Skip to content

Commit

Permalink
Merge pull request s3gw-tech#38 from jecluis/wip-setup-k3s
Browse files Browse the repository at this point in the history
k3s: setup UX improvements
  • Loading branch information
jecluis authored May 10, 2022
2 parents be5d69d + 533f5ce commit 7ee2c79
Show file tree
Hide file tree
Showing 7 changed files with 492 additions and 26 deletions.
19 changes: 18 additions & 1 deletion k3s/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,25 @@ This README will guide you through the setup of a K3s cluster on your system.

# Setup

## Note Before

In some host systems, including OpenSUSE Tumbleweed, one will need to disable
firewalld to ensure proper functioning of k3s and its pods.

This is something we intend figuring out in the near future.

## From the internet

One can easily setup k3s with s3gw from the internet, by running

```
$ curl -sfL https://raw.githubusercontent.com/aquarist-labs/s3gw-core/main/k3s/setup.sh | sh -
```

## From source repository

To install a lightweight Kubernetes cluster for development purpose run
the following command. It will install open-iscsi and K3s on your local
the following commands. It will install open-iscsi and K3s on your local
system. Additionally, it will deploy Longhorn and the s3gw in the cluster.

```
Expand Down
78 changes: 78 additions & 0 deletions k3s/generate-spec.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/bin/bash
# generate-spec.sh - create spec files for a k3s cluster with longhorn and s3gw
# Copyright 2022 SUSE, LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

tgtfile="s3gw.yaml"
is_dev_env=false

s3gw_pod_yaml="s3gw-pod"

while [[ $# -gt 0 ]]; do
case $1 in
--output|-o)
tgtfile="${2}"
shift 1
;;
--dev)
s3gw_pod_yaml="s3gw-pod-dev"
;;
esac
shift 1
done

[[ -z "${tgtfile}" ]] && \
echo "error: missing output file" >&2 && \
exit 1

specs=(
"longhorn-ingress"
"longhorn-s3gw-secret"
"longhorn-storageclass"
"s3gw-namespace"
"s3gw-pvc"
${s3gw_pod_yaml}
"s3gw-service"
"s3gw-ingress"
)

d="$(date +'%Y/%M/%d %H:%m:%S %Z')"

cat > ${tgtfile} << EOF
# ${tgtfile} - setup a k3s cluster with longhorn and s3gw
# Copyright 2022 SUSE, LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# This file was auto-generated by generate-spec.sh on ${d}
#
EOF

has_prior=false
for spec in ${specs[@]}; do
${has_prior} && echo "---" >> ${tgtfile}
has_prior=true
cat ${spec}.yaml >> ${tgtfile}
done
161 changes: 161 additions & 0 deletions k3s/s3gw-dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
# s3gw-dev.yaml - setup a k3s cluster with longhorn and s3gw
# Copyright 2022 SUSE, LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# This file was auto-generated by generate-spec.sh on 2022/02/09 12:05:49 UTC
#

apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
name: stripprefix
namespace: longhorn-system
spec:
stripPrefix:
prefixes:
- /longhorn
forceSlash: false
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: longhorn-ingress
namespace: longhorn-system
annotations:
kubernetes.io/ingress.class: traefik
traefik.ingress.kubernetes.io/router.middlewares: longhorn-system-stripprefix@kubernetescrd
spec:
rules:
- http:
paths:
- pathType: Prefix
path: /longhorn
backend:
service:
name: longhorn-frontend
port:
number: 80
---
apiVersion: v1
kind: Secret
metadata:
name: s3gw-secret
namespace: longhorn-system
type: Opaque
data:
AWS_ACCESS_KEY_ID: MDU1NWIzNTY1NGFkMTY1NmQ4MDQ=
AWS_SECRET_ACCESS_KEY: aDdHaHh1QkxUcmxoVlV5eFNQVUtVVjhyLzJFSTRuZ3FKeEQ3aUJkQllMaHdsdU4zMEphVDNRPT0=
AWS_ENDPOINTS: aHR0cDovL3MzZ3ctc2VydmljZS5zM2d3LXN5c3RlbTo4MC8= # http://s3gw-service.s3gw-system:80/
---
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: longhorn-single
provisioner: driver.longhorn.io
allowVolumeExpansion: true
reclaimPolicy: Delete
volumeBindingMode: Immediate
parameters:
fsType: "ext4"
numberOfReplicas: "1"
staleReplicaTimeout: "2880"
fromBackup: ""

---
apiVersion: v1
kind: Namespace
metadata:
name: s3gw-system
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: s3gw-pvc
namespace: s3gw-system
spec:
accessModes:
- ReadWriteOnce
storageClassName: longhorn-single
resources:
requests:
storage: 2Gi

---
apiVersion: v1
kind: Pod
metadata:
name: s3gw
namespace: s3gw-system
labels:
app.aquarist-labs.io/name: s3gw
spec:
containers:
- name: s3gw
image: localhost/s3gw:latest
imagePullPolicy: Never
volumeMounts:
- name: s3gw-lh-store
mountPath: /data
ports:
- containerPort: 7480
name: s3gw-http
volumes:
- name: s3gw-lh-store
persistentVolumeClaim:
claimName: s3gw-pvc
---
apiVersion: v1
kind: Service
metadata:
name: s3gw-service
namespace: s3gw-system
spec:
selector:
app.aquarist-labs.io/name: s3gw
ports:
- name: s3gw-service-http
protocol: TCP
port: 80
targetPort: s3gw-http
---
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
name: stripprefix
namespace: s3gw-system
spec:
stripPrefix:
prefixes:
- /s3gw
forceSlash: false
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: s3gw-ingress
namespace: s3gw-system
annotations:
kubernetes.io/ingress.class: traefik
traefik.ingress.kubernetes.io/router.middlewares: s3gw-system-stripprefix@kubernetescrd
spec:
rules:
- http:
paths:
- path: /s3gw
pathType: Prefix
backend:
service:
name: s3gw-service
port:
number: 80
22 changes: 22 additions & 0 deletions k3s/s3gw-pod-dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: v1
kind: Pod
metadata:
name: s3gw
namespace: s3gw-system
labels:
app.aquarist-labs.io/name: s3gw
spec:
containers:
- name: s3gw
image: localhost/s3gw:latest
imagePullPolicy: Never
volumeMounts:
- name: s3gw-lh-store
mountPath: /data
ports:
- containerPort: 7480
name: s3gw-http
volumes:
- name: s3gw-lh-store
persistentVolumeClaim:
claimName: s3gw-pvc
3 changes: 1 addition & 2 deletions k3s/s3gw-pod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ metadata:
spec:
containers:
- name: s3gw
image: localhost/s3gw:latest
imagePullPolicy: Never
image: ghcr.io/aquarist-labs/s3gw:latest
volumeMounts:
- name: s3gw-lh-store
mountPath: /data
Expand Down
Loading

0 comments on commit 7ee2c79

Please sign in to comment.