Skip to content

dcasati/kubernetes-PlantUML

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kubernetes-PlantUML

These are the PlantUML sprites, macros and stereotypes for creating PlantUML diagrams with the Kubernetes components. The official Kubernetes Icons Set (where this work is based) can be found here

This repo is heavily influenced by the awesome work from Ricardo Niepel on Azure-PlantUML

vscode

Table of Contents

Getting Started

TL;DR - If you're familiar with PlantUML this is what you need:

' Kubernetes
!define KubernetesPuml https://raw.githubusercontent.com/dcasati/kubernetes-PlantUML/master/dist

' global definition
!includeurl KubernetesPuml/kubernetes_Common.puml
!includeurl KubernetesPuml/kubernetes_Context.puml
!includeurl KubernetesPuml/kubernetes_Simplified.puml

' k8s specific components
!includeurl KubernetesPuml/OSS/KubernetesPod.puml
!includeurl KubernetesPuml/OSS/KubernetesPsp.puml
!includeurl KubernetesPuml/OSS/KubernetesPv.puml
!includeurl KubernetesPuml/OSS/KubernetesPvc.puml

[...]

If you're starting with PlantUML, here's what you need:

  1. VS Code with the PlantUML extension PlantUML
  2. Graphviz
  3. Copy one of the examples from: https://github.com/dcasati/kubernetes-PlantUML/tree/master/samples

I also have an introduction to PlantUML here

Examples

A basic hello world example could look like this:

kubernetes

This picture was rendered with the following code:

@startuml kubernetes

footer Kubernetes Plant-UML
scale max 1024 width

skinparam nodesep 10
skinparam ranksep 10

' Kubernetes
!define KubernetesPuml https://raw.githubusercontent.com/dcasati/kubernetes-PlantUML/master/dist

!includeurl KubernetesPuml/kubernetes_Common.puml
!includeurl KubernetesPuml/kubernetes_Context.puml
!includeurl KubernetesPuml/kubernetes_Simplified.puml

!includeurl KubernetesPuml/OSS/KubernetesSvc.puml
!includeurl KubernetesPuml/OSS/KubernetesPod.puml

actor "User" as userAlias
left to right direction

' Kubernetes Components
Cluster_Boundary(cluster, "Kubernetes Cluster") {
    Namespace_Boundary(ns, "Web") {
        KubernetesSvc(svc, "service", "")
        KubernetesPod(pod1, "web-pod1", "")
        KubernetesPod(pod2, "web-pod2", "")
    }
}

Rel(userAlias,svc,"get HTTP/1.1 index.html", "1")
Rel(svc,pod1,"load Balances to Pods", "2")
Rel(svc,pod2,"load Balances to Pods", "2")
Rel_U(pod1, svc, "serves content", "3")
Rel(svc, userAlias, "return content to", "4")
@enduml

A more complete example would look like this picture:

more complete example

and the accompaining code:

@startuml kubernetes

footer Kubernetes Plant-UML
scale max 1024 width

skinparam nodesep 10
skinparam ranksep 10

' Kubernetes
!define KubernetesPuml https://raw.githubusercontent.com/dcasati/kubernetes-PlantUML/master/dist

!includeurl KubernetesPuml/kubernetes_Common.puml
!includeurl KubernetesPuml/kubernetes_Context.puml
!includeurl KubernetesPuml/kubernetes_Simplified.puml

!includeurl KubernetesPuml/OSS/KubernetesSvc.puml
!includeurl KubernetesPuml/OSS/KubernetesIng.puml
!includeurl KubernetesPuml/OSS/KubernetesPod.puml
!includeurl KubernetesPuml/OSS/KubernetesRs.puml
!includeurl KubernetesPuml/OSS/KubernetesDeploy.puml
!includeurl KubernetesPuml/OSS/KubernetesHpa.puml

actor "User" as userAlias
left to right direction

' Kubernetes Components
Cluster_Boundary(cluster, "Kubernetes Cluster") {
    Namespace_Boundary(ns, "Back End") {
        KubernetesIng(ingress, "your.domain.com", "")
        KubernetesSvc(svc, "service", "")
        KubernetesPod(pod1, "pod1", "")
        KubernetesPod(pod2, "pod2", "")
        KubernetesPod(pod3, "pod3", "")

        KubernetesRs(rs,"","")
        KubernetesDeploy(deploy,"deployment","")
        KubernetesHpa(hpa, "HPA", "")
    }
}

Rel(userAlias,ingress," ")
Rel(ingress,svc," ")

Rel(svc,pod1," ")
Rel(svc,pod2," ")
Rel(svc,pod3," ")

Rel_U(rs,pod1," ")
Rel_U(rs,pod2," ")
Rel_U(rs,pod3," ")

Rel_U(deploy,rs, " ")
Rel_U(hpa,deploy, " ")

@enduml

Using kubernetes-PlantUML with other PlantUML files

You can certainly mix and match the stencils from kubernetes-PlantUML with other PlantUML files. For instance, here is an example of using it with the Azure-PlantUML files to ilustrate this reference architecture microservices

microsoervices-diagram

The equivalent of that in PlantUML would look like this:

microservices-plantuml

@startuml kubernetes

footer Kubernetes Plant-UML
scale max 1024 width

skinparam nodesep 10
skinparam ranksep 10

' Azure
!define AzurePuml https://raw.githubusercontent.com/RicardoNiepel/Azure-PlantUML/release/2-1/dist

!includeurl AzurePuml/AzureCommon.puml
!includeurl AzurePuml/AzureSimplified.puml

!includeurl AzurePuml/Containers/AzureContainerRegistry.puml
!includeurl AzurePuml/Databases/AzureCosmosDb.puml
!includeurl AzurePuml/Databases/AzureSqlDatabase.puml
!includeurl AzurePuml/DevOps/AzurePipelines.puml
!includeurl AzurePuml/Identity/AzureActiveDirectory.puml
!includeurl AzurePuml/Networking/AzureLoadBalancer.puml
!includeurl AzurePuml/Security/AzureKeyVault.puml

' Kubernetes
!define KubernetesPuml https://raw.githubusercontent.com/dcasati/kubernetes-PlantUML/master/dist

!includeurl KubernetesPuml/kubernetes_Common.puml
!includeurl KubernetesPuml/kubernetes_Context.puml
!includeurl KubernetesPuml/kubernetes_Simplified.puml

!includeurl KubernetesPuml/OSS/KubernetesApi.puml
!includeurl KubernetesPuml/OSS/KubernetesIng.puml
!includeurl KubernetesPuml/OSS/KubernetesPod.puml

actor "DevOps" as devopsAlias
collections "Client Apps" as clientalias
collections "Helm Charts" as helmalias

left to right direction

' Azure Components
AzureActiveDirectory(aad, "\nAzure\nActive Directory", "Global")
AzureContainerRegistry(acr, "ACR", "Canada Central")
AzureCosmosDb(cosmos, "\nCosmos DB", "Global")
AzureKeyVault(keyvault, "\nAzure\nKey Vault", "Global")
AzureLoadBalancer(alb, "\nLoad\nBalancer", "Canada Central")
AzureSqlDatabase(sql, "\nExternal\ndata stores", "Canada Central")
AzurePipelines(ado, "CI/CD\nAzure Pipelines", "Global")

' Kubernetes Components
Cluster_Boundary(cluster, "Kubernetes Cluster") {
    KubernetesApi(KubernetesApi, "Kubernetes API", "")

    Namespace_Boundary(nsFrontEnd, "Front End") {
        KubernetesIng(ingress, "API Gateway", "")
    }

    Namespace_Boundary(nsBackEnd, "Back End") {
        KubernetesPod(KubernetesBE1, "", "")
        KubernetesPod(KubernetesBE2, "", "")
        KubernetesPod(KubernetesBE3, "", "")
    }

    Namespace_Boundary(nsUtil, "Utiliy Services") {
        KubernetesPod(KubernetesUtil1, "", "")
        KubernetesPod(KubernetesUtil2, "","")
    }
}

Rel(devopsAlias, aad, "AUTH")
Rel(helmalias, KubernetesApi, "helm upgrade")

Rel(aad, keyvault, " ")
Rel(KubernetesApi, aad, "RBAC", "ASYNC")

Rel(clientalias, alb, "HTTP", "ASYNC")
Rel(alb, ingress, "HTTP", "ASYNC")

Rel(ingress, KubernetesBE1, " ")
Rel(KubernetesBE1, KubernetesBE2, " ")
Rel(KubernetesBE1, KubernetesBE3, " ")

Rel(KubernetesBE2, sql, " ")
Rel(KubernetesBE3, keyvault, "Pod Identity")
Rel(KubernetesBE3, cosmos, " ")

Rel(ado, acr, "docker push")
Rel_U(KubernetesApi, acr, "docker pull")
@enduml

List of Supported Symbols

Category Macro (Name)
Mono 
Url
OSS
OSS KubernetesCronjob
(Kubernetes Cronjob)
KubernetesCronjob OSS/KubernetesCronjob.puml
OSS KubernetesGroup
(Kubernetes Group)
KubernetesGroup OSS/KubernetesGroup.puml
OSS KubernetesPsp
(Kubernetes Psp)
KubernetesPsp OSS/KubernetesPsp.puml
OSS KubernetesRole
(Kubernetes Role)
KubernetesRole OSS/KubernetesRole.puml
OSS KubernetesApi
(Kubernetes Api)
KubernetesApi OSS/KubernetesApi.puml
OSS KubernetesJob
(Kubernetes Job)
KubernetesJob OSS/KubernetesJob.puml
OSS KubernetesCm
(Kubernetes Cm)
KubernetesCm OSS/KubernetesCm.puml
OSS KubernetesMaster
(Kubernetes Master)
KubernetesMaster OSS/KubernetesMaster.puml
OSS KubernetesKproxy
(Kubernetes Kproxy)
KubernetesKproxy OSS/KubernetesKproxy.puml
OSS KubernetesCrd
(Kubernetes Crd)
KubernetesCrd OSS/KubernetesCrd.puml
OSS KubernetesDs
(Kubernetes Ds)
KubernetesDs OSS/KubernetesDs.puml
OSS KubernetesSc
(Kubernetes Sc)
KubernetesSc OSS/KubernetesSc.puml
OSS KubernetesCrb
(Kubernetes Crb)
KubernetesCrb OSS/KubernetesCrb.puml
OSS KubernetesSched
(Kubernetes Sched)
KubernetesSched OSS/KubernetesSched.puml
OSS KubernetesLimits
(Kubernetes Limits)
KubernetesLimits OSS/KubernetesLimits.puml
OSS KubernetesQuota
(Kubernetes Quota)
KubernetesQuota OSS/KubernetesQuota.puml
OSS KubernetesVol
(Kubernetes Vol)
KubernetesVol OSS/KubernetesVol.puml
OSS KubernetesSa
(Kubernetes Sa)
KubernetesSa OSS/KubernetesSa.puml
OSS KubernetesKubelet
(Kubernetes Kubelet)
KubernetesKubelet OSS/KubernetesKubelet.puml
OSS KubernetesPvc
(Kubernetes Pvc)
KubernetesPvc OSS/KubernetesPvc.puml
OSS KubernetesCcm
(Kubernetes Ccm)
KubernetesCcm OSS/KubernetesCcm.puml
OSS KubernetesSts
(Kubernetes Sts)
KubernetesSts OSS/KubernetesSts.puml
OSS KubernetesNetpol
(Kubernetes Netpol)
KubernetesNetpol OSS/KubernetesNetpol.puml
OSS KubernetesCrole
(Kubernetes Crole)
KubernetesCrole OSS/KubernetesCrole.puml
OSS KubernetesRs
(Kubernetes Rs)
KubernetesRs OSS/KubernetesRs.puml
OSS KubernetesNode
(Kubernetes Node)
KubernetesNode OSS/KubernetesNode.puml
OSS KubernetesSecret
(Kubernetes Secret)
KubernetesSecret OSS/KubernetesSecret.puml
OSS KubernetesNs
(Kubernetes Ns)
KubernetesNs OSS/KubernetesNs.puml
OSS KubernetesDeploy
(Kubernetes Deploy)
KubernetesDeploy OSS/KubernetesDeploy.puml
OSS KubernetesUser
(Kubernetes User)
KubernetesUser OSS/KubernetesUser.puml
OSS KubernetesPv
(Kubernetes Pv)
KubernetesPv OSS/KubernetesPv.puml
OSS KubernetesEp
(Kubernetes Ep)
KubernetesEp OSS/KubernetesEp.puml
OSS KubernetesSvc
(Kubernetes Svc)
KubernetesSvc OSS/KubernetesSvc.puml
OSS KubernetesRb
(Kubernetes Rb)
KubernetesRb OSS/KubernetesRb.puml
OSS KubernetesEtcd
(Kubernetes Etcd)
KubernetesEtcd OSS/KubernetesEtcd.puml
OSS KubernetesIng
(Kubernetes Ing)
KubernetesIng OSS/KubernetesIng.puml
OSS KubernetesHpa
(Kubernetes Hpa)
KubernetesHpa OSS/KubernetesHpa.puml

Contributing

I've built this on a necessity that I have for making better diagrams when Kubernetes is part of the solution. This is based on a community effort and as such this should belong to the Kubernetes community. Feel free to fork and to submit PRs.

Reference

None of the work here would be possible without the foundation from Ricardo Niepel, PlantUML and the C4 Model