Add miscellaneous examples

This commit is contained in:
Philippe Merle
2025-01-04 02:23:33 +01:00
parent 16bc5ac8b8
commit 13ee89f2c4
21 changed files with 6186 additions and 0 deletions
+45
View File
@@ -0,0 +1,45 @@
# Miscellaneous Examples
This example provides miscellaneous architecture diagrams for CronJob, LimitRange, NetworkPolicy, and ResourceQuota resource kinds.
## Instructions
Start a Kubernetes cluster.
Generate some miscellaneous architecture diagrams:
```sh
$ ./generate.sh
```
## Generated architecture diagrams
Architecture diagram for [cronjob.yaml](cronjob.yaml):
![cronjob.png](cronjob.png)
Architecture diagram for a deployed [cronjob.yaml](cronjob.yaml) instance:
![cronjob-deployed.png](cronjob-deployed.png)
Architecture diagram for [limit-ranges.yaml](limit-ranges.yaml):
![limit-ranges.png](limit-ranges.png)
Architecture diagram for [nginx.yaml](nginx.yaml):
![nginx.png](nginx.png)
Architecture diagram for a deployed [nginx.yaml](nginx.yaml) instance showing `Endpoints` resources:
![nginx-deployed-only-ep.png](nginx-deployed-only-ep.png)
Architecture diagram for a deployed [nginx.yaml](nginx.yaml) instance showing `EndpointSlice` resources:
![nginx-deployed-only-eps.png](nginx-deployed-only-eps.png)
Architecture diagram for a deployed [nginx.yaml](nginx.yaml) instance showing both `Endpoints` and `EndpointSlice` resources:
![nginx-deployed-all.png](nginx-deployed-all.png)
Architecture diagram for [network_policies.yaml](network_policies.yaml):
![network_policies.png](network_policies.png)
Architecture diagram for [quotas.yaml](quotas.yaml):
![quotas.png](quotas.png)
All-in-one architecture diagram:
![all-in-one.png](all-in-one.png)
Binary file not shown.

After

Width:  |  Height:  |  Size: 170 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 88 KiB

File diff suppressed because it is too large Load Diff
Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

+21
View File
@@ -0,0 +1,21 @@
# Source: https://k8s.io/examples/application/job/cronjob.yaml
# https://kubernetes.io/docs/tasks/job/automated-tasks-with-cron-jobs/
apiVersion: batch/v1
kind: CronJob
metadata:
name: hello
spec:
schedule: "* * * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: hello
image: busybox:1.28
imagePullPolicy: IfNotPresent
command:
- /bin/sh
- -c
- date; echo Hello from the Kubernetes cluster
restartPolicy: OnFailure
+38
View File
@@ -0,0 +1,38 @@
#! /bin/sh
PATH=../../bin:$PATH
echo_run()
{
echo $@
$@
}
if [ "$1" = "deployed" ]
then
echo_run kubectl apply -f cronjob.yaml
echo_run sleep 150
echo kubectl get
kubectl get cronjob,job,pod,cm,sa,node -o=yaml > cronjob-deployed.yaml
echo_run kubectl delete cronjob hello
echo_run kubectl apply -f nginx.yaml
echo_run sleep 60
kubectl get all,ingress,ingressclass,networkpolicy,ep,endpointslice,cm,sa,node -o=yaml > nginx-deployed-all.yaml
kubectl get all,ingress,ingressclass,networkpolicy,ep,cm,sa,node -o=yaml > nginx-deployed-only-ep.yaml
kubectl get all,ingress,ingressclass,networkpolicy,endpointslice,cm,sa,node -o=yaml > nginx-deployed-only-eps.yaml
echo_run kubectl delete -f nginx.yaml
fi
# Generate the miscellaneous architecture diagrams.
for file in `ls *.yaml`
do
echo_run kube-diagrams -v $file
done
echo_run kube-diagrams -v -o all-in-one \
cronjob.yaml \
limit-ranges.yaml \
network_policies.yaml \
nginx.yaml \
quotas.yaml
Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

+42
View File
@@ -0,0 +1,42 @@
# Source: https://kubernetes.io/docs/concepts/policy/limit-range/
apiVersion: v1
kind: LimitRange
metadata:
name: cpu-resource-constraint
spec:
limits:
- default: # this section defines default limits
cpu: 500m
defaultRequest: # this section defines default requests
cpu: 500m
max: # max and min define the limit range
cpu: "1"
min:
cpu: 100m
type: Container
---
# Source: https://k8s.io/examples/admin/resource/memory-constraints.yaml
apiVersion: v1
kind: LimitRange
metadata:
name: mem-min-max-demo-lr
spec:
limits:
- max:
memory: 1Gi
min:
memory: 500Mi
type: Container
---
# Source: https://kubernetes.io/docs/tasks/administer-cluster/limit-storage-consumption/
apiVersion: v1
kind: LimitRange
metadata:
name: storagelimits
spec:
limits:
- type: PersistentVolumeClaim
max:
storage: 2Gi
min:
storage: 1Gi
Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

@@ -0,0 +1,123 @@
# From https://github.com/NickSchleicher/k8d/blob/master/example/sample_policies.yaml
apiVersion: v1
kind: Pod
metadata:
name: myapp-pod
namespace: default
labels:
app: myapp-pod
spec:
containers:
- name: nginx
image: nginx:1.7.9
ports:
- containerPort: 80
---
apiVersion: v1
kind: Pod
metadata:
name: myapp-pod2
namespace: default
labels:
app: myapp-pod2
spec:
containers:
- name: myapp-container
image: byrnedo/alpine-curl
command: ["/bin/sh"]
args: ["-c", "sleep 36000"]
---
apiVersion: v1
kind: Service
metadata:
name: myapp-pod
namespace: default
labels:
app: myapp-pod
spec:
ports:
- port: 80
protocol: TCP
selector:
app: myapp-pod
---
kind: NetworkPolicy
apiVersion: networking.k8s.io/v1
metadata:
name: myapp-pod-to-myapp-pod2
namespace: default
spec:
podSelector:
matchLabels:
app: myapp-pod
ingress:
- from:
- ipBlock:
cidr: 1.1.1.1/32
- ipBlock:
cidr: 2.2.2.2/32
- podSelector:
matchLabels:
app: myapp-pod2
ports:
- port: 80
protocol: UDP
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: default-deny-ingress
spec:
podSelector: {}
policyTypes:
- Ingress
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-all-ingress
spec:
podSelector: {}
ingress:
- {}
policyTypes:
- Ingress
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: default-deny-egress
spec:
podSelector: {}
policyTypes:
- Egress
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-all-egress
spec:
podSelector: {}
egress:
- {}
policyTypes:
- Egress
# default deny ingress is overwritten by explicit allow ingress policies
# default allow ingress overwrites specific deny (explicit)
# default deny egress is overwritten by explicit allow egress policies
# default allow egress overwrites specific deny egress (explicit)
Binary file not shown.

After

Width:  |  Height:  |  Size: 225 KiB

File diff suppressed because it is too large Load Diff
Binary file not shown.

After

Width:  |  Height:  |  Size: 196 KiB

File diff suppressed because it is too large Load Diff
Binary file not shown.

After

Width:  |  Height:  |  Size: 200 KiB

File diff suppressed because it is too large Load Diff
Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

+75
View File
@@ -0,0 +1,75 @@
# Inspired from https://k8s.io/examples/application/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
selector:
matchLabels:
app: nginx
replicas: 3 # tells deployment to run 3 pods matching the template
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: nginx-service
labels:
app: nginx
spec:
selector:
app: nginx
ports:
- protocol: TCP
port: 80
targetPort: 80
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: nginx-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
labels:
app: nginx
spec:
rules:
- http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: nginx-service
port:
number: 80
---
# Inspired from https://kubernetes.io/docs/concepts/services-networking/network-policies/
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: nginx-network-policy
labels:
app: nginx
spec:
podSelector:
matchLabels:
app: nginx
policyTypes:
- Ingress
- Egress
ingress:
- {}
egress:
- {}
Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

+46
View File
@@ -0,0 +1,46 @@
# Source: https://kubernetes.io/docs/concepts/policy/resource-quotas/
apiVersion: v1
kind: List
items:
- apiVersion: v1
kind: ResourceQuota
metadata:
name: pods-high
spec:
hard:
cpu: "1000"
memory: 200Gi
pods: "10"
scopeSelector:
matchExpressions:
- operator : In
scopeName: PriorityClass
values: ["high"]
- apiVersion: v1
kind: ResourceQuota
metadata:
name: pods-medium
spec:
hard:
cpu: "10"
memory: 20Gi
pods: "10"
scopeSelector:
matchExpressions:
- operator : In
scopeName: PriorityClass
values: ["medium"]
- apiVersion: v1
kind: ResourceQuota
metadata:
name: pods-low
spec:
hard:
cpu: "5"
memory: 10Gi
pods: "10"
scopeSelector:
matchExpressions:
- operator : In
scopeName: PriorityClass
values: ["low"]