Add cilium chart

This commit is contained in:
Jonny Ervine
2024-07-15 18:18:16 +08:00
parent 9b2e417702
commit 221e0d5590
159 changed files with 37242 additions and 0 deletions
@@ -0,0 +1,51 @@
{{- if and .Values.hubble.enabled .Values.hubble.relay.enabled }}
{{- $peerSvcPort := .Values.hubble.peerService.servicePort -}}
{{- if not .Values.hubble.peerService.servicePort }}
{{- $peerSvcPort = (.Values.hubble.tls.enabled | ternary 443 80) -}}
{{- end }}
---
apiVersion: v1
kind: ConfigMap
metadata:
name: hubble-relay-config
namespace: {{ .Release.Namespace }}
{{- with .Values.hubble.relay.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
data:
config.yaml: |
cluster-name: {{ .Values.cluster.name }}
peer-service: "hubble-peer.{{ .Release.Namespace }}.svc.{{ .Values.hubble.peerService.clusterDomain }}:{{ $peerSvcPort }}"
listen-address: {{ .Values.hubble.relay.listenHost }}:{{ .Values.hubble.relay.listenPort }}
gops: {{ .Values.hubble.relay.gops.enabled }}
gops-port: {{ .Values.hubble.relay.gops.port | quote }}
{{- if .Values.hubble.relay.pprof.enabled }}
pprof: {{ .Values.hubble.relay.pprof.enabled | quote }}
pprof-address: {{ .Values.hubble.relay.pprof.address | quote }}
pprof-port: {{ .Values.hubble.relay.pprof.port | quote }}
{{- end }}
{{- if .Values.hubble.relay.prometheus.enabled }}
metrics-listen-address: ":{{ .Values.hubble.relay.prometheus.port }}"
{{- end }}
dial-timeout: {{ .Values.hubble.relay.dialTimeout }}
retry-timeout: {{ .Values.hubble.relay.retryTimeout }}
sort-buffer-len-max: {{ .Values.hubble.relay.sortBufferLenMax }}
sort-buffer-drain-timeout: {{ .Values.hubble.relay.sortBufferDrainTimeout }}
{{- if .Values.hubble.tls.enabled }}
tls-hubble-client-cert-file: /var/lib/hubble-relay/tls/client.crt
tls-hubble-client-key-file: /var/lib/hubble-relay/tls/client.key
tls-hubble-server-ca-files: /var/lib/hubble-relay/tls/hubble-server-ca.crt
{{- else }}
disable-client-tls: true
{{- end }}
{{- if and .Values.hubble.tls.enabled .Values.hubble.relay.tls.server.enabled }}
tls-relay-server-cert-file: /var/lib/hubble-relay/tls/server.crt
tls-relay-server-key-file: /var/lib/hubble-relay/tls/server.key
{{- if .Values.hubble.relay.tls.server.mtls }}
tls-relay-client-ca-files: /var/lib/hubble-relay/tls/hubble-server-ca.crt
{{- end }}
{{- else }}
disable-server-tls: true
{{- end }}
{{- end }}
@@ -0,0 +1,201 @@
{{- if and .Values.hubble.enabled .Values.hubble.relay.enabled }}
apiVersion: apps/v1
kind: Deployment
metadata:
name: hubble-relay
namespace: {{ .Release.Namespace }}
{{- with .Values.hubble.relay.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
labels:
k8s-app: hubble-relay
app.kubernetes.io/name: hubble-relay
app.kubernetes.io/part-of: cilium
spec:
replicas: {{ .Values.hubble.relay.replicas }}
selector:
matchLabels:
k8s-app: hubble-relay
{{- with .Values.hubble.relay.updateStrategy }}
strategy:
{{- toYaml . | trim | nindent 4 }}
{{- end }}
template:
metadata:
annotations:
{{- if .Values.hubble.relay.rollOutPods }}
# ensure pods roll when configmap updates
cilium.io/hubble-relay-configmap-checksum: {{ include (print $.Template.BasePath "/hubble-relay/configmap.yaml") . | sha256sum | quote }}
{{- end }}
{{- with .Values.hubble.relay.podAnnotations }}
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
k8s-app: hubble-relay
app.kubernetes.io/name: hubble-relay
app.kubernetes.io/part-of: cilium
{{- with .Values.hubble.relay.podLabels }}
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
{{- with .Values.hubble.relay.podSecurityContext }}
securityContext:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
containers:
- name: hubble-relay
{{- with .Values.hubble.relay.securityContext }}
securityContext:
{{- toYaml . | nindent 12 }}
{{- end }}
image: {{ include "cilium.image" .Values.hubble.relay.image | quote }}
imagePullPolicy: {{ .Values.hubble.relay.image.pullPolicy }}
command:
- hubble-relay
args:
- serve
{{- if .Values.debug.enabled }}
- --debug
{{- end }}
ports:
- name: grpc
containerPort: {{ .Values.hubble.relay.listenPort }}
{{- if .Values.hubble.relay.prometheus.enabled }}
- name: prometheus
containerPort: {{ .Values.hubble.relay.prometheus.port }}
protocol: TCP
{{- end }}
readinessProbe:
{{- include "hubble-relay.probe" . | nindent 12 }}
{{- if semverCompare "<1.20-0" .Capabilities.KubeVersion.Version }}
# Starting from Kubernetes 1.20, we are using startupProbe instead
# of this field.
initialDelaySeconds: 5
{{- end }}
livenessProbe:
{{- include "hubble-relay.probe" . | nindent 12 }}
{{- if semverCompare "<1.20-0" .Capabilities.KubeVersion.Version }}
# Starting from Kubernetes 1.20, we are using startupProbe instead
# of this field.
initialDelaySeconds: 60
{{- end }}
{{- if semverCompare ">=1.20-0" .Capabilities.KubeVersion.Version }}
startupProbe:
# give the relay one minute to start up
{{- include "hubble-relay.probe" . | nindent 12 }}
failureThreshold: 20
periodSeconds: 3
{{- end }}
{{- with .Values.hubble.relay.extraEnv }}
env:
{{- toYaml . | trim | nindent 12 }}
{{- end }}
{{- with .Values.hubble.relay.resources }}
resources:
{{- toYaml . | trim | nindent 12 }}
{{- end }}
volumeMounts:
- name: config
mountPath: /etc/hubble-relay
readOnly: true
{{- if .Values.hubble.tls.enabled }}
- name: tls
mountPath: /var/lib/hubble-relay/tls
readOnly: true
{{- end }}
{{- with .Values.hubble.relay.extraVolumeMounts }}
{{- toYaml . | nindent 10 }}
{{- end }}
terminationMessagePolicy: FallbackToLogsOnError
restartPolicy: Always
priorityClassName: {{ .Values.hubble.relay.priorityClassName }}
serviceAccount: {{ .Values.serviceAccounts.relay.name | quote }}
serviceAccountName: {{ .Values.serviceAccounts.relay.name | quote }}
automountServiceAccountToken: {{ .Values.serviceAccounts.relay.automount }}
terminationGracePeriodSeconds: {{ .Values.hubble.relay.terminationGracePeriodSeconds }}
{{- with .Values.hubble.relay.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.hubble.relay.topologySpreadConstraints }}
topologySpreadConstraints:
{{- range $constraint := . }}
- {{ toYaml $constraint | nindent 8 | trim }}
{{- if not $constraint.labelSelector }}
labelSelector:
matchLabels:
k8s-app: hubble-relay
{{- end }}
{{- end }}
{{- end }}
{{- with .Values.hubble.relay.nodeSelector }}
nodeSelector:
{{- toYaml . | trim | nindent 8 }}
{{- end }}
{{- with .Values.hubble.relay.tolerations }}
tolerations:
{{- toYaml . | trim | nindent 8 }}
{{- end }}
volumes:
- name: config
configMap:
name: hubble-relay-config
items:
- key: config.yaml
path: config.yaml
{{- if .Values.hubble.tls.enabled }}
- name: tls
projected:
# note: the leading zero means this number is in octal representation: do not remove it
defaultMode: 0400
sources:
- secret:
name: hubble-relay-client-certs
items:
- key: tls.crt
path: client.crt
- key: tls.key
path: client.key
{{- if not .Values.tls.caBundle.enabled }}
- key: ca.crt
path: hubble-server-ca.crt
{{- else }}
- {{ .Values.tls.caBundle.useSecret | ternary "secret" "configMap" }}:
name: {{ .Values.tls.caBundle.name }}
items:
- key: {{ .Values.tls.caBundle.key }}
path: hubble-server-ca.crt
{{- end }}
{{- if .Values.hubble.relay.tls.server.enabled }}
- secret:
name: hubble-relay-server-certs
items:
- key: tls.crt
path: server.crt
- key: tls.key
path: server.key
{{- end }}
{{- end }}
{{- with .Values.hubble.relay.extraVolumes }}
{{- toYaml . | nindent 6 }}
{{- end }}
{{- end }}
{{- define "hubble-relay.probe" }}
{{- /* This distinction can be removed once we drop support for k8s 1.23 */}}
{{- if semverCompare ">=1.24-0" .Capabilities.KubeVersion.Version -}}
grpc:
port: 4222
{{- else }}
exec:
command:
- grpc_health_probe
- -addr=localhost:4222
{{- end }}
timeoutSeconds: 3
{{- end }}
@@ -0,0 +1,24 @@
{{- if and .Values.hubble.enabled .Values.hubble.relay.enabled .Values.hubble.relay.prometheus.enabled }}
# We use a separate service from hubble-relay which can be exposed externally
kind: Service
apiVersion: v1
metadata:
name: hubble-relay-metrics
namespace: {{ .Release.Namespace }}
{{- with .Values.hubble.relay.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
labels:
k8s-app: hubble-relay
spec:
clusterIP: None
type: ClusterIP
selector:
k8s-app: hubble-relay
ports:
- name: metrics
port: {{ .Values.hubble.relay.prometheus.port }}
protocol: TCP
targetPort: prometheus
{{- end }}
@@ -0,0 +1,26 @@
{{- if and .Values.hubble.enabled .Values.hubble.relay.enabled .Values.hubble.relay.podDisruptionBudget.enabled }}
{{- $component := .Values.hubble.relay.podDisruptionBudget }}
apiVersion: {{ include "podDisruptionBudget.apiVersion" . }}
kind: PodDisruptionBudget
metadata:
name: hubble-relay
namespace: {{ .Release.Namespace }}
{{- with .Values.hubble.relay.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
labels:
k8s-app: hubble-relay
app.kubernetes.io/name: hubble-relay
app.kubernetes.io/part-of: cilium
spec:
{{- with $component.maxUnavailable }}
maxUnavailable: {{ . }}
{{- end }}
{{- with $component.minAvailable }}
minAvailable: {{ . }}
{{- end }}
selector:
matchLabels:
k8s-app: hubble-relay
{{- end }}
@@ -0,0 +1,30 @@
{{- if and .Values.hubble.enabled .Values.hubble.relay.enabled }}
kind: Service
apiVersion: v1
metadata:
name: hubble-relay
namespace: {{ .Release.Namespace }}
{{- with .Values.hubble.relay.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
labels:
k8s-app: hubble-relay
app.kubernetes.io/name: hubble-relay
app.kubernetes.io/part-of: cilium
spec:
type: {{ .Values.hubble.relay.service.type | quote }}
selector:
k8s-app: hubble-relay
ports:
- protocol: TCP
{{- if .Values.hubble.relay.servicePort }}
port: {{ .Values.hubble.relay.servicePort }}
{{- else }}
port: {{ .Values.hubble.relay.tls.server.enabled | ternary 443 80 }}
{{- end }}
targetPort: {{ .Values.hubble.relay.listenPort }}
{{- if and (eq "NodePort" .Values.hubble.relay.service.type) .Values.hubble.relay.service.nodePort }}
nodePort: {{ .Values.hubble.relay.service.nodePort }}
{{- end }}
{{- end }}
@@ -0,0 +1,16 @@
{{- if and .Values.hubble.enabled .Values.hubble.relay.enabled .Values.serviceAccounts.relay.create }}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ .Values.serviceAccounts.relay.name | quote }}
namespace: {{ .Release.Namespace }}
{{- if or .Values.serviceAccounts.relay.annotations .Values.hubble.relay.annotations }}
annotations:
{{- with .Values.hubble.relay.annotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.serviceAccounts.relay.annotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
{{- end }}
@@ -0,0 +1,39 @@
{{- if and .Values.hubble.enabled .Values.hubble.relay.enabled .Values.hubble.relay.prometheus.enabled .Values.hubble.relay.prometheus.serviceMonitor.enabled }}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: hubble-relay
namespace: {{ .Values.hubble.relay.prometheus.serviceMonitor.namespace | default .Release.Namespace }}
labels:
{{- with .Values.hubble.relay.prometheus.serviceMonitor.labels }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- if or .Values.hubble.relay.prometheus.serviceMonitor.annotations .Values.hubble.relay.annotations }}
annotations:
{{- with .Values.hubble.relay.annotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.hubble.relay.prometheus.serviceMonitor.annotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
spec:
selector:
matchLabels:
k8s-app: hubble-relay
namespaceSelector:
matchNames:
- {{ .Release.Namespace }}
endpoints:
- port: metrics
interval: {{ .Values.hubble.relay.prometheus.serviceMonitor.interval | quote }}
path: /metrics
{{- with .Values.hubble.relay.prometheus.serviceMonitor.relabelings }}
relabelings:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.hubble.relay.prometheus.serviceMonitor.metricRelabelings }}
metricRelabelings:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}