Local Installation of OTH using OTH Kubernetes Controller
It is possible to deploy the OTH Kubernetes Controller locally using something like kind
or minikube
.
The following have been used to bootstrap a kind
cluster locally during development:
#!/usr/bin/env bash
set -euo pipefail
# Start kind cluster
cat <<EOF | kind create cluster --config=-
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
kubeadmConfigPatches:
- |
kind: InitConfiguration
nodeRegistration:
kubeletExtraArgs:
node-labels: "ingress-ready=true"
extraPortMappings:
- containerPort: 80
hostPort: 80
protocol: TCP
- containerPort: 443
hostPort: 443
protocol: TCP
EOF
# Setup ingress (nginx)
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/provider/kind/deploy.yaml
# setup dashboard ....
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.3.1/aio/deploy/recommended.yaml
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: ServiceAccount
metadata:
name: admin-user
namespace: kubernetes-dashboard
EOF
cat <<EOF | kubectl apply -f -
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: admin-user
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: admin-user
namespace: kubernetes-dashboard
EOF
# ensure ingres is ready
until kubectl wait --namespace ingress-nginx --for=condition=ready pod --selector=app.kubernetes.io/component=controller --timeout=90s; do
echo "waiting .. "
sleep 1
done
# get the token
TOKEN=$(kubectl -n kubernetes-dashboard get secret $(kubectl -n kubernetes-dashboard get sa/admin-user -o jsonpath="{.secrets[0].name}") -o go-template="{{.data.token | base64decode}}")
echo "Admin token is"
echo $TOKEN
echo
echo
echo "Setup proxy for dashboad by:"
echo "kubectl port-forward -n kubernetes-dashboard service/kubernetes-dashboard 10443:443 --address 0.0.0.0"
echo "Go to https://localhost:10443/"
To locally deploy the solution the following steps are required:
- Install OTH Kubernetes Controller
- Setup stateful services (rabbitmq and mariadb)
- Bootstrap deployment
- Install deployment
- Test deployment
Each of the steps will be described in more detail.
Install of controller
Create local resources
OTH requires access to a MariaDB and RabbitMQ, these can be started using docker
like this:
RabbitMQ
Start RabbitMQ by:
docker run -d --rm --name k8srabbitmq -p 5672:5672 -p 15672:15672 -e RABBITMQ_DEFAULT_USER=oth -e RABBITMQ_DEFAULT_PASS=opentele -e RABBITMQ_DEFAULT_VHOST=oth rabbitmq:3.8-management
MariaDB
Start MariaDB using:
docker run -d --rm --name k8smariadb -p 3306:3306 -e MYSQL_ROOT_PASSWORD=opentele -e MYSQL_USER=oth -e MYSQL_PASSWORD=opentele -e MYSQL_DATABASE=clinician mariadb:10.3
Deployment of OTH
Run bootstrap tool
Setup passwords for RabbitMQ and MariaDB using the oth-k8s-bootstrap
tool like so:
export customer=test
export stage=demo
export name=$customer-$stage
oth-k8s-bootstrap init -n $name -c $customer -s $stage \
-a $AWS_ACCESS_KEY_ID -k $AWS_SECRET_ACCESS_KEY \
--pv 2.70.00 \
--dbpassword opentele --dbadminpassword opentele \
--rabbitmqpassword opentele
Note down your LAN IP.
Then create the OTH deployment like this (minimal deployment):
apiVersion: k8s.oth.io/v1alpha1
kind: Oth
metadata:
name: oth-sample
namespace: oth-sample
spec:
# Add fields here
productversion: "2.70.00"
external:
database: true
rabbitmq: true
deployment:
tls:
enabled: false
fqdn: <your lan ip>.nip.io
timezone: Europe/Copenhagen
language: da-DK
customer: oth
stage: sample
environment: demo
database:
hostname: <your lan ip>.nip.io
username: oth
rabbitmq:
hostname: <your lan ip>.nip.io
username: oth
vhost: oth
features:
cors:
whitelist:
- http://192.168.0.132:8000
- http://localhost:8000
Then deploy it using kubectl -n test-demo test-demo.yml
.