├── 01-namespace.yaml ├── 02-pvc.yaml ├── 03-nodeports.yaml ├── 04-mqtt-configmap.yaml ├── 05-netmaker-backend.yaml ├── 06-netmaker-mq.yaml ├── 07-netmaker-ui,yaml ├── 08-ingress.yaml ├── 90-network-deny.yaml ├── 91-allow-internet.yaml ├── 94-netmaker.yaml ├── LICENSE ├── README.md ├── traefik-http.jpg └── traefik-tcp.jpg /01-namespace.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Namespace 3 | metadata: 4 | name: netmaker 5 | labels: 6 | networking/namespace: netmaker 7 | -------------------------------------------------------------------------------- /02-pvc.yaml: -------------------------------------------------------------------------------- 1 | 2 | #mkdir -p /srv/netmaker/nm-dnsconfig-pvc 3 | #mkdir -p /srv/netmaker/nm-sqldata-pvc 4 | #mkdir -p /srv/netmaker/nm-mq-certs 5 | #mkdir -p /srv/netmaker/nm-mq-log 6 | #mkdir -p /srv/netmaker/nm-mq-data 7 | #chmod 777 /srv/netmaker/* 8 | 9 | --- 10 | apiVersion: v1 11 | kind: PersistentVolume 12 | metadata: 13 | name: nm-pv-dnsconfig-backend 14 | namespace: netmaker 15 | spec: 16 | capacity: 17 | storage: 128Mi 18 | accessModes: 19 | - ReadWriteOnce 20 | persistentVolumeReclaimPolicy: Retain 21 | storageClassName: local-path 22 | local: 23 | path: /srv/netmaker/nm-dnsconfig-pvc 24 | nodeAffinity: 25 | required: 26 | nodeSelectorTerms: 27 | - matchExpressions: 28 | - key: kubernetes.io/hostname 29 | operator: In 30 | values: 31 | - HOSTNAME 32 | --- 33 | kind: PersistentVolumeClaim 34 | apiVersion: v1 35 | metadata: 36 | name: nm-pvc-dnsconfig-backend 37 | namespace: netmaker 38 | spec: 39 | accessModes: 40 | - ReadWriteOnce 41 | storageClassName: local-path 42 | resources: 43 | requests: 44 | storage: 128Mi 45 | volumeName: nm-pv-dnsconfig-backend 46 | 47 | 48 | --- 49 | apiVersion: v1 50 | kind: PersistentVolume 51 | metadata: 52 | name: nm-pv-dnsconfig-coredns 53 | namespace: netmaker 54 | spec: 55 | capacity: 56 | storage: 128Mi 57 | accessModes: 58 | - ReadWriteOnce 59 | persistentVolumeReclaimPolicy: Retain 60 | storageClassName: local-path 61 | local: 62 | path: /srv/netmaker/nm-dnsconfig-pvc 63 | nodeAffinity: 64 | required: 65 | nodeSelectorTerms: 66 | - matchExpressions: 67 | - key: kubernetes.io/hostname 68 | operator: In 69 | values: 70 | - HOSTNAME 71 | --- 72 | kind: PersistentVolumeClaim 73 | apiVersion: v1 74 | metadata: 75 | name: nm-pvc-dnsconfig-coredns 76 | namespace: netmaker 77 | spec: 78 | accessModes: 79 | - ReadWriteOnce 80 | storageClassName: local-path 81 | resources: 82 | requests: 83 | storage: 128Mi 84 | volumeName: nm-pv-dnsconfig-coredns 85 | 86 | 87 | --- 88 | apiVersion: v1 89 | kind: PersistentVolume 90 | metadata: 91 | name: nm-pv-sqldata 92 | namespace: netmaker 93 | spec: 94 | capacity: 95 | storage: 1Gi 96 | accessModes: 97 | - ReadWriteOnce 98 | persistentVolumeReclaimPolicy: Retain 99 | storageClassName: local-path 100 | local: 101 | path: /srv/netmaker/nm-sqldata-pvc 102 | nodeAffinity: 103 | required: 104 | nodeSelectorTerms: 105 | - matchExpressions: 106 | - key: kubernetes.io/hostname 107 | operator: In 108 | values: 109 | - HOSTNAME 110 | --- 111 | kind: PersistentVolumeClaim 112 | apiVersion: v1 113 | metadata: 114 | name: nm-pvc-sqldata 115 | namespace: netmaker 116 | spec: 117 | accessModes: 118 | - ReadWriteOnce 119 | storageClassName: local-path 120 | resources: 121 | requests: 122 | storage: 1Gi 123 | volumeName: nm-pv-sqldata 124 | 125 | 126 | --- 127 | apiVersion: v1 128 | kind: PersistentVolume 129 | metadata: 130 | name: nm-pv-mq-certs-mq 131 | namespace: netmaker 132 | spec: 133 | capacity: 134 | storage: 128Mi 135 | accessModes: 136 | - ReadWriteOnce 137 | persistentVolumeReclaimPolicy: Retain 138 | storageClassName: local-path 139 | local: 140 | path: /srv/netmaker/nm-mq-certs 141 | nodeAffinity: 142 | required: 143 | nodeSelectorTerms: 144 | - matchExpressions: 145 | - key: kubernetes.io/hostname 146 | operator: In 147 | values: 148 | - HOSTNAME 149 | --- 150 | kind: PersistentVolumeClaim 151 | apiVersion: v1 152 | metadata: 153 | name: nm-pvc-mq-certs-mq 154 | namespace: netmaker 155 | spec: 156 | accessModes: 157 | - ReadWriteOnce 158 | storageClassName: local-path 159 | resources: 160 | requests: 161 | storage: 128Mi 162 | volumeName: nm-pv-mq-certs-mq 163 | 164 | 165 | --- 166 | apiVersion: v1 167 | kind: PersistentVolume 168 | metadata: 169 | name: nm-pv-mq-certs-nm 170 | namespace: netmaker 171 | spec: 172 | capacity: 173 | storage: 128Mi 174 | accessModes: 175 | - ReadWriteOnce 176 | persistentVolumeReclaimPolicy: Retain 177 | storageClassName: local-path 178 | local: 179 | path: /srv/netmaker/nm-mq-certs 180 | nodeAffinity: 181 | required: 182 | nodeSelectorTerms: 183 | - matchExpressions: 184 | - key: kubernetes.io/hostname 185 | operator: In 186 | values: 187 | - HOSTNAME 188 | --- 189 | kind: PersistentVolumeClaim 190 | apiVersion: v1 191 | metadata: 192 | name: nm-pvc-mq-certs-nm 193 | namespace: netmaker 194 | spec: 195 | accessModes: 196 | - ReadWriteOnce 197 | storageClassName: local-path 198 | resources: 199 | requests: 200 | storage: 128Mi 201 | volumeName: nm-pv-mq-certs-nm 202 | 203 | 204 | --- 205 | apiVersion: v1 206 | kind: PersistentVolume 207 | metadata: 208 | name: nm-pv-mq-log 209 | namespace: netmaker 210 | spec: 211 | capacity: 212 | storage: 1Gi 213 | accessModes: 214 | - ReadWriteOnce 215 | persistentVolumeReclaimPolicy: Retain 216 | storageClassName: local-path 217 | local: 218 | path: /srv/netmaker/nm-mq-log 219 | nodeAffinity: 220 | required: 221 | nodeSelectorTerms: 222 | - matchExpressions: 223 | - key: kubernetes.io/hostname 224 | operator: In 225 | values: 226 | - HOSTNAME 227 | --- 228 | kind: PersistentVolumeClaim 229 | apiVersion: v1 230 | metadata: 231 | name: nm-pvc-mq-log 232 | namespace: netmaker 233 | spec: 234 | accessModes: 235 | - ReadWriteOnce 236 | storageClassName: local-path 237 | resources: 238 | requests: 239 | storage: 1Gi 240 | volumeName: nm-pv-mq-log 241 | 242 | --- 243 | apiVersion: v1 244 | kind: PersistentVolume 245 | metadata: 246 | name: nm-pv-mq-data 247 | namespace: netmaker 248 | spec: 249 | capacity: 250 | storage: 1Gi 251 | accessModes: 252 | - ReadWriteOnce 253 | persistentVolumeReclaimPolicy: Retain 254 | storageClassName: local-path 255 | local: 256 | path: /srv/netmaker/nm-mq-data 257 | nodeAffinity: 258 | required: 259 | nodeSelectorTerms: 260 | - matchExpressions: 261 | - key: kubernetes.io/hostname 262 | operator: In 263 | values: 264 | - HOSTNAME 265 | --- 266 | kind: PersistentVolumeClaim 267 | apiVersion: v1 268 | metadata: 269 | name: nm-pvc-mq-data 270 | namespace: netmaker 271 | spec: 272 | accessModes: 273 | - ReadWriteOnce 274 | storageClassName: local-path 275 | resources: 276 | requests: 277 | storage: 1Gi 278 | volumeName: nm-pv-mq-data 279 | -------------------------------------------------------------------------------- /03-nodeports.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: netmaker-31821 5 | namespace: netmaker 6 | spec: 7 | type: NodePort 8 | selector: 9 | app: netmaker 10 | ports: 11 | - port: 31821 12 | targetPort: 31821 13 | nodePort: 31821 14 | protocol: UDP 15 | 16 | 17 | --- 18 | apiVersion: v1 19 | kind: Service 20 | metadata: 21 | name: netmaker-31822 22 | namespace: netmaker 23 | spec: 24 | type: NodePort 25 | selector: 26 | app: netmaker 27 | ports: 28 | - port: 31822 29 | targetPort: 31822 30 | nodePort: 31822 31 | protocol: UDP 32 | 33 | 34 | --- 35 | apiVersion: v1 36 | kind: Service 37 | metadata: 38 | name: netmaker-31823 39 | namespace: netmaker 40 | spec: 41 | type: NodePort 42 | selector: 43 | app: netmaker 44 | ports: 45 | - port: 31823 46 | targetPort: 31823 47 | nodePort: 31823 48 | protocol: UDP 49 | 50 | 51 | --- 52 | apiVersion: v1 53 | kind: Service 54 | metadata: 55 | name: netmaker-31824 56 | namespace: netmaker 57 | spec: 58 | type: NodePort 59 | selector: 60 | app: netmaker 61 | ports: 62 | - port: 31824 63 | targetPort: 31824 64 | nodePort: 31824 65 | protocol: UDP 66 | 67 | 68 | --- 69 | apiVersion: v1 70 | kind: Service 71 | metadata: 72 | name: netmaker-31825 73 | namespace: netmaker 74 | spec: 75 | type: NodePort 76 | selector: 77 | app: netmaker 78 | ports: 79 | - port: 31825 80 | targetPort: 31825 81 | nodePort: 31825 82 | protocol: UDP 83 | 84 | 85 | --- 86 | apiVersion: v1 87 | kind: Service 88 | metadata: 89 | name: netmaker-31826 90 | namespace: netmaker 91 | spec: 92 | type: NodePort 93 | selector: 94 | app: netmaker 95 | ports: 96 | - port: 31826 97 | targetPort: 31826 98 | nodePort: 31826 99 | protocol: UDP 100 | -------------------------------------------------------------------------------- /04-mqtt-configmap.yaml: -------------------------------------------------------------------------------- 1 | #https://github.com/gravitl/netmaker/blob/master/docker/mosquitto.conf 2 | apiVersion: v1 3 | kind: ConfigMap 4 | metadata: 5 | name: netmaker-mq-configmap 6 | namespace: netmaker 7 | data: 8 | mosquitto.conf: | 9 | per_listener_settings true 10 | 11 | listener 8883 12 | allow_anonymous false 13 | require_certificate true 14 | use_identity_as_username true 15 | cafile /mosquitto/certs/root.pem 16 | certfile /mosquitto/certs/server.pem 17 | keyfile /mosquitto/certs/server.key 18 | 19 | listener 1883 20 | allow_anonymous true 21 | -------------------------------------------------------------------------------- /05-netmaker-backend.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: apps/v1 3 | kind: Deployment 4 | metadata: 5 | name: netmaker-backend 6 | namespace: netmaker 7 | labels: 8 | app: netmaker-backend 9 | spec: 10 | selector: 11 | matchLabels: 12 | app: netmaker-backend 13 | replicas: 1 14 | strategy: 15 | type: Recreate 16 | template: 17 | metadata: 18 | labels: 19 | app: netmaker-backend 20 | networking/allow-internet-access: "true" 21 | spec: 22 | containers: 23 | 24 | - name: netmaker-backend 25 | image: gravitl/netmaker:v0.15.1 26 | imagePullPolicy: Always 27 | ports: 28 | - containerPort: 8081 29 | securityContext: 30 | privileged: true 31 | capabilities: 32 | add: 33 | - NET_ADMIN 34 | env: 35 | - name: SERVER_NAME 36 | value: "broker.BASE_DOMAIN" 37 | - name: DISPLAY_KEYS 38 | value: "on" 39 | - name: MANAGE_IPTABLES 40 | value: "off" 41 | - name: RCE 42 | value: "on" 43 | - name: NODE_ID 44 | value: "netmaker-server-1" 45 | - name: DATABASE 46 | value: "sqlite" 47 | - name: MQ_HOST 48 | value: netmaker-mq 49 | - name: MQ_PORT 50 | value: "443" 51 | 52 | - name: SERVER_API_CONN_STRING 53 | value: "api.BASE_DOMAIN:443" 54 | - name: COREDNS_ADDR 55 | value: "127.0.0.1" 56 | - name: POD_IP 57 | valueFrom: 58 | fieldRef: 59 | fieldPath: status.podIP 60 | - name: SERVER_HTTP_HOST 61 | value: "api.BASE_DOMAIN" 62 | - name: API_PORT 63 | value: "8081" 64 | - name: CLIENT_MODE 65 | value: "on" 66 | - name: MASTER_KEY 67 | value: "Unkn0wn!" 68 | - name: PLATFORM 69 | value: "Kubernetes" 70 | - name: CORS_ALLOWED_ORIGIN 71 | value: "*" 72 | volumeMounts: 73 | - name: nm-pvc-dnsconfig-backend 74 | mountPath: /root/config/dnsconfig 75 | - name: nm-pvc-sqldata 76 | mountPath: /root/data 77 | - name: nm-pvc-mq-certs-nm 78 | mountPath: /etc/netmaker 79 | 80 | 81 | - name: netmaker-dns 82 | imagePullPolicy: Always 83 | image: coredns/coredns 84 | args: 85 | - -conf 86 | - /root/dnsconfig/Corefile 87 | ports: 88 | - containerPort: 53 89 | name: dns 90 | protocol: UDP 91 | - containerPort: 53 92 | name: dns-tcp 93 | protocol: TCP 94 | volumeMounts: 95 | - mountPath: /root/dnsconfig 96 | name: nm-pvc-dnsconfig-coredns 97 | readOnly: true 98 | securityContext: 99 | allowPrivilegeEscalation: false 100 | capabilities: 101 | add: 102 | - NET_BIND_SERVICE 103 | drop: 104 | - all 105 | 106 | volumes: 107 | - name: nm-pvc-dnsconfig-backend 108 | persistentVolumeClaim: 109 | claimName: nm-pvc-dnsconfig-backend 110 | - name: nm-pvc-sqldata 111 | persistentVolumeClaim: 112 | claimName: nm-pvc-sqldata 113 | - name: nm-pvc-mq-certs-nm 114 | persistentVolumeClaim: 115 | claimName: nm-pvc-mq-certs-nm 116 | - name: nm-pvc-dnsconfig-coredns 117 | persistentVolumeClaim: 118 | claimName: nm-pvc-dnsconfig-coredns 119 | 120 | --- 121 | apiVersion: v1 122 | kind: Service 123 | metadata: 124 | namespace: netmaker 125 | labels: 126 | app: netmaker-backend 127 | name: netmaker-api 128 | spec: 129 | ports: 130 | - port: 8081 131 | protocol: TCP 132 | targetPort: 8081 133 | selector: 134 | app: netmaker-backend 135 | sessionAffinity: None 136 | type: ClusterIP 137 | -------------------------------------------------------------------------------- /06-netmaker-mq.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: apps/v1 3 | kind: Deployment 4 | metadata: 5 | name: netmaker-mq 6 | namespace: netmaker 7 | labels: 8 | app: netmaker-mq 9 | spec: 10 | selector: 11 | matchLabels: 12 | app: netmaker-mq 13 | replicas: 1 14 | strategy: 15 | type: Recreate 16 | template: 17 | metadata: 18 | labels: 19 | app: netmaker-mq 20 | spec: 21 | containers: 22 | 23 | - name: netmaker-mq 24 | image: eclipse-mosquitto:2.0.11-openssl 25 | ports: 26 | - containerPort: 1883 27 | name: mqtt-local 28 | protocol: TCP 29 | - containerPort: 8883 30 | name: mqtt-broker 31 | protocol: TCP 32 | volumeMounts: 33 | - name: netmaker-mq-configmap 34 | mountPath: /mosquitto/config/mosquitto.conf 35 | subPath: mosquitto.conf 36 | readOnly: true 37 | - name: nm-pvc-mq-certs-mq 38 | mountPath: /mosquitto/certs 39 | readOnly: true 40 | - name: nm-pvc-mq-log 41 | mountPath: /mosquitto/log 42 | - name: nm-pvc-mq-data 43 | mountPath: /mosquitto/data 44 | 45 | volumes: 46 | - name: netmaker-mq-configmap 47 | configMap: 48 | name: netmaker-mq-configmap 49 | - name: nm-pvc-mq-certs-mq 50 | persistentVolumeClaim: 51 | claimName: nm-pvc-mq-certs-mq 52 | - name: nm-pvc-mq-log 53 | persistentVolumeClaim: 54 | claimName: nm-pvc-mq-log 55 | - name: nm-pvc-mq-data 56 | persistentVolumeClaim: 57 | claimName: nm-pvc-mq-data 58 | 59 | --- 60 | apiVersion: v1 61 | kind: Service 62 | metadata: 63 | namespace: netmaker 64 | labels: 65 | app: netmaker-mq 66 | name: netmaker-mq 67 | spec: 68 | ports: 69 | - port: 8883 70 | name: mqtt-broker 71 | protocol: TCP 72 | targetPort: 8883 73 | - port: 1883 74 | name: mqtt-local 75 | protocol: TCP 76 | targetPort: 1883 77 | selector: 78 | app: netmaker-mq 79 | sessionAffinity: None 80 | type: ClusterIP 81 | -------------------------------------------------------------------------------- /07-netmaker-ui,yaml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: apps/v1 3 | kind: Deployment 4 | metadata: 5 | name: netmaker-ui 6 | namespace: netmaker 7 | labels: 8 | app: netmaker-ui 9 | spec: 10 | selector: 11 | matchLabels: 12 | app: netmaker-ui 13 | replicas: 1 14 | strategy: 15 | type: Recreate 16 | template: 17 | metadata: 18 | labels: 19 | app: netmaker-ui 20 | spec: 21 | containers: 22 | 23 | - name: netmaker-ui 24 | image: gravitl/netmaker-ui:v0.15.1 25 | ports: 26 | - containerPort: 80 27 | env: 28 | - name: BACKEND_URL 29 | value: "https://api.BASE_DOMAIN" 30 | 31 | --- 32 | apiVersion: v1 33 | kind: Service 34 | metadata: 35 | namespace: netmaker 36 | labels: 37 | app: netmaker-ui 38 | name: netmaker-ui 39 | spec: 40 | ports: 41 | - port: 80 42 | protocol: TCP 43 | targetPort: 80 44 | selector: 45 | app: netmaker-ui 46 | sessionAffinity: None 47 | type: ClusterIP 48 | -------------------------------------------------------------------------------- /08-ingress.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: traefik.containo.us/v1alpha1 3 | kind: Middleware 4 | metadata: 5 | name: secheaders 6 | namespace: netmaker 7 | spec: 8 | headers: 9 | #HSTS 10 | stsIncludeSubdomains: true 11 | stsPreload: true 12 | stsSeconds: 31536000 13 | forceSTSHeader: true 14 | sslRedirect: true 15 | referrerPolicy: "same-origin" 16 | frameDeny: true 17 | contentTypeNosniff: true 18 | browserXssFilter: true 19 | accessControlAllowMethods: ["GET", "OPTIONS", "PUT"] 20 | accessControlMaxAge: 100 21 | customFrameOptionsValue: SAMEORIGIN 22 | contentSecurityPolicy: frame-ancestors 'self' 23 | permissionsPolicy: geolocation=(), microphone=() 24 | referrerPolicy: no-referrer 25 | 26 | 27 | --- 28 | apiVersion: traefik.containo.us/v1alpha1 29 | kind: IngressRoute 30 | metadata: 31 | name: nm-api-ingress-nginx-tls 32 | namespace: netmaker 33 | spec: 34 | entryPoints: 35 | - websecure 36 | routes: 37 | - match: Host(`api.BASE_DOMAIN`) 38 | kind: Rule 39 | services: 40 | - name: netmaker-api 41 | port: 8081 42 | tls: 43 | certResolver: 44 | 45 | 46 | 47 | --- 48 | apiVersion: traefik.containo.us/v1alpha1 49 | kind: IngressRoute 50 | metadata: 51 | name: nm-ui-ingress-nginx-tls 52 | namespace: netmaker 53 | spec: 54 | entryPoints: 55 | - websecure 56 | routes: 57 | - match: Host(`dashboard.BASE_DOMAIN`) 58 | kind: Rule 59 | services: 60 | - name: netmaker-ui 61 | port: 80 62 | middlewares: 63 | - name: secheaders 64 | tls: 65 | certResolver: 66 | 67 | 68 | 69 | --- 70 | apiVersion: traefik.containo.us/v1alpha1 71 | kind: IngressRouteTCP 72 | metadata: 73 | namespace: netmaker 74 | name: nm-mq-ingress-nginx-tls 75 | spec: 76 | entryPoints: 77 | - websecure 78 | routes: 79 | - match: HostSNI(`broker.BASE_DOMAIN`) 80 | services: 81 | - name: netmaker-mq 82 | port: 8883 83 | tls: 84 | passthrough: true 85 | 86 | 87 | -------------------------------------------------------------------------------- /90-network-deny.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: networking.k8s.io/v1 3 | kind: NetworkPolicy 4 | metadata: 5 | name: default-deny-all-except-kube-dns 6 | namespace: netmaker 7 | spec: 8 | policyTypes: 9 | - Ingress 10 | - Egress 11 | podSelector: {} 12 | egress: 13 | - to: 14 | - namespaceSelector: 15 | matchLabels: 16 | kubernetes.io/metadata.name: kube-system 17 | podSelector: 18 | matchLabels: 19 | k8s-app: kube-dns 20 | ports: 21 | - protocol: TCP 22 | port: 53 23 | - protocol: UDP 24 | port: 53 25 | -------------------------------------------------------------------------------- /91-allow-internet.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: networking.k8s.io/v1 2 | kind: NetworkPolicy 3 | metadata: 4 | name: allow-internet-egress 5 | namespace: netmaker 6 | spec: 7 | podSelector: 8 | matchLabels: 9 | networking/allow-internet-access: "true" 10 | egress: 11 | - to: 12 | - ipBlock: 13 | cidr: 0.0.0.0/0 14 | except: 15 | - 10.0.0.0/8 16 | - 192.168.0.0/16 17 | - 172.16.0.0/20 18 | ingress: [] 19 | policyTypes: 20 | - Egress 21 | - Ingress 22 | -------------------------------------------------------------------------------- /94-netmaker.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: networking.k8s.io/v1 3 | kind: NetworkPolicy 4 | metadata: 5 | name: netmaker-backend 6 | namespace: netmaker 7 | spec: 8 | podSelector: 9 | matchLabels: 10 | app: netmaker-backend 11 | policyTypes: 12 | - Ingress 13 | - Egress 14 | ingress: 15 | - from: 16 | - namespaceSelector: 17 | matchLabels: 18 | kubernetes.io/metadata.name: kube-system 19 | podSelector: 20 | matchLabels: 21 | app.kubernetes.io/name: traefik 22 | ports: 23 | - port: 8081 24 | 25 | - from: 26 | - ipBlock: 27 | cidr: 0.0.0.0/0 28 | ports: 29 | - protocol: UDP 30 | port: 31821 31 | endPort: 31829 32 | 33 | egress: 34 | - to: 35 | - ipBlock: 36 | cidr: 0.0.0.0/0 37 | ports: 38 | - protocol: UDP 39 | port: 31821 40 | endPort: 31829 41 | - to: 42 | - namespaceSelector: 43 | matchLabels: 44 | networking/namespace: netmaker 45 | podSelector: 46 | matchLabels: 47 | app: netmaker-mq 48 | ports: 49 | - port: 1883 50 | 51 | --- 52 | apiVersion: networking.k8s.io/v1 53 | kind: NetworkPolicy 54 | metadata: 55 | name: netmaker-mq 56 | namespace: netmaker 57 | spec: 58 | podSelector: 59 | matchLabels: 60 | app: netmaker-mq 61 | policyTypes: 62 | - Ingress 63 | - Egress 64 | ingress: 65 | - from: 66 | - namespaceSelector: 67 | matchLabels: 68 | kubernetes.io/metadata.name: kube-system 69 | podSelector: 70 | matchLabels: 71 | app.kubernetes.io/name: traefik 72 | ports: 73 | - port: 8883 74 | - from: 75 | - namespaceSelector: 76 | matchLabels: 77 | networking/namespace: netmaker 78 | podSelector: 79 | matchLabels: 80 | app: netmaker-backend 81 | ports: 82 | - port: 1883 83 | 84 | --- 85 | apiVersion: networking.k8s.io/v1 86 | kind: NetworkPolicy 87 | metadata: 88 | name: netmaker-ui 89 | namespace: netmaker 90 | spec: 91 | podSelector: 92 | matchLabels: 93 | app: netmaker-ui 94 | policyTypes: 95 | - Ingress 96 | - Egress 97 | ingress: 98 | - from: 99 | - namespaceSelector: 100 | matchLabels: 101 | kubernetes.io/metadata.name: kube-system 102 | podSelector: 103 | matchLabels: 104 | app.kubernetes.io/name: traefik 105 | ports: 106 | - port: 80 107 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # netmaker-k3s 2 | Run netmaker on a k3s server with defaults. 3 | 4 | ## Update 5 | Netmaker decided in version 0.14.2 to change the broker(mqtt) communication from port 8883 to 443. This is a fantastic move 6 | since now all communication flows over port 443. The dashboard, api and broker. You notice in the ingress manifest that this 7 | is implemented using a tcp ingress route. Well done, I would say!!! 8 | 9 | ![img-description](traefik-http.jpg) 10 | ![img-description](traefik-tcp.jpg) 11 | 12 | 13 | 14 | Wouldn't it be nice this could be deployed more easily to kubernetes? 15 | The project offers a helm chart that adds high availability if you are in need of such a thing. I was not. I just wanted to test it in a vm/pi/etc. 16 | To adapt this to run in a cluster, simply modify the pvc configs to use nfs, longhorn, rook, etc. 17 | 18 | This project contains a deployment that puts the netmaker backend, ui, mqtt and coredns into a few simple pods. The pods are then isolated using network policies. 19 | The communication between the services within the same pod is facilitated via the loopback interface. 20 | The database is a sqlite file for simplicity. All the persistant volumes are mapped to a local folder for easy access just like a docker volume mount. 21 | 22 | I am using traefik with let'sencrypt here but this can be swapped out to your choice of ingress. 23 | 24 | ### 01-namespace.yaml 25 | will create a namespace. If you change the name here you have to change it everywhere. 26 | 27 | ### 02-pvc.yaml 28 | Before applying this you need to create a few folders. Like this for example: 29 | 30 | ``` 31 | mkdir -p /srv/netmaker/nm-dnsconfig-pvc 32 | mkdir -p /srv/netmaker/nm-sqldata-pvc 33 | mkdir -p /srv/netmaker/nm-mq-certs 34 | mkdir -p /srv/netmaker/nm-mq-log 35 | mkdir -p /srv/netmaker/nm-mq-data 36 | chmod 777 /srv/netmaker/* 37 | ``` 38 | 39 | But you can see that there are seven pv's. Well k3s local-path provider does not support readWriteMany. Since the dns pvc is mounted to netmaker and coredns at the same time, the workaround is to simply make two pvc's to the same path on disk. 40 | 41 | Also replace HOSTNAME with the name of the vm/host you are running on. 42 | 43 | ### 03-nodeports.yaml 44 | These are nodeports for wireguard connections to the container. Every network needs it's own port. This file creates six nodeports. That means you can create six networks before you have to go in here and just add more (copy/paste). 45 | 46 | ### 04-mqtt-configmap.yaml 47 | This just needs to be there. It's from the official docker netmaker config. 48 | 49 | ### 05-netmaker-backend.yaml 50 | You need to replace BASE_DOMAIN with your domain in all the spots. 51 | 52 | ### 06-netmaker-mq.yaml 53 | You need to replace BASE_DOMAIN with your domain in all the spots. 54 | 55 | ### 07-netmaker-ui.yaml 56 | You need to replace BASE_DOMAIN with your domain in all the spots. 57 | 58 | ### 08-ingress.yaml (Using k3s traefik) 59 | You need three domains with let'sencrypt. The dashboard, api and the broker. Note here the special broker config. It's not http. 60 | Replace BASE_DOMAIN with your domain name. Replace cert-provider with your provider. 61 | 62 | -- It's functional now. The following manifests implement network policy to improve security posture --- 63 | 64 | ### 90-network-deny.yaml 65 | Optional step 1: It puts a default deny into the network namespace and only allows dns. 66 | 67 | ### 91-allow-internet.yaml 68 | Optional step 2: Allows for internet acces but not LAN access 69 | 70 | ### 94-netmaker.yaml 71 | Optional step 3: This policy allows the pods to communicate between each other and traefik. 72 | 73 | ### Tip 74 | Once it is running, Coredns created the corefile in the path you specified in 02-pvc. Go there and edit the default forwarder if you like. 75 | It creates it with 8.8.8.8 but I like to send it to a pi-hole instead. Your choice. 76 | 77 | ### In Conclusion 78 | Netmaker works really well now. There is an apt repo to help with the netclient installation and updating. https://docs.netmaker.org/netclient.html#installation 79 | Don't forget to join the official discord. 80 | -------------------------------------------------------------------------------- /traefik-http.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/geragcp/netmaker-k3s/0cc8fb1828d5da6d53f65db204041c49eb8798cb/traefik-http.jpg -------------------------------------------------------------------------------- /traefik-tcp.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/geragcp/netmaker-k3s/0cc8fb1828d5da6d53f65db204041c49eb8798cb/traefik-tcp.jpg --------------------------------------------------------------------------------