Basic Kubernetes configuration up and running

Add postgres operator and cluster
Create gitlab database declaratively
Update flake
YES, YES, I KNOW THE PASSWORDS ARE DUMB AND WORLD READABLE
This commit is contained in:
Greg Hellings
2025-05-26 12:20:29 -05:00
parent 7a60c58a74
commit 3110cff93c
18 changed files with 279 additions and 58 deletions
+15
View File
@@ -0,0 +1,15 @@
Stands up my personal infrastructure in a Kubernetes environment.
To apply this you need to install kubectl, kustomize, and helm. It can then by applied
by simply invoking the command:
```bash
# Working directory is assumed to be the manifests directory
./apply.sh
```
Once the basic cluster stuff is setup, you can just apply this directory with
```bash
kubectl apply -k .
```
+11
View File
@@ -0,0 +1,11 @@
#!/usr/bin/env bash
# Get the directory where the script is located
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
# Change to the script directory
cd "$SCRIPT_DIR"
kubectl apply -k namespaces
kustomize build postgres --enable-helm | kubectl apply -f - --server-side --force-conflicts
kubectl apply -k .
+6
View File
@@ -0,0 +1,6 @@
namespace: db
resources:
- postgres-cluster.yaml
- postgres-gitlab.yaml
- postgres-pgadmin.yaml
+26
View File
@@ -0,0 +1,26 @@
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
name: postgres
spec:
instances: 3
storage:
size: 10Gi
primaryUpdateStrategy: unsupervised
managed:
roles:
- name: gitlab
ensure: present
comment: Gitlab user
login: true
superuser: false
passwordSecret:
name: postgres-user-gitlab
- name: pgadmin
ensure: present
comment: PG Admin user
login: true
superuser: true
passwordSecret:
name: postgres-user-pgadmin
+21
View File
@@ -0,0 +1,21 @@
apiVersion: v1
kind: Secret
metadata:
name: postgres-user-gitlab
labels:
cnpg.io/reload: "true"
type: kubernetes.io/basic-auth
stringData:
# Currently this is set to "gitlab"
username: gitlab
password: gitlab
---
apiVersion: postgresql.cnpg.io/v1
kind: Database
metadata:
name: database-gitlab
spec:
name: gitlab
owner: gitlab
cluster:
name: postgres
+118
View File
@@ -0,0 +1,118 @@
apiVersion: v1
kind: Secret
metadata:
name: postgres-user-pgadmin
labels:
cnpg.io/reload: "true"
type: kubernetes.io/basic-auth
stringData:
username: pgadmin
password: pgadmin
---
apiVersion: v1
kind: ConfigMap
metadata:
name: config-pgadmin
data:
servers.json: |
{
"Servers": {
"1": {
"Name": "Postgres",
"Group": "Servers",
"Port": 5432,
"Username": "pgadmin",
"Host": "postgres-rw",
"SSLMode": "allow",
"MaintenanceDB": "postgres"
}
}
}
---
apiVersion: v1
kind: Service
metadata:
name: service-pgadmin
spec:
ports:
- protocol: TCP
port: 80
targetPort: http
selector:
app: pgadmin
type: ClusterIP
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: pgadmin
spec:
serviceName: service-pgadmin
podManagementPolicy: Parallel
replicas: 1
updateStrategy:
type: RollingUpdate
selector:
matchLabels:
app: pgadmin
template:
metadata:
labels:
app: pgadmin
spec:
terminationGracePeriodSeconds: 10
containers:
- name: pgadmin
image: "dpage/pgadmin4:9.3"
imagePullPolicy: Always
env:
- name: PGADMIN_DEFAULT_EMAIL
value: greg@thehellings.com
- name: PGADMIN_DEFAULT_PASSWORD
valueFrom:
secretKeyRef:
name: postgres-user-pgadmin
key: password
- name: PGADMIN_SERVER_JSON_FILE
value: /config-pgadmin-vol/servers.json
ports:
- name: http
containerPort: 80
protocol: TCP
volumeMounts:
- name: config-pgadmin-vol
mountPath: /config-pgadmin-vol/
readOnly: true
- name: pgadmin-data
mountPath: /var/lib/pgadmin
volumes:
- name: config-pgadmin-vol
configMap:
name: config-pgadmin
volumeClaimTemplates:
- metadata:
name: pgadmin-data
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 3Gi
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-pgadmin
annotations:
ingressClassName: traefik
spec:
rules:
- host: pgadmin.thehellings.lan
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: service-pgadmin
port:
number: 80
+3
View File
@@ -0,0 +1,3 @@
resources:
- namespaces
- databases
+4
View File
@@ -0,0 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: db
+2
View File
@@ -0,0 +1,2 @@
resources:
- db.yaml
+13
View File
@@ -0,0 +1,13 @@
namespace: db
helmCharts:
# Install the operator first (with CRDs)
- name: cloudnative-pg
repo: "https://cloudnative-pg.github.io/charts/"
version: "0.23.2"
namespace: cnpg-system
releaseName: cnpg
includeCRDs: true
valuesInline:
crds:
create: true
+11
View File
@@ -0,0 +1,11 @@
#!/usr/bin/env bash
# Get the directory where the script is located
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
# Change to the script directory
cd "$SCRIPT_DIR"
kubectl delete -k .
kustomize build postgres --enable-helm | kubectl delete -f -
kubectl delete -k namespaces