Summary
KubeDiagrams is a repo on GitHub that enables you to generate Kubernetes architecture diagrams from Kubernetes manifest files.
This article on visualising SQL Server in Kubernetes initially appeared on Andrew Pruski’s blog. It has been republished with the author’s credit and consent.
The other day, I came across an interesting repo on GitHub, KubeDiagrams.
What this repo does is generate Kubernetes architecture diagrams from Kubernetes manifest files…nice!
Deploying applications to Kubernetes can get complicated fast…especially with stateful applications such as SQL Server.
So having the ability to easily generate diagrams is really helpful…because we all should be documenting everything, right? 🙂
Plus, I’m rubbish at creating diagrams!
So let’s have a look at how this works. First, install the dependencies via pip:
1 2 |
1. pip install pyyaml 2. pip install diagrams |
And install graphviz:
1 |
1. sudo apt install graphviz |
Great, now pull down the repo:
1 |
1. git clone https://github.com/philippemerle/KubeDiagrams.git |
And we’re good to go! So here’s an example manifest file to deploy a SQL Server statefulset to Kubernetes:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
1 apiVersion: v1 2 kind: Namespace 3 metadata: 4 name: mssql 5 —– 6 apiVersion: storage.k8s.io/v1 7 kind: StorageClass 8 metadata: 9 name: mssql–sc 10 provisioner: docker.io/hostpath 11 reclaimPolicy: Delete 12 volumeBindingMode: Immediate 13 —– 14 apiVersion: v1 15 kind: Service 16 metadata: 17 name: mssql–headless 18 namespace: mssql 19 spec: 20 clusterIP: None 21 selector: 22 name: mssql–pod 23 ports: 24 – name: mssql–port 25 port: 1433 26 targetPort: 1433 27 —– 28 apiVersion: apps/v1 29 kind: StatefulSet 30 metadata: 31 name: mssql–statefulset 32 namespace: mssql 33 spec: 34 serviceName: “mssql-headless” 35 replicas: 1 36 podManagementPolicy: Parallel 37 selector: 38 matchLabels: 39 name: mssql–pod 40 template: 41 metadata: 42 labels: 43 name: mssql–pod 44 spec: 45 securityContext: 46 fsGroup: 10001 47 containers: 48 – name: mssql–container 49 image: mcr.microsoft.com/mssql/server:2022–CU16–ubuntu–20.04 50 ports: 51 – containerPort: 1433 52 name: mssql–port 53 env: 54 – name: MSSQL_PID 55 value: “Developer” 56 – name: ACCEPT_EULA 57 value: “Y” 58 – name: MSSQL_AGENT_ENABLED 59 value: “1” 60 – name: MSSQL_SA_PASSWORD 61 value: “Testing1122” 62 resources: 63 requests: 64 memory: “1024Mi” 65 cpu: “500m” 66 limits: 67 memory: “2048Mi” 68 cpu: “2000m” 69 volumeMounts: 70 – name: sqlsystem 71 mountPath: /var/opt/mssql 72 – name: sqldata 73 mountPath: /opt/sqlserver/data 74 – name: sqllog 75 mountPath: /opt/sqlserver/log 76 volumeClaimTemplates: 77 – metadata: 78 name: sqlsystem 79 namespace: mssql 80 spec: 81 accessModes: 82 – ReadWriteOncePod 83 storageClassName: mssql–sc 84 resources: 85 requests: 86 storage: 25Gi 87 – metadata: 88 name: sqldata 89 namespace: mssql 90 spec: 91 accessModes: 92 – ReadWriteOncePod 93 storageClassName: mssql–sc 94 resources: 95 requests: 96 storage: 25Gi 97 – metadata: 98 name: sqllog 99 namespace: mssql 100 spec: 101 accessModes: 102 – ReadWriteOncePod 103 storageClassName: mssql–sc 104 resources: 105 requests: 106 storage: 25Gi 107 —– 108 apiVersion: v1 109 kind: Service 110 metadata: 111 name: mssql–service 112 namespace: mssql 113 spec: 114 ports: 115 – name: mssql–ports 116 port: 1433 117 targetPort: 1433 118 selector: 119 name: mssql–pod 120 type: LoadBalancer |
I’m using Docker Desktop here (hence the provisioner: docker.io/hostpath in the storage class). What this will create is a namespace, storage class, headless service for the statefulset, the statefulset itself, three persistent volume claims, and a load balanced service to connect to SQL.
Quite a lot of objects for a simple SQL Server deployment, right? (Ahh, I know it’s a statefulset, but you know what I mean.)
So let’s point KubeDiagrams at the manifest:
1 |
1. ./kube–diagrams mssql–statefulset.yaml |
And here’s the output!
Pretty cool, eh?
I noticed a couple of quirks. The docs say it’ll work with any version 3 install of Python. I had 3.8 installed but had to upgrade to 3.9.
Also, I had to add namespace: mssql to the PVCs in the statefulset, otherwise KubeDiagrams threw a warning:
1 2 3 |
Error: ‘sqlsystem/mssql/PersistentVolumeClaim/v1’ resource not found! Error: ‘sqldata/mssql/PersistentVolumeClaim/v1’ resource not found! Error: ‘sqllog/mssql/PersistentVolumeClaim/v1’ resource not found! |
But other than those, it works really well and is a great way to visualise objects in Kubernetes.
Massive thank you to the creator, Philippe Merle.