deployment.yaml 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. initialDelaySeconds: 10
  77. periodSeconds: 10
  78. timeoutSeconds: 5
  79. failureThreshold: 5
  80. successThreshold: 2
  81. livenessProbe:
  82. httpGet:
  83. path: /
  84. port: {{ .Values.webUIPort }}
  85. initialDelaySeconds: 10
  86. periodSeconds: 10
  87. timeoutSeconds: 5
  88. failureThreshold: 5
  89. successThreshold: 1
  90. startupProbe:
  91. httpGet:
  92. path: /
  93. port: {{ .Values.webUIPort }}
  94. initialDelaySeconds: 10
  95. periodSeconds: 5
  96. timeoutSeconds: 2
  97. failureThreshold: 60
  98. successThreshold: 1
  99. {{ $ip := .Values.wgeasy.client_address_range | replace "x" "0" }}
  100. lifecycle:
  101. preStop:
  102. exec:
  103. command:
  104. - /bin/bash
  105. - -c
  106. - |
  107. echo "Deleting routes created by the app..."
  108. netmask=$(ip route | grep {{ $ip }})
  109. netmask=$(echo $netmask | grep -o -E '/.\d*')
  110. netmask=${netmask#/}
  111. echo "Matched routes to delete... {{ $ip }}/$netmask"
  112. # Don't try to delete routes if steps above didn't grep-ed anything
  113. if [ ! "$netmask" == "" ]; then
  114. ip route del {{ $ip }}/$netmask || echo "Route deletion failed..."
  115. fi
  116. echo "Routes deleted..."
  117. interface=$(ip a | grep wg0)
  118. if [ ! "$interface" == "" ]; then
  119. echo "Removing wg0 interface..."
  120. ip link delete wg0
  121. echo "Removed wg0 interface..."
  122. fi
  123. {{ include "common.networking.dnsConfiguration" .Values | nindent 6 }}
  124. volumes: {{ include "common.storage.configureAppVolumes" .Values | nindent 8 }}
  125. {{ range $index, $hostPathConfiguration := .Values.extraAppVolumeMounts }}
  126. - name: extrappvolume-{{ $index }}
  127. hostPath:
  128. path: {{ $hostPathConfiguration.hostPath }}
  129. {{ end }}