Skip to content

Instantly share code, notes, and snippets.

@ZCube
Last active December 6, 2022 23:35
Show Gist options
  • Save ZCube/e1c14ff029d153210feaa1a3db9456c1 to your computer and use it in GitHub Desktop.
Save ZCube/e1c14ff029d153210feaa1a3db9456c1 to your computer and use it in GitHub Desktop.
Basic Github Workflow for testing charts
# reference : https://medium.com/codex/setup-multiple-node-groups-for-local-k3s-clusters-with-docker-compose-d9f1a49c1774
# reference : https://gist.github.com/rockcyj/86c54d866ab5a1b38e6aaf4315d3149a#file-k3s-nodegroup-taint-yaml
version: '3'
services:
server:
image: "rancher/k3s:${K3S_VERSION:-latest}"
command:
- server
tmpfs:
- /run
- /var/run
privileged: true
environment:
- K3S_TOKEN=secret
- K3S_KUBECONFIG_OUTPUT=/output/kubeconfig.yaml
- K3S_KUBECONFIG_MODE=666
volumes:
- .:/output
ports:
- 6443:6443
agent:
image: "rancher/k3s:${K3S_VERSION:-latest}"
command:
- agent
tmpfs:
- /run
- /var/run
privileged: true
environment:
- K3S_URL=https://server:6443
- K3S_TOKEN=secret
name: k3s Testing
on: push
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Testing Chart
run: |
docker-compose up -d --scale agent=3
# wait until k3s up
until [ -f kubeconfig.yaml ]
do
sleep 5
done
# copy KUBECONFIG
mkdir -p .kube
cp -f kubeconfig.yaml .kube/config
chmod 600 .kube/config
export KUBECONFIG=$PWD/.kube/config
# install helm
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
chmod 700 get_helm.sh
./get_helm.sh
# install goss
export GOSS_VER=v0.3.16
curl -fsSL https://goss.rocks/install | GOSS_DST=/usr/local/bin sh
curl -L https://raw.githubusercontent.com/aelsabbahy/goss/master/extras/dgoss/dgoss -o /usr/local/bin/dgoss
chmod +rx /usr/local/bin/dgoss
curl -L https://raw.githubusercontent.com/aelsabbahy/goss/master/extras/kgoss/kgoss -o /usr/local/bin/kgoss
chmod +rx /usr/local/bin/kgoss
# test k3s and goss binaries
kubectl get nodes
goss | true
kgoss | true
dgoss | true
# install test charts
helm repo add bitnami https://charts.bitnami.com/bitnami
helm install test bitnami/nginx --wait
# install test service
cat <<EOF > svc.yaml
apiVersion: v1
kind: Service
metadata:
name: nginx
spec:
type: ExternalName
externalName: test-nginx
EOF
kubectl apply -f svc.yaml
# check status
kubectl get pods -A
kubectl get svc -A
- name: Cleanup k3s
if: always()
run: |
docker-compose down -v | true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment