How to connect to kubernetes internal network using WireGuard

$ kubectl -n kube-system get svc | grep kube-dns | awk '{print $3}'
# output example: 10.124.0.10
apiVersion: v1
kind: Namespace
metadata:
name: wireguard
labels:
name: wireguard
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pv-claim-wireguard
namespace: wireguard
spec:
storageClassName: "standard"
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10M
apiVersion: v1
kind: ConfigMap
metadata:
name: wireguard-configmap
namespace: wireguard
data:
PUID: "1000"
PGID: "1000"
TZ: "America/Mexico_City"
SERVERPORT: "31820"
PEERS: "2"
PEERDNS: "10.124.0.10"
ALLOWEDIPS: "0.0.0.0/0, ::/0"
INTERNAL_SUBNET: "10.13.13.0"
apiVersion: v1
kind: Pod
metadata:
name: wireguard
namespace: wireguard
labels:
app: wireguard
spec:
containers:
- name: wireguard
image: ghcr.io/linuxserver/wireguard
envFrom:
- configMapRef:
name: wireguard-configmap
securityContext:
capabilities:
add:
- NET_ADMIN
- SYS_MODULE
privileged: true
volumeMounts:
- name: wg-config
mountPath: /config
- name: host-volumes
mountPath: /lib/modules
ports:
- containerPort: 51820
protocol: UDP
resources:
requests:
memory: "64Mi"
cpu: "100m"
limits:
memory: "128Mi"
cpu: "200m"
volumes:
- name: wg-config
persistentVolumeClaim:
claimName: pv-claim-wireguard
- name: host-volumes
hostPath:
path: /lib/modules
type: Directory
kind: Service
apiVersion: v1
metadata:
labels:
k8s-app: wireguard
name: wireguard-service
namespace: wireguard
spec:
type: NodePort
ports:
- port: 51820
nodePort: 31820
protocol: UDP
targetPort: 51820
selector:
app: wireguard
$ kubectl apply -f wireguard-pod.yaml
$ kubectl -n wireguard logs wireguard
$ kubectl -n wireguard exec wireguard -- cat /config/peer1/peer1.conf > ~/peer1.conf
$ nmcli connection import type wireguard file ~/peer1.conf
$ nmcli connection up peer1 
$ nmcli connection down peer1
<clusterip-service>.<namespace>.svc.cluster.local
http://thingsboard-service.thingsboard.svc.cluster.local:9090

Conclusion

--

--

--

Engineer || MSc student || DevOps in progress

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Tips for Android App Development

VSCode, GitHub and Go

Scrolling Sprite Background

Python Tutorials

Java Basics — Ep.8

Google Chat Rich Messages Custom Payload in Dialogflow

Python beginner coding experience: Making a calculator app

RASA in AWS ECS…

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ivan Moreno

Ivan Moreno

Engineer || MSc student || DevOps in progress

More from Medium

Using Cincinnati Operator (AKA Update-Service-Operator) in disconnected environments

Gitlab runner in EKS

Kubernetes with Prometheus and Grafana on Amazon EKS — better together

Au!tomating — Monitoring & Nodes

Kubernetes configuration