-
Notifications
You must be signed in to change notification settings - Fork 38
/
kubernetes_traefik_ingress_gke.py
executable file
·115 lines (97 loc) · 3.27 KB
/
kubernetes_traefik_ingress_gke.py
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
#!/usr/bin/env python3
# coding=utf-8
# vim:ts=4:sts=4:sw=4:et
#
# Author: Hari Sekhon
# Date: 2023-04-15 22:35:45 +0100 (Sat, 15 Apr 2023)
#
# https://github.com/HariSekhon/Diagrams-as-Code
#
# License: see accompanying Hari Sekhon LICENSE file
#
# If you're using my code you're welcome to connect with me on LinkedIn
# and optionally send me feedback to help steer this or other code I publish
#
# https://www.linkedin.com/in/HariSekhon
#
"""
Kubernetes Ingress on GKE
"""
__author__ = 'Hari Sekhon'
__version__ = '0.3'
import os
from diagrams import Diagram, Cluster, Edge
# ============================================================================ #
# On-premise / Open Source resources:
#
# https://diagrams.mingrammer.com/docs/nodes/onprem
#
from diagrams.onprem.network import Traefik
# from diagrams.onprem.certificates import CertManager, LetsEncrypt
from diagrams.onprem.client import Users
# ============================================================================ #
# Kubernetes resources:
#
# K8s resources:
#
# https://diagrams.mingrammer.com/docs/nodes/k8s
#
from diagrams.k8s.compute import Pod
from diagrams.k8s.network import Service
# ============================================================================ #
# GCP resources:
#
# https://diagrams.mingrammer.com/docs/nodes/gcp
#
from diagrams.gcp.compute import GKE
from diagrams.gcp.network import DNS, LoadBalancing
graph_attr = {
"splines": "spline",
}
# pylint: disable=W0104,W0106
with Diagram('Kubernetes Traefik Ingress on GKE',
show=not bool(os.environ.get('CI', 0)),
direction='BT',
filename='images/kubernetes_traefik_ingress_gke',
graph_attr=graph_attr,
):
# letsencrypt = LetsEncrypt("LetsEncrypt Certificate Authority")
users = Users("Users")
with Cluster("GCP"):
load_balancer = LoadBalancing("Cloud Load Balancer")
dns = DNS("Cloud DNS")
# load_balancer - dns
with Cluster("Kubernetes Cluster"):
gke = GKE("GKE")
# with Cluster("Cert Manager"):
# certmanager = CertManager("Cert Manager")
with Cluster("Ingress"):
traefik = Traefik("Traefik\nIngress")
# letsencrypt >> \
# Edge(label="ACME protocol\ngenerated certificate", style="dashed") \
# >> certmanager \
# >> Edge(label="SSL cert", style="dashed") \
# >> traefik
with Cluster("WebApp 2"):
service = Service("WebApp 2 Service")
traefik >> service
pods = []
for _ in range(3, 0, -1):
pods.append(Pod(f"Pod {_}") << service)
# argocd >> service
# argocd >> pods
with Cluster("WebApp 1"):
service = Service("WebApp 1 Service")
traefik >> service
pods = []
for _ in range(3, 0, -1):
pods.append(Pod(f"Pod {_}") << service)
# argocd >> service
# argocd >> pods
users \
>> Edge(label="HTTPS traffic") \
>> load_balancer \
>> traefik
users \
>> Edge(label="DNS queries") \
>> dns