Skip to content

Instantly share code, notes, and snippets.

@dictcp
Last active January 11, 2024 17:31
Show Gist options
  • Save dictcp/685d47fc7abad0f4da91f44428ac5c70 to your computer and use it in GitHub Desktop.
Save dictcp/685d47fc7abad0f4da91f44428ac5c70 to your computer and use it in GitHub Desktop.

microk8s & fluxcd

(optional) prepare the server

# install at https://multipass.run/
multipass launch --name microk8s-flux --mem 2G
multipass shell microk8s-flux

# assume ubuntu with snap installed, if not install it via
apt install snapd

bootstrapping cluster

# for simplicity, we switch to root for the following commands, or you need to handle the sudo issue
sudo -i

# setup microk8s and utils
snap install microk8s --classic --channel=1.14/stable
snap install helm --classic --channel=3.0/stable
snap install fluxctl --classic

# if you did not switch to root user
# sudo usermod -a -G microk8s multipass

echo 'alias kubectl=microk8s.kubectl' >> ~/.bash_aliases
microk8s.config > .kube/config
microk8s.enable dns

install fluxcd and helm-operator

# install fluxcd
export GHUSER="xxxxx"
export GHREPO="xxxxx"

helm repo add fluxcd https://charts.fluxcd.io

kubectl create ns flux

## remark: no-wait for manual get ssh public key
helm upgrade -i flux fluxcd/flux \
--namespace flux \
--set git.url=git@github.com:${GHUSER}/${GHREPO}

fluxctl identity --k8s-fwd-ns flux
fluxctl sync --k8s-fwd-ns flux

# install helmv3 operator
# ref: https://github.com/fluxcd/helm-operator/issues/8#issuecomment-559119525
# ref: https://github.com/fluxcd/helm-operator/tree/master/chart/helm-operator

kubectl apply -f https://raw.githubusercontent.com/fluxcd/helm-operator/v1.0.0-rc7/deploy/flux-helm-release-crd.yaml

helm upgrade -i helm-operator fluxcd/helm-operator \
--namespace flux \
--set git.ssh.secretName=flux-git-deploy \
--set helm.versions=v3

check the installation

kubectl get all --all-namespaces
helm list --namespace flux

# check helm release
AUTH_VALUES=$(cat <<-END
usePassword: true
password: "redis_pass"
usePasswordFile: true
END
)

kubectl create secret generic redis-auth --from-literal=values.yaml="$AUTH_VALUES"

cat <<EOF | kubectl apply -f -
apiVersion: helm.fluxcd.io/v1
kind: HelmRelease
metadata:
  name: redis
  namespace: default
spec:
  releaseName: redis
  chart:
    repository: https://kubernetes-charts.storage.googleapis.com
    name: redis
    version: 9.0.2
  valuesFrom:
  - secretKeyRef:
      name: redis-auth
  values:
    master:
      persistence:
        enabled: false
    volumePermissions:
      enabled: true
    metrics:
      enabled: true
    cluster:
      enabled: false
EOF
kubectl get hr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment