feat(traefik): Add traefik ingress controller configuration

This commit is contained in:
Tanguy Herbron 2024-12-21 22:27:07 +01:00
parent a964118922
commit 93b25589b0
18 changed files with 346 additions and 70 deletions

230
traefik/flannel.yaml Normal file
View File

@ -0,0 +1,230 @@
---
apiVersion: policy/v1beta1
kind: PodSecurityPolicy
metadata:
name: psp.flannel.unprivileged
annotations:
seccomp.security.alpha.kubernetes.io/allowedProfileNames: docker/default
seccomp.security.alpha.kubernetes.io/defaultProfileName: docker/default
apparmor.security.beta.kubernetes.io/allowedProfileNames: runtime/default
apparmor.security.beta.kubernetes.io/defaultProfileName: runtime/default
spec:
privileged: false
volumes:
- configMap
- secret
- emptyDir
- hostPath
allowedHostPaths:
- pathPrefix: "/etc/cni/net.d"
- pathPrefix: "/etc/kube-flannel"
- pathPrefix: "/run/flannel"
readOnlyRootFilesystem: false
# Users and groups
runAsUser:
rule: RunAsAny
supplementalGroups:
rule: RunAsAny
fsGroup:
rule: RunAsAny
# Privilege Escalation
allowPrivilegeEscalation: false
defaultAllowPrivilegeEscalation: false
# Capabilities
allowedCapabilities: ['NET_ADMIN']
defaultAddCapabilities: []
requiredDropCapabilities: []
# Host namespaces
hostPID: false
hostIPC: false
hostNetwork: true
hostPorts:
- min: 0
max: 65535
# SELinux
seLinux:
# SELinux is unused in CaaSP
rule: 'RunAsAny'
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: flannel
rules:
- apiGroups: ['extensions']
resources: ['podsecuritypolicies']
verbs: ['use']
resourceNames: ['psp.flannel.unprivileged']
- apiGroups:
- ""
resources:
- pods
verbs:
- get
- apiGroups:
- ""
resources:
- nodes
verbs:
- list
- watch
- apiGroups:
- ""
resources:
- nodes/status
verbs:
- patch
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: flannel
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: flannel
subjects:
- kind: ServiceAccount
name: flannel
namespace: kube-system
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: flannel
namespace: kube-system
---
kind: ConfigMap
apiVersion: v1
metadata:
name: kube-flannel-cfg
namespace: kube-system
labels:
tier: node
app: flannel
data:
cni-conf.json: |
{
"name": "cbr0",
"cniVersion": "0.3.1",
"plugins": [
{
"type": "flannel",
"delegate": {
"hairpinMode": true,
"isDefaultGateway": true
}
},
{
"type": "portmap",
"capabilities": {
"portMappings": true
}
}
]
}
net-conf.json: |
{
"Network": "${flannel_cidr}",
"Backend": {
"Type": "vxlan"
}
}
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: kube-flannel-ds-amd64
namespace: kube-system
labels:
tier: node
app: flannel
spec:
selector:
matchLabels:
app: flannel
template:
metadata:
labels:
tier: node
app: flannel
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/os
operator: In
values:
- linux
- key: kubernetes.io/arch
operator: In
values:
- amd64
hostNetwork: true
tolerations:
- operator: Exists
effect: NoSchedule
serviceAccountName: flannel
initContainers:
- name: install-cni
image: quay.io/coreos/flannel:v0.12.0-amd64
command:
- cp
args:
- -f
- /etc/kube-flannel/cni-conf.json
- /etc/cni/net.d/10-flannel.conflist
volumeMounts:
- name: cni
mountPath: /etc/cni/net.d
- name: flannel-cfg
mountPath: /etc/kube-flannel/
containers:
- name: kube-flannel
image: quay.io/coreos/flannel:v0.12.0-amd64
command:
- /opt/bin/flanneld
args:
- --ip-masq=false
- --kube-subnet-mgr
- --iface=${interface}
resources:
requests:
cpu: "50m"
memory: "50Mi"
limits:
cpu: "50m"
memory: "50Mi"
securityContext:
privileged: false
capabilities:
add: ["NET_ADMIN"]
env:
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
volumeMounts:
- name: run
mountPath: /run/flannel
- name: flannel-cfg
mountPath: /etc/kube-flannel/
volumes:
- name: run
hostPath:
path: /run/flannel
- name: cni
hostPath:
path: /etc/cni/net.d
- name: flannel-cfg
configMap:
name: kube-flannel-cfg
---

View File

@ -1,5 +1,3 @@
---
# Source: traefik/templates/rbac/clusterrole.yaml
kind: ClusterRole kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1 apiVersion: rbac.authorization.k8s.io/v1
metadata: metadata:
@ -12,12 +10,19 @@ rules:
- "" - ""
resources: resources:
- services - services
- endpoints
- secrets - secrets
- nodes
verbs: verbs:
- get - get
- list - list
- watch - watch
- apiGroups:
- discovery.k8s.io
resources:
- endpointslices
verbs:
- list
- watch
- apiGroups: - apiGroups:
- extensions - extensions
- networking.k8s.io - networking.k8s.io
@ -36,17 +41,18 @@ rules:
verbs: verbs:
- update - update
- apiGroups: - apiGroups:
- traefik.containo.us - traefik.io
resources: resources:
- ingressroutes
- ingressroutetcps
- ingressrouteudps
- middlewares - middlewares
- middlewaretcps - middlewaretcps
- ingressroutes
- traefikservices
- ingressroutetcps
- ingressrouteudps
- tlsoptions - tlsoptions
- tlsstores - tlsstores
- traefikservices
- serverstransports - serverstransports
- serverstransporttcps
verbs: verbs:
- get - get
- list - list

View File

@ -14,5 +14,3 @@ roleRef:
subjects: subjects:
- kind: ServiceAccount - kind: ServiceAccount
name: traefik name: traefik
namespace: default

View File

@ -5,5 +5,3 @@ metadata:
labels: labels:
app.kubernetes.io/name: traefik app.kubernetes.io/name: traefik
app.kubernetes.io/instance: traefik app.kubernetes.io/instance: traefik
annotations:

View File

@ -1,5 +1,4 @@
--- ---
# Source: traefik/templates/deployment.yaml
apiVersion: apps/v1 apiVersion: apps/v1
kind: Deployment kind: Deployment
metadata: metadata:
@ -7,9 +6,8 @@ metadata:
labels: labels:
app.kubernetes.io/name: traefik app.kubernetes.io/name: traefik
app.kubernetes.io/instance: traefik app.kubernetes.io/instance: traefik
annotations:
spec: spec:
replicas: 1 replicas: 2
selector: selector:
matchLabels: matchLabels:
app.kubernetes.io/name: traefik app.kubernetes.io/name: traefik
@ -30,11 +28,18 @@ spec:
app.kubernetes.io/name: traefik app.kubernetes.io/name: traefik
app.kubernetes.io/instance: traefik app.kubernetes.io/instance: traefik
spec: spec:
topologySpreadConstraints:
- maxSkew: 1
topologyKey: kubernetes.io/hostname
whenUnsatisfiable: DoNotSchedule
labelSelector:
matchLabels:
app.kubernetes.io/name: traefik
serviceAccountName: traefik serviceAccountName: traefik
terminationGracePeriodSeconds: 60 terminationGracePeriodSeconds: 60
hostNetwork: false hostNetwork: true
containers: containers:
- image: "traefik:2.8.4" - image: "traefik:3.2.1"
imagePullPolicy: IfNotPresent imagePullPolicy: IfNotPresent
name: traefik name: traefik
resources: resources:
@ -89,13 +94,20 @@ spec:
- name: tmp - name: tmp
mountPath: /tmp mountPath: /tmp
args: args:
- "--global.checknewversion"
- "--entrypoints.admin.address=:8080/tcp" - "--entrypoints.admin.address=:8080/tcp"
- "--entrypoints.metrics.address=:9100/tcp" - "--entrypoints.metrics.address=:9100/tcp"
- "--entrypoints.minecrafttcp.address=:25565/tcp" - "--entrypoints.minecrafttcp.address=:25565/tcp"
- "--entrypoints.traefik.address=:9000/tcp" - "--entrypoints.traefik.address=:9000/tcp"
- "--entrypoints.web.address=:8000/tcp" - "--entrypoints.web.address=:8000/tcp"
- "--entrypoints.websecure.address=:8443/tcp" - "--entrypoints.websecure.address=:8443/tcp"
#- "--entryPoints.web.proxyProtocol.insecure=true"
#- "--entryPoints.web.forwardedHeaders.insecure=true"
- "--entryPoints.web.proxyProtocol.trustedIPs=10.20.0.0/24,51.15.80.73/32,192.168.113.0/24"
- "--entryPoints.web.forwardedHeaders.trustedIPs=10.20.0.0/24,51.15.80.73/32,192.168.113.0/24"
#- "--entryPoints.websecure.proxyProtocol.insecure=true"
#- "--entryPoints.websecure.forwardedHeaders.insecure=true"
- "--entryPoints.websecure.proxyProtocol.trustedIPs=10.20.0.0/24,51.15.80.73/32,192.168.113.0/24"
- "--entryPoints.websecure.forwardedHeaders.trustedIPs=10.20.0.0/24,51.15.80.73/32,192.168.113.0/24"
- "--api.dashboard=true" - "--api.dashboard=true"
- "--ping=true" - "--ping=true"
- "--metrics.prometheus=true" - "--metrics.prometheus=true"
@ -108,8 +120,7 @@ spec:
- "--accesslog=true" - "--accesslog=true"
- "--entrypoints.websecure.http.tls=true" - "--entrypoints.websecure.http.tls=true"
- "--entrypoints.websecure.http.tls.certresolver=letsencrypt" - "--entrypoints.websecure.http.tls.certresolver=letsencrypt"
- "--entrypoints.websecure.http.tls.domains[0].main=beta.halia.dev" - "--entrypoints.websecure.http.tls.domains[0].sans=*.halis.io"
- "--entrypoints.websecure.http.tls.domains[0].sans=*.beta.halia.dev"
- "--certificatesresolvers.letsencrypt.acme.tlschallenge=true" - "--certificatesresolvers.letsencrypt.acme.tlschallenge=true"
- "--certificatesresolvers.letsencrypt.acme.dnschallenge=true" - "--certificatesresolvers.letsencrypt.acme.dnschallenge=true"
- "--certificatesresolvers.letsencrypt.acme.dnschallenge.provider=ovh" - "--certificatesresolvers.letsencrypt.acme.dnschallenge.provider=ovh"

View File

@ -5,4 +5,5 @@ resources:
- pvc.yaml - pvc.yaml
- deployment.yaml - deployment.yaml
- service.yaml - service.yaml
- servicemonitor.yaml - loadbalancer.yaml
#- servicemonitor.yaml

View File

@ -0,0 +1,28 @@
apiVersion: v1
kind: Service
metadata:
name: traefik-external
labels:
app.kubernetes.io/name: traefik-external
app.kubernetes.io/instance: traefik-external
spec:
type: LoadBalancer
loadBalancerIP: 51.15.80.73
loadBalancerSourceRanges:
- 0.0.0.0/0
selector:
app.kubernetes.io/name: traefik
app.kubernetes.io/instance: traefik
ports:
- port: 25565
name: minecrafttcp
targetPort: "minecrafttcp"
protocol: TCP
- port: 80
name: web
targetPort: "web"
protocol: TCP
- port: 443
name: websecure
targetPort: "websecure"
protocol: TCP

View File

@ -1,18 +1,15 @@
--- ---
# Source: traefik/templates/pvc.yaml
apiVersion: v1 apiVersion: v1
kind: PersistentVolumeClaim kind: PersistentVolumeClaim
metadata: metadata:
name: traefik name: traefik
annotations:
helm.sh/resource-policy: keep
labels: labels:
app.kubernetes.io/name: traefik app.kubernetes.io/name: traefik
app.kubernetes.io/instance: traefik app.kubernetes.io/instance: traefik
spec: spec:
accessModes: accessModes:
- "ReadWriteOnce" - "ReadWriteMany"
resources: resources:
requests: requests:
storage: "128Mi" storage: "128Mi"
storageClassName: "local-path" storageClassName: "redundant-storage-class"

View File

@ -2,7 +2,6 @@ apiVersion: v1
kind: Service kind: Service
metadata: metadata:
name: traefik-dashboard-svc name: traefik-dashboard-svc
namespace: default
spec: spec:
ports: ports:
- name: admin - name: admin

View File

@ -1,32 +1,16 @@
---
# Source: traefik/templates/service.yaml
apiVersion: v1 apiVersion: v1
kind: Service kind: Service
metadata: metadata:
name: traefik-external name: traefik-external-metrics
labels: labels:
app.kubernetes.io/name: traefik-external app.kubernetes.io/name: traefik-external
app.kubernetes.io/instance: traefik-external app.kubernetes.io/instance: traefik-external
annotations: annotations:
spec: spec:
type: LoadBalancer
loadBalancerIP: 51.15.80.73
selector: selector:
app.kubernetes.io/name: traefik app.kubernetes.io/name: traefik
app.kubernetes.io/instance: traefik app.kubernetes.io/instance: traefik
ports: ports:
- port: 25565
name: minecrafttcp
targetPort: "minecrafttcp"
protocol: TCP
- port: 80 # Change port here to accomodate for internal only services
name: web
targetPort: "web"
protocol: TCP
- port: 443
name: websecure
targetPort: "websecure"
protocol: TCP
- port: 9100 - port: 9100
name: metrics name: metrics
targetPort: "metrics" targetPort: "metrics"

View File

@ -2,8 +2,7 @@ apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor kind: ServiceMonitor
metadata: metadata:
name: traefik-external name: traefik-external
labels: namespace: traefik
team: core
spec: spec:
selector: selector:
matchLabels: matchLabels:

View File

@ -0,0 +1,7 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: general-purpose-dev-config
data:
lb-ip: 10.10.0.32

View File

@ -1,5 +1,4 @@
--- ---
# Source: traefik/templates/deployment.yaml
apiVersion: apps/v1 apiVersion: apps/v1
kind: Deployment kind: Deployment
metadata: metadata:
@ -7,9 +6,8 @@ metadata:
labels: labels:
app.kubernetes.io/name: traefik-inter app.kubernetes.io/name: traefik-inter
app.kubernetes.io/instance: traefik-inter app.kubernetes.io/instance: traefik-inter
annotations:
spec: spec:
replicas: 1 replicas: 2
selector: selector:
matchLabels: matchLabels:
app.kubernetes.io/name: traefik-inter app.kubernetes.io/name: traefik-inter
@ -30,11 +28,18 @@ spec:
app.kubernetes.io/name: traefik-inter app.kubernetes.io/name: traefik-inter
app.kubernetes.io/instance: traefik-inter app.kubernetes.io/instance: traefik-inter
spec: spec:
topologySpreadConstraints:
- maxSkew: 1
topologyKey: kubernetes.io/hostname
whenUnsatisfiable: DoNotSchedule
labelSelector:
matchLabels:
app.kubernetes.io/name: traefik-inter
serviceAccountName: traefik serviceAccountName: traefik
terminationGracePeriodSeconds: 60 terminationGracePeriodSeconds: 60
hostNetwork: false hostNetwork: false
containers: containers:
- image: "traefik:2.8.4" - image: "traefik:3.2.1"
imagePullPolicy: IfNotPresent imagePullPolicy: IfNotPresent
name: traefik-inter name: traefik-inter
resources: resources:
@ -92,6 +97,10 @@ spec:
- "--entrypoints.traefik.address=:9000/tcp" - "--entrypoints.traefik.address=:9000/tcp"
- "--entrypoints.web.address=:8000/tcp" - "--entrypoints.web.address=:8000/tcp"
- "--entrypoints.websecure.address=:8443/tcp" - "--entrypoints.websecure.address=:8443/tcp"
- "--entryPoints.web.proxyProtocol.insecure"
- "--entryPoints.web.forwardedHeaders.insecure"
- "--entryPoints.websecure.proxyProtocol.insecure"
- "--entryPoints.websecure.forwardedHeaders.insecure"
- "--api.dashboard=true" - "--api.dashboard=true"
- "--api.insecure=true" - "--api.insecure=true"
- "--ping=true" - "--ping=true"

View File

@ -5,4 +5,5 @@ resources:
- pvc.yaml - pvc.yaml
- deployment.yaml - deployment.yaml
- service.yaml - service.yaml
- servicemonitor.yaml - loadbalancer.yaml
#- servicemonitor.yaml

View File

@ -0,0 +1,22 @@
apiVersion: v1
kind: Service
metadata:
name: traefik-internal
labels:
app.kubernetes.io/name: traefik-inter
app.kubernetes.io/instance: traefik-inter
spec:
type: LoadBalancer
loadBalancerIP: 10.10.0.16
selector:
app.kubernetes.io/name: traefik-inter
app.kubernetes.io/instance: traefik-inter
ports:
- port: 80
name: web
targetPort: "web"
protocol: TCP
- port: 443
name: websecure
targetPort: "websecure"
protocol: TCP

View File

@ -1,18 +1,15 @@
--- ---
# Source: traefik/templates/pvc.yaml
apiVersion: v1 apiVersion: v1
kind: PersistentVolumeClaim kind: PersistentVolumeClaim
metadata: metadata:
name: traefik-inter name: traefik-inter
annotations:
helm.sh/resource-policy: keep
labels: labels:
app.kubernetes.io/name: traefik-inter app.kubernetes.io/name: traefik-inter
app.kubernetes.io/instance: traefik-inter app.kubernetes.io/instance: traefik-inter
spec: spec:
accessModes: accessModes:
- "ReadWriteOnce" - "ReadWriteMany"
resources: resources:
requests: requests:
storage: "128Mi" storage: "128Mi"
storageClassName: "local-path" storageClassName: "redundant-storage-class"

View File

@ -1,26 +1,15 @@
apiVersion: v1 apiVersion: v1
kind: Service kind: Service
metadata: metadata:
name: traefik-internal name: traefik-internal-metrics
namespace: default
labels: labels:
app.kubernetes.io/name: traefik-inter app.kubernetes.io/name: traefik-inter
app.kubernetes.io/instance: traefik-inter app.kubernetes.io/instance: traefik-inter
spec: spec:
type: LoadBalancer
loadBalancerIP: 192.168.56.101
selector: selector:
app.kubernetes.io/name: traefik-inter app.kubernetes.io/name: traefik-inter
app.kubernetes.io/instance: traefik-inter app.kubernetes.io/instance: traefik-inter
ports: ports:
- port: 80
name: web
targetPort: "web"
protocol: TCP
- port: 443
name: websecure
targetPort: "websecure"
protocol: TCP
- port: 9100 - port: 9100
name: metrics name: metrics
targetPort: "metrics" targetPort: "metrics"

View File

@ -2,12 +2,12 @@ apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor kind: ServiceMonitor
metadata: metadata:
name: traefik-inter name: traefik-inter
labels: namespace: traefik
team: core
spec: spec:
selector: selector:
matchLabels: matchLabels:
app.kubernetes.io/name: traefik-inter app.kubernetes.io/name: traefik-inter
app.kubernetes.io/instance: traefik-inter
endpoints: endpoints:
- port: metrics - port: metrics
path: /metrics path: /metrics