Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions argoproj/n8n/application.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: n8n
namespace: argocd
spec:
project: default
source:
repoURL: https://github.com/boxp/lolice.git
targetRevision: main
path: argoproj/n8n
destination:
server: https://kubernetes.default.svc
namespace: n8n
syncPolicy:
automated:
prune: true
selfHeal: true
syncOptions:
- CreateNamespace=true
- ServerSideApply=true
56 changes: 56 additions & 0 deletions argoproj/n8n/deployment-cloudflared.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: cloudflared
namespace: n8n
labels:
app: cloudflared
spec:
replicas: 1
strategy:
type: Recreate
selector:
matchLabels:
app: cloudflared
template:
metadata:
labels:
app: cloudflared
spec:
automountServiceAccountToken: false
containers:
- name: cloudflared
image: docker.io/cloudflare/cloudflared:latest
args:
- tunnel
- --metrics
- 0.0.0.0:2000
- run
- --protocol
- http2
- --token
- $(TUNNEL_TOKEN)
env:
- name: TUNNEL_TOKEN
valueFrom:
secretKeyRef:
name: tunnel-credentials
key: tunnel-token
ports:
- containerPort: 2000
name: metrics
protocol: TCP
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 200m
memory: 256Mi
livenessProbe:
httpGet:
path: /ready
port: 2000
failureThreshold: 1
initialDelaySeconds: 10
periodSeconds: 10
86 changes: 86 additions & 0 deletions argoproj/n8n/deployment-n8n.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: n8n
namespace: n8n
labels:
app: n8n
spec:
replicas: 1
strategy:
type: Recreate
selector:
matchLabels:
app: n8n
template:
metadata:
labels:
app: n8n
spec:
automountServiceAccountToken: false
securityContext:
fsGroup: 1000
runAsUser: 1000
runAsGroup: 1000
runAsNonRoot: true
containers:
- name: n8n
image: docker.io/n8nio/n8n:latest
ports:
- containerPort: 5678
protocol: TCP
env:
- name: DB_TYPE
value: postgresdb
- name: DB_POSTGRESDB_HOST
value: postgres.n8n.svc.cluster.local
- name: DB_POSTGRESDB_PORT
value: "5432"
- name: DB_POSTGRESDB_DATABASE
value: n8n
- name: DB_POSTGRESDB_USER
value: n8n
- name: DB_POSTGRESDB_PASSWORD
valueFrom:
secretKeyRef:
name: postgres-credentials
key: POSTGRES_PASSWORD
- name: N8N_ENCRYPTION_KEY
valueFrom:
secretKeyRef:
name: n8n-credentials
key: ENCRYPTION_KEY
- name: N8N_PORT
value: "5678"
- name: N8N_PROTOCOL
value: https
- name: GENERIC_TIMEZONE
value: Asia/Tokyo
- name: TZ
value: Asia/Tokyo
volumeMounts:
- name: n8n-data
mountPath: /home/node/.n8n
resources:
requests:
cpu: 200m
memory: 256Mi
limits:
cpu: 1000m
memory: 1Gi
livenessProbe:
httpGet:
path: /healthz
port: 5678
initialDelaySeconds: 30
periodSeconds: 10
readinessProbe:
httpGet:
path: /healthz
port: 5678
initialDelaySeconds: 5
periodSeconds: 5
volumes:
- name: n8n-data
persistentVolumeClaim:
claimName: n8n-data
21 changes: 21 additions & 0 deletions argoproj/n8n/external-secret-n8n.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: external-secrets.io/v1
kind: ExternalSecret
metadata:
name: n8n-credentials
namespace: n8n
spec:
refreshInterval: 1h
secretStoreRef:
name: parameterstore
kind: ClusterSecretStore
target:
name: n8n-credentials
creationPolicy: Owner
deletionPolicy: Retain
data:
- secretKey: ENCRYPTION_KEY
remoteRef:
key: /lolice/n8n/ENCRYPTION_KEY
conversionStrategy: Default
decodingStrategy: None
metadataPolicy: None
21 changes: 21 additions & 0 deletions argoproj/n8n/external-secret-postgres.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: external-secrets.io/v1
kind: ExternalSecret
metadata:
name: postgres-credentials
namespace: n8n
spec:
refreshInterval: 1h
secretStoreRef:
name: parameterstore
kind: ClusterSecretStore
target:
name: postgres-credentials
creationPolicy: Owner
deletionPolicy: Retain
data:
- secretKey: POSTGRES_PASSWORD
remoteRef:
key: /lolice/n8n/DB_POSTGRESDB_PASSWORD
conversionStrategy: Default
decodingStrategy: None
metadataPolicy: None
20 changes: 20 additions & 0 deletions argoproj/n8n/external-secret-tunnel.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: external-secrets.io/v1
kind: ExternalSecret
metadata:
name: tunnel-credentials
namespace: n8n
spec:
refreshInterval: 1h
secretStoreRef:
name: parameterstore
kind: ClusterSecretStore
target:
name: tunnel-credentials
creationPolicy: Owner
data:
- secretKey: tunnel-token
remoteRef:
key: /lolice/n8n/TUNNEL_TOKEN
conversionStrategy: Default
decodingStrategy: None
metadataPolicy: None
17 changes: 17 additions & 0 deletions argoproj/n8n/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

namespace: n8n

resources:
- namespace.yaml
- external-secret-n8n.yaml
- external-secret-postgres.yaml
- external-secret-tunnel.yaml
- statefulset-postgres.yaml
- deployment-n8n.yaml
- deployment-cloudflared.yaml
- service-n8n.yaml
- service-postgres.yaml
- pvc-n8n.yaml
- networkpolicy.yaml
4 changes: 4 additions & 0 deletions argoproj/n8n/namespace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: n8n
132 changes: 132 additions & 0 deletions argoproj/n8n/networkpolicy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
---
# n8n Pod: cloudflaredからの受信のみ許可、PostgreSQLと外部HTTPSへの送信を許可
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: n8n-network-policy
namespace: n8n
spec:
podSelector:
matchLabels:
app: n8n
policyTypes:
- Ingress
- Egress
ingress:
- from:
- podSelector:
matchLabels:
app: cloudflared
ports:
- protocol: TCP
port: 5678
egress:
# PostgreSQLへの接続
- to:
- podSelector:
matchLabels:
app: postgres
ports:
- protocol: TCP
port: 5432
# DNS解決 (kube-system)
- to:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: kube-system
ports:
- protocol: UDP
port: 53
- protocol: TCP
port: 53
# 外部HTTPS (Webhook送信、外部API連携用)
- to:
- ipBlock:
cidr: 0.0.0.0/0
except:
- 10.0.0.0/8
- 172.16.0.0/12
- 192.168.0.0/16
ports:
- protocol: TCP
port: 443
---
# PostgreSQL Pod: n8nからの受信のみ許可、送信は不要
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: postgres-network-policy
namespace: n8n
spec:
podSelector:
matchLabels:
app: postgres
policyTypes:
- Ingress
- Egress
ingress:
- from:
- podSelector:
matchLabels:
app: n8n
ports:
- protocol: TCP
port: 5432
egress:
# DNS解決のみ
- to:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: kube-system
ports:
- protocol: UDP
port: 53
- protocol: TCP
port: 53
---
# cloudflared Pod: Cloudflare Edgeへの送信とn8nへの送信を許可
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: cloudflared-network-policy
namespace: n8n
spec:
podSelector:
matchLabels:
app: cloudflared
policyTypes:
- Ingress
- Egress
ingress: []
egress:
# n8nへの接続
- to:
- podSelector:
matchLabels:
app: n8n
ports:
- protocol: TCP
port: 5678
# DNS解決 (kube-system)
- to:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: kube-system
ports:
- protocol: UDP
port: 53
- protocol: TCP
port: 53
# Cloudflare Edge (HTTPS)
- to:
- ipBlock:
cidr: 0.0.0.0/0
except:
- 10.0.0.0/8
- 172.16.0.0/12
- 192.168.0.0/16
ports:
- protocol: TCP
port: 443
- protocol: UDP
port: 7844
12 changes: 12 additions & 0 deletions argoproj/n8n/pvc-n8n.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: n8n-data
namespace: n8n
spec:
accessModes:
- ReadWriteOnce
storageClassName: longhorn
resources:
requests:
storage: 5Gi
Loading