deployment.yaml 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. {{ include "common.storage.hostPathValidate" .Values }}
  2. apiVersion: {{ template "common.capabilities.deployment.apiVersion" . }}
  3. kind: Deployment
  4. metadata:
  5. name: {{ template "common.names.fullname" . }}-wg
  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. {{- if not .Values.hostNetwork }}
  54. hostPort: null
  55. {{- end }}
  56. - name: web
  57. containerPort: {{ .Values.webUIPort }}
  58. {{- if not .Values.hostNetwork }}
  59. hostPort: null
  60. {{- end }}
  61. env:
  62. {{ $wgeasy := .Values.wgeasy }}
  63. {{ $envList := (default list .Values.environmentVariables) }}
  64. {{ $envList = mustAppend $envList (dict "name" "WG_HOST" "value" $wgeasy.host) }}
  65. {{ $envList = mustAppend $envList (dict "name" "PASSWORD" "value" $wgeasy.password) }}
  66. {{ $envList = mustAppend $envList (dict "name" "WG_PORT" "value" .Values.wgUDPPort) }}
  67. {{ $envList = mustAppend $envList (dict "name" "PORT" "value" .Values.webUIPort) }}
  68. {{ $envList = mustAppend $envList (dict "name" "WG_PERSISTENT_KEEPALIVE" "value" $wgeasy.keep_alive) }}
  69. {{ $envList = mustAppend $envList (dict "name" "WG_MTU" "value" $wgeasy.client_mtu) }}
  70. {{ $envList = mustAppend $envList (dict "name" "WG_DEFAULT_ADDRESS" "value" $wgeasy.client_address_range) }}
  71. {{ $envList = mustAppend $envList (dict "name" "WG_DEFAULT_DNS" "value" $wgeasy.client_dns_server) }}
  72. {{ if $wgeasy.allowed_ips }}
  73. {{ $envList = mustAppend $envList (dict "name" "WG_ALLOWED_IPS" "value" (join "," $wgeasy.allowed_ips)) }}
  74. {{ else }}
  75. {{ $envList = mustAppend $envList (dict "name" "WG_ALLOWED_IPS" "value" ("0.0.0.0/0,::/0")) }}
  76. {{ end }}
  77. {{ include "common.containers.environmentVariables" (dict "environmentVariables" $envList) | nindent 12 }}
  78. readinessProbe:
  79. httpGet:
  80. path: /
  81. port: {{ .Values.webUIPort }}
  82. initialDelaySeconds: 10
  83. periodSeconds: 10
  84. timeoutSeconds: 5
  85. failureThreshold: 5
  86. successThreshold: 2
  87. livenessProbe:
  88. httpGet:
  89. path: /
  90. port: {{ .Values.webUIPort }}
  91. initialDelaySeconds: 10
  92. periodSeconds: 10
  93. timeoutSeconds: 5
  94. failureThreshold: 5
  95. successThreshold: 1
  96. startupProbe:
  97. httpGet:
  98. path: /
  99. port: {{ .Values.webUIPort }}
  100. initialDelaySeconds: 10
  101. periodSeconds: 5
  102. timeoutSeconds: 2
  103. failureThreshold: 60
  104. successThreshold: 1
  105. {{ $ip := .Values.wgeasy.client_address_range | replace "x" "0" }}
  106. lifecycle:
  107. preStop:
  108. exec:
  109. command:
  110. - /bin/bash
  111. - -c
  112. - |
  113. echo "Deleting routes created by the app..."
  114. netmask=$(ip route | grep {{ $ip }})
  115. netmask=$(echo $netmask | grep -o -E '/.\d*')
  116. netmask=${netmask#/}
  117. echo "Matched routes to delete... {{ $ip }}/$netmask"
  118. # Don't try to delete routes if steps above didn't grep-ed anything
  119. if [ ! "$netmask" == "" ]; then
  120. ip route del {{ $ip }}/$netmask || echo "Route deletion failed..."
  121. fi
  122. echo "Routes deleted..."
  123. interface=$(ip a | grep wg0)
  124. if [ ! "$interface" == "" ]; then
  125. echo "Removing wg0 interface..."
  126. ip link delete wg0
  127. echo "Removed wg0 interface..."
  128. fi
  129. {{ include "common.networking.dnsConfiguration" .Values | nindent 6 }}
  130. volumes: {{ include "common.storage.configureAppVolumes" .Values | nindent 8 }}
  131. {{ range $index, $hostPathConfiguration := .Values.extraAppVolumeMounts }}
  132. - name: extrappvolume-{{ $index }}
  133. hostPath:
  134. path: {{ $hostPathConfiguration.hostPath }}
  135. {{ end }}