deployment.yaml 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. {{ include "common.storage.hostPathValidate" .Values }}
  2. apiVersion: {{ template "common.capabilities.deployment.apiVersion" . }}
  3. kind: Deployment
  4. metadata:
  5. name: {{ template "common.names.fullname" . }}
  6. labels:
  7. app: {{ template "common.names.name" . }}
  8. chart: {{ template "common.names.chart" . }}
  9. release: {{ .Release.Name }}
  10. heritage: {{ .Release.Service }}
  11. annotations:
  12. rollme: {{ randAlphaNum 5 | quote }}
  13. spec:
  14. replicas: {{ (default 1 .Values.replicas) }}
  15. strategy:
  16. type: "Recreate"
  17. selector:
  18. matchLabels:
  19. app: {{ template "common.names.name" . }}
  20. release: {{ .Release.Name }}
  21. template:
  22. metadata:
  23. name: {{ template "common.names.fullname" . }}
  24. labels:
  25. {{- include "common.labels.selectorLabels" . | nindent 8 }}
  26. annotations: {{ include "common.annotations" . | nindent 8 }}
  27. spec:
  28. hostNetwork: {{ .Values.hostNetwork }}
  29. hostname: {{ .Release.Name }}
  30. containers:
  31. - name: {{ .Chart.Name }}
  32. {{ include "common.resources.limitation" . | nindent 10 }}
  33. {{ include "common.containers.imageConfig" .Values.image | nindent 10 }}
  34. securityContext:
  35. capabilities:
  36. add:
  37. - NET_ADMIN
  38. - SYS_MODULE
  39. {{/* https://github.com/WeeJeWel/wg-easy/pull/394 */}}
  40. runAsUser: 0
  41. runAsGroup: 0
  42. readOnlyRootFilesystem: false
  43. runAsNonRoot: false
  44. volumeMounts: {{ include "common.storage.configureAppVolumeMountsInContainer" .Values | nindent 12 }}
  45. {{ range $index, $hostPathConfiguration := .Values.extraAppVolumeMounts }}
  46. - name: extrappvolume-{{ $index }}
  47. mountPath: {{ $hostPathConfiguration.mountPath }}
  48. {{ end }}
  49. ports:
  50. - name: udp
  51. containerPort: {{ .Values.wgUDPPort }}
  52. protocol: UDP
  53. - name: web
  54. containerPort: {{ .Values.webUIPort }}
  55. env:
  56. {{ $wgeasy := .Values.wgeasy }}
  57. {{ $envList := (default list .Values.environmentVariables) }}
  58. {{ $envList = mustAppend $envList (dict "name" "WG_HOST" "value" $wgeasy.host) }}
  59. {{ $envList = mustAppend $envList (dict "name" "PASSWORD" "value" $wgeasy.password) }}
  60. {{ $envList = mustAppend $envList (dict "name" "WG_PORT" "value" .Values.wgUDPPort) }}
  61. {{ $envList = mustAppend $envList (dict "name" "PORT" "value" .Values.webUIPort) }}
  62. {{ $envList = mustAppend $envList (dict "name" "WG_PERSISTENT_KEEPALIVE" "value" $wgeasy.keep_alive) }}
  63. {{ $envList = mustAppend $envList (dict "name" "WG_MTU" "value" $wgeasy.client_mtu) }}
  64. {{ $envList = mustAppend $envList (dict "name" "WG_DEFAULT_ADDRESS" "value" $wgeasy.client_address_range) }}
  65. {{ $envList = mustAppend $envList (dict "name" "WG_DEFAULT_DNS" "value" $wgeasy.client_dns_server) }}
  66. {{ if $wgeasy.allowed_ips }}
  67. {{ $envList = mustAppend $envList (dict "name" "WG_ALLOWED_IPS" "value" (join "," $wgeasy.allowed_ips)) }}
  68. {{ else }}
  69. {{ $envList = mustAppend $envList (dict "name" "WG_ALLOWED_IPS" "value" ("0.0.0.0/0,::/0")) }}
  70. {{ end }}
  71. {{ include "common.containers.environmentVariables" (dict "environmentVariables" $envList) | nindent 12 }}
  72. readinessProbe:
  73. httpGet:
  74. path: /
  75. port: {{ .Values.webUIPort }}
  76. failureThreshold: 5
  77. periodSeconds: 15
  78. livenessProbe:
  79. httpGet:
  80. path: /
  81. port: {{ .Values.webUIPort }}
  82. failureThreshold: 5
  83. periodSeconds: 15
  84. startupProbe:
  85. httpGet:
  86. path: /
  87. port: {{ .Values.webUIPort }}
  88. initialDelaySeconds: 5
  89. failureThreshold: 40
  90. periodSeconds: 15
  91. {{ $ip := .Values.wgeasy.client_address_range | replace "x" "0" }}
  92. lifecycle:
  93. preStop:
  94. exec:
  95. command:
  96. - /bin/bash
  97. - -c
  98. - |
  99. echo "Deleting routes created by the app..."
  100. netmask=$(ip route | grep {{ $ip }})
  101. netmask=$(echo $netmask | grep -o -E '/.\d*')
  102. netmask=${netmask#/}
  103. echo "Matched routes to delete... {{ $ip }}/$netmask"
  104. # Don't try to delete routes if steps above didn't grep-ed anything
  105. if [ ! "$netmask" == "" ]; then
  106. ip route del {{ $ip }}/$netmask || echo "Route deletion failed..."
  107. fi
  108. echo "Routes deleted..."
  109. interface=$(ip a | grep wg0)
  110. if [ ! "$interface" == "" ]; then
  111. echo "Removing wg0 interface..."
  112. ip link delete wg0
  113. echo "Removed wg0 interface..."
  114. fi
  115. {{ include "common.networking.dnsConfiguration" .Values | nindent 6 }}
  116. volumes: {{ include "common.storage.configureAppVolumes" .Values | nindent 8 }}
  117. {{ range $index, $hostPathConfiguration := .Values.extraAppVolumeMounts }}
  118. - name: extrappvolume-{{ $index }}
  119. hostPath:
  120. path: {{ $hostPathConfiguration.hostPath }}
  121. {{ end }}