| giolekva | 6b879db | 2020-06-10 21:00:39 +0400 | [diff] [blame] | 1 | kind: Secret |
| 2 | apiVersion: v1 |
| 3 | metadata: |
| 4 | name: wg-secret |
| 5 | namespace: wireguard |
| 6 | type: Opaque |
| 7 | data: |
| 8 | # Generate and encode the server private key: `wg genkey | base64` |
| 9 | privatekey: Z0hnaVdNdDJjbzhKQ2JyT05HWnlLTEFpYnVKaUJRdFlUZzJ0RlJkS1NrST0K |
| 10 | --- |
| 11 | kind: ConfigMap |
| 12 | apiVersion: v1 |
| 13 | metadata: |
| 14 | name: wg-configmap |
| 15 | namespace: wireguard |
| 16 | data: |
| 17 | wg0.conf: | |
| 18 | [Interface] |
| 19 | Address = 10.0.0.1/24 |
| 20 | ListenPort = 51820 |
| 21 | PostUp = wg set wg0 private-key /etc/wireguard/privatekey; iptables -A FORWARD -i %i -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE |
| 22 | PostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE |
| 23 | # PostUp = wg set wg0 private-key /etc/wireguard/privatekey && iptables -t nat -A POSTROUTING -s 0.0.0.0/0 -o eth0 -j MASQUERADE |
| 24 | # PostDown = iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE |
| 25 | # PostUp = wg set wg0 private-key /etc/wireguard/privatekey && iptables -A FORWARD -i %i -j ACCEPT && iptables -A FORWARD -o %i -j ACCEPT && iptables -t nat -A POSTROUTING -s 10.0.0.0/24 -o eth0 -j MASQUERADE |
| 26 | # PostDown = iptables -D FORWARD -i %i -j ACCEPT && iptables -D FORWARD -o %i -j ACCEPT && iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE |
| 27 | DNS = 8.8.8.8 |
| 28 | |
| 29 | [Peer] |
| 30 | PublicKey = ES2NAzBw/ZVWu14blA2/UiQBVfeuxZpstbZbkEAuzUo= |
| 31 | AllowedIPs = 10.0.0.2/24 |
| 32 | --- |
| 33 | kind: Service |
| 34 | apiVersion: v1 |
| 35 | metadata: |
| 36 | name: wireguard |
| 37 | namespace: wireguard |
| 38 | labels: |
| 39 | app: wireguard |
| 40 | spec: |
| 41 | type: LoadBalancer |
| 42 | ports: |
| 43 | - name: wg |
| 44 | protocol: UDP |
| 45 | port: 51820 |
| 46 | targetPort: 51820 |
| 47 | selector: |
| 48 | app: wireguard |
| 49 | --- |
| 50 | apiVersion: apps/v1 |
| 51 | kind: Deployment |
| 52 | metadata: |
| 53 | name: wireguard |
| 54 | namespace: wireguard |
| 55 | spec: |
| 56 | replicas: 1 |
| 57 | selector: |
| 58 | matchLabels: |
| 59 | app: wireguard |
| 60 | template: |
| 61 | metadata: |
| 62 | labels: |
| 63 | app: wireguard |
| 64 | spec: |
| 65 | initContainers: |
| 66 | - name: sysctls |
| 67 | image: busybox |
| 68 | command: |
| 69 | - sh |
| 70 | - -c |
| 71 | - sysctl -w net.ipv4.ip_forward=1 && sysctl -w net.ipv4.conf.all.forwarding=1 |
| 72 | securityContext: |
| 73 | capabilities: |
| 74 | add: |
| 75 | - NET_ADMIN |
| 76 | privileged: true |
| 77 | containers: |
| 78 | - name: wireguard |
| 79 | image: giolekva/wireguard:latest |
| 80 | command: |
| 81 | - sh |
| 82 | - -c |
| 83 | - echo "Public key '$(wg pubkey < /etc/wireguard/privatekey)'" && sysctl -w net.ipv4.ip_forward=1 && sysctl -w net.ipv4.conf.all.forwarding=1 && /entrypoint.sh |
| 84 | ports: |
| 85 | - containerPort: 51820 |
| 86 | protocol: UDP |
| 87 | name: wireguard |
| 88 | env: |
| 89 | - name: LOG_LEVEL |
| 90 | value: debug |
| 91 | securityContext: |
| 92 | capabilities: |
| 93 | add: |
| 94 | - NET_ADMIN |
| 95 | privileged: true |
| 96 | resources: |
| 97 | requests: |
| 98 | memory: 64Mi |
| 99 | cpu: "100m" |
| 100 | limits: |
| 101 | memory: 256Mi |
| 102 | volumeMounts: |
| 103 | - name: cfgmap |
| 104 | mountPath: /etc/wireguard/wg0.conf |
| 105 | subPath: wg0.conf |
| 106 | - name: secret |
| 107 | mountPath: /etc/wireguard/privatekey |
| 108 | subPath: privatekey |
| 109 | volumes: |
| 110 | - name: cfgmap |
| 111 | configMap: |
| 112 | name: wg-configmap |
| 113 | - name: secret |
| 114 | secret: |
| 115 | secretName: wg-secret |