项目作者: mateothegreat

项目描述 :
OpenVPN @ Kubernetes, Secure LAN access. Keep it buttoned up!
高级语言: Makefile
项目地址: git://github.com/mateothegreat/k8-byexamples-openvpn.git
创建时间: 2018-02-04T00:22:08Z
项目社区:https://github.com/mateothegreat/k8-byexamples-openvpn

开源协议:MIT License

下载


Clickity click
Twitter Follow Skype Contact

OpenVPN @ Kubernetes, Secure LAN access. Keep it buttoned up!

k8 by example — straight to the point, simple execution.

Easy start:

  1. make deploy install
  2. <push your docker image>
  3. make issue-cert NAME=myuser-1

Getting Started

Export your configuration variables (keeps you from having to pass these on each command):

  1. export NS=infra
  2. export CN=k8.yomateo.io
  3. export REMOTE_TAG=gcr.io/bebuildin/cluster-1/infra-openvpn:latest
  4. ```
  5. First we need to generate the certificates used for issuing client certs:
  6. ```sh
  7. $ make prepare
  8. docker volume create --name openvpn-data
  9. openvpn-data
  10. $ make pki
  11. docker run --net=none -v openvpn-data:/etc/openvpn --rm -it -e EASYRSA_KEY_SIZE=1024 kylemanna/openvpn ovpn_initpki nopass yes
  12. WARNING!!!
  13. You are about to remove the EASYRSA_PKI at: /etc/openvpn/pki
  14. and initialize a fresh PKI here.
  15. ...
  16. $ make config
  17. Disable default push of 'block-outside-dns'
  18. Processing PUSH Config: 'dhcp-option DNS 10.15.240.10'
  19. Processing PUSH Config: 'route 10.12.0.0 255.255.0.0'
  20. Processing PUSH Config: 'route 10.15.0.0 255.255.0.0'
  21. Processing PUSH Config: 'dhcp-option DOMAIN cluster.local'
  22. Processing PUSH Config: 'dhcp-option DOMAIN svc.cluster.local'
  23. Processing PUSH Config: 'dhcp-option DOMAIN default.svc.cluster.local'
  24. Successfully generated config

Now you can build the openvpn docker image with configs baked into it:

  1. $ make build push-gcloud
  2. docker build --rm --tag proliant:1.0.0 .
  3. Sending build context to Docker daemon 92.16 kB
  4. Step 1/2 : FROM kylemanna/openvpn:2.4
  5. ---> 532821c851ac
  6. Step 2/2 : COPY openvpn/server /etc/openvpn
  7. ---> Using cache
  8. ---> 137c013cd054
  9. Successfully built 137c013cd054
  10. Successfully tagged proliant:1.0.0
  11. docker tag proliant:1.0.0 gcr.io/streaming-platform-devqa/cluster-2/infra-openvpn:latest
  12. gcloud docker -- push gcr.io/streaming-platform-devqa/cluster-2/infra-openvpn:latest
  13. The push refers to repository [gcr.io/streaming-platform-devqa/cluster-2/infra-openvpn]
  14. 679835a0c90c: Layer already exists
  15. b8a94757e349: Layer already exists
  16. 2c2c4b7741e1: Layer already exists
  17. 74a92dc69120: Layer already exists
  18. 0e7ecc5cec9e: Layer already exists
  19. 5bef08742407: Layer already exists
  20. latest: digest: sha256:8bface219796f32f0e6507d6a391a7d35a5c4dbd0794dcc213cbe3594f280b81 size: 1571

Now we just need to deploy our kubernetes resources using the new docker image!

  1. $ make deploy
  2. deployment "openvpn" unchanged
  3. service "openvpn" unchanged

Generate certificates

This will run inside a docker container and store your cert data (CA, etc..) using a docker volume.

  1. make issue-myclient-123

Your vpn client config will be in the current directory when finished.

Cleanup

You can delete all resources deployed and data by running

  1. make rollback clean

DNS Resolution

It even works on windows :o

  1. PS C:\Windows\system32> nslookup kubernetes
  2. Server: kube-dns.kube-system.svc.cluster.local
  3. Address: 10.15.240.10
  4. Non-authoritative answer:
  5. Name: kubernetes.default.svc.cluster.local
  6. Address: 10.15.240.1
  7. PS C:\Windows\system32> nslookup kubernetes.default
  8. Server: kube-dns.kube-system.svc.cluster.local
  9. Address: 10.15.240.10
  10. Non-authoritative answer:
  11. Name: kubernetes.default.svc.cluster.local
  12. Address: 10.15.240.1
  13. PS C:\Windows\system32> nslookup kubernetes.default.svc
  14. Server: kube-dns.kube-system.svc.cluster.local
  15. Address: 10.15.240.10
  16. Non-authoritative answer:
  17. Name: kubernetes.default.svc.cluster.local
  18. Address: 10.15.240.1
  19. PS C:\Windows\system32> nslookup kubernetes.default.svc.cluster.local
  20. Server: kube-dns.kube-system.svc.cluster.local
  21. Address: 10.15.240.10
  22. Non-authoritative answer:
  23. Name: kubernetes.default.svc.cluster.local
  24. Address: 10.15.240.1
  25. PS C:\Windows\system32> nslookup google.com
  26. Server: kube-dns.kube-system.svc.cluster.local
  27. Address: 10.15.240.10
  28. Non-authoritative answer:
  29. Name: google.com
  30. Addresses: 2607:f8b0:4001:c14::8a
  31. 74.125.124.138
  32. 74.125.124.139
  33. 74.125.124.113
  34. 74.125.124.102
  35. 74.125.124.101
  36. 74.125.124.100

See also