Kubernetes
From Organic Design wiki
Aka k8s.
Contents
k3s
k3s is a lighter-weight implementation of k8s that runs in a single binary with a smaller memory footprint. You can run this (barely) with 1GB of ram but you probably want at least 2GB + swap.
Install
curl -sfL https://get.k3s.io | sh -
Commands
# Get a list of pods:
kubectl -n <NAMESPACE> get pods
# Edit the deployment config of a deployment (defaults to vim)
kubectl -n <NAMESPACE> edit deploy <DEPLOYMENT NAME>
# Edit the service config of a deployment (defaults to vim)
kubectl -n <NAMESPACE> edit svc <DEPLOYMENT NAME>
# Display the deployment logs
kubectl -n <NAMESPACE> logs deploy/<DEPLOYMENT NAME>
# Get the service config for a deployment
kubectl -n <NAMESPACE> get svc <DEPLOYMENT NAME> -o yaml
# Perform a rolling restart on a config.
kubectl rollout restart deploy <DEPLOYMENT NAME>
# Patch a deployment config (cli alternative to editing)
kubectl -n <NAMESPACE> patch deployment <DEPLOYMENT NAME> --type='json' -p='[{"op": "add", "path": "/spec/template/spec/containers/0/args", "value":["--address", "0.0.0.0:8080"]}]'
# Forward a port locally.
kubectl port-forward -n <NAMESPACE> svc/<DEPLOYMENT NAME> 8080:8080 &
# Scale a deployment to 0 (i.e. disable it)
kubectl scale deployment -n <NAMESPACE> <DEPLOYMENT NAME> --replicas=0
# Get the details of a pod.
kubectl describe pod -n <NAMESPACE> <POD NAME>
# View k8s config:
kubectl config view --raw
# Delete pod:
kubectl delete pod -n <NAMESPACE> -l app=<APP>
OpenFaas
Install
# Install arkade (pre-req)
curl -sLS https://get.arkade.dev | sh
# Write the config from k3s to where kubernetes would put it.
kubectl config view --raw > ~/.kube/config
# Install OpenFaas to the k3s instance.
arkade install openfaas
# Install the CLI
curl -sSL https://cli.openfaas.com | sudo sh
Get Service Password
PASSWORD=$(kubectl get secret -n openfaas basic-auth -o jsonpath="{.data.basic-auth-password}" | base64 --decode; echo)
Lower Memory
You can reduce memory usage by disabling prometheus and alertmanager:
kubectl scale deployment alertmanager -n openfaas --replicas=0
kubectl scale deployment prometheus -n openfaas --replicas=0
Exposing 8080
Expose the port in the deployment:
kubectl -n openfaas edit deploy gateway
spec:
template:
spec:
containers:
- args:
ports:
- containerPort: 8080
hostPort: 8080 # Add this line
name: http
protocol: TCP
Change the type to NodePort (instead of ClsuterPort):
kubectl -n openfaas edit svc gateway
spec:
type: NodePort # Change this to "NodePort"