项目作者: proventa

项目描述 :
Setup a postgres ha-cluster with patroni on a local multi-node kubernetes cluster on windows.
高级语言: Shell
项目地址: git://github.com/proventa/postgres-patroni-local-kubernetes.git


postgres-patroni-local-kubernetes

Setup a PostgreSQL-HA-Cluster with Patroni on a local multi-node kubernetes cluster on windows and linux mint.

Setup a local multi-node k8s cluster

System Requirements

Docker

Basic kind installation and configuration

  • Install the open source project kind
    • Create directory for kind
      • Windows: “c:\user\username\kind”
  1. curl.exe -Lo kind-windows-amd64.exe https://github.com/kubernetes-sigs/kind/releases/download/v0.7.0/kind-windows-amd64
  2. Move-Item .\kind-windows-amd64.exe $pwd\kind.exe
  • Linux: mkdir -p /kubernetes-local/kind
  1. curl -Lo ./kind "https://github.com/kubernetes-sigs/kind/releases/download/v0.7.0/kind-$(uname)-amd64"
  2. chmod +x ./kind
  3. mv ./kind /kubernetes-local/kind
  • Set environment variables for kind
    • Windows (as Administrator): [Environment]::SetEnvironmentVariable("Path", $env:Path + ";$pwd", "User")
    • linux: cp ~/kubernetes-local/kind/./kind /usr/local/bin and add path to .zshrc or .bashrc
  • Test if kind is working: type in kind in powershell or bash

Sample Multi-node cluster (1 master, 2 workers)

  • Multinode-cluster (Section: Advanced/Configuring Your kind Cluster)
    • Create kind-example-config.yaml under c:/user/username/kind

sample kind-example-config.yaml

  1. ## Three node (two workers) k8s-cluster config
  2. kind: Cluster
  3. apiVersion: kind.x-k8s.io/v1alpha4
  4. nodes:
  5. - role: control-plane
  6. - role: worker
  7. - role: worker
  • Create multi-node cluster (this will take a few minutes): kind create cluster --config <kind-example-config.yaml-path> (Docker must be running!)
  • Test running cluster: kubectl cluster-info —context kind-kind

Install and configure Kubernetes Dashboard

  1. Command: kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0-beta8/aio/deploy/recommended.yaml
  2. Command: kubectl proxy
  3. Access /proxy/">kuberentes dashboard
  • Access-token for access: kubectl -n kubernetes-dashboard describe secret $(kubectl -n kubernetes-dashboard get secret | grep admin-user | awk '{print $1}')
  • sample output:
  1. Name: kubernetes-dashboard-token-jdxjs
  2. Namespace: kubernetes-dashboard
  3. Labels: <none>
  4. Annotations: kubernetes.io/service-account.name: kubernetes-dashboard
  5. kubernetes.io/service-account.uid: aceae174-dd49-4193-aa6d-2947e04e2170
  6. Type: kubernetes.io/service-account-token
  7. Data
  8. ====
  9. ca.crt: 1025 bytes
  10. namespace: 20 bytes
  11. token: eyJhbGciOiJSUzI1NiIsImtpZCI6InpRV1h1dmpYM25YdUNQeFF6N2hWUkZiQlFmdEw1RDY5M01WQlQ2aGx4dlUifQOA9U-2OMCbCzhhTAKc9kwIK3SxUZLLGU9qJ_FwAYWi3yWmlXwnhxyiDIvP-CqxHvf-trYeevd1djRnq-hWP5nFrafEsm90brt_7YsEGZH1ELGVp1CyD5cf9lw
  • Copy last access-token (token:) on output to web-ui: token field

  • Alias for “kubectl” for windows powershell Set-Alias kc "C:\path\kubectl.exe"

Troubleshooting

  1. Missing permissions for kubernetes-dashboard user to list, edit, … ressources
  • sample: admin/root permissions to administrate the k8s-cluster
  • kubectl edit clusterroles kubernetes-dashboard
  • change access to ressources to the following

clusterrole: kubernetes-dashboard

  1. - apiGroups:
  2. - '*'
  3. resources:
  4. - '*'
  5. verbs:
  6. - '*'

Setup Postgres-HA with Patroni

In the patroni folder are YAML-Manifest and a script for the automated deployment of on PostgreSQL-HA-Cluster with patroni.

Steps

  1. clone this repository
  2. chmod +x setup-patroni-cluster.sh
  3. kubectl create namespace zalando-postgres
  4. ./setup-patroni-cluster.sh

Useful

  • forward a port from a deployment
    1. kubectl get pods -n <namespace>
    2. kubectl port-forward <pod-name> hostport:pod-port -n namespace