blob: 58644247802a4e8add745d1751fd8b396fd3830a [file] [log] [blame]
giolekva6b879db2020-06-10 21:00:39 +04001kind: Secret
2apiVersion: v1
3metadata:
4 name: wg-secret
5 namespace: wireguard
6type: Opaque
7data:
8 # Generate and encode the server private key: `wg genkey | base64`
9 privatekey: Z0hnaVdNdDJjbzhKQ2JyT05HWnlLTEFpYnVKaUJRdFlUZzJ0RlJkS1NrST0K
10---
11kind: ConfigMap
12apiVersion: v1
13metadata:
14 name: wg-configmap
15 namespace: wireguard
16data:
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---
33kind: Service
34apiVersion: v1
35metadata:
36 name: wireguard
37 namespace: wireguard
38 labels:
39 app: wireguard
40spec:
41 type: LoadBalancer
42 ports:
43 - name: wg
44 protocol: UDP
45 port: 51820
46 targetPort: 51820
47 selector:
48 app: wireguard
49---
50apiVersion: apps/v1
51kind: Deployment
52metadata:
53 name: wireguard
54 namespace: wireguard
55spec:
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