Blame

6c6328 Ralph Thesen 2023-09-07 21:29:24
initial commit
1
# Howto: NGINX-public_html
2
3
1. create a `~/public_html/domain.tld` on `gate0.t3m4.net`
4
2. `sudo` or ping <mail@redimp.de> to add the folder to `/etc/exports` and run `exportfs -a`
5
3. create a `domain-tld.yaml` definition for a deployment, a service and an ingress and `kubectl apply -f domain-tld.yaml` it.
6
7
<mark>Please consider all files in the exported folders as public, since any k8s pod can mount it via nfs. name the directories accordingly, e.g. `public_html` or `share`.</mark>
8
9
## k8s deployment, service and ingress
10
11
An example for an nginx deployment can be found below. Make sure to replace all the
12
13
- domain-tld
14
- domain.tld
15
- username
16
17
entries.
18
19
```yaml
20
---
21
apiVersion: apps/v1
22
kind: Deployment
23
metadata:
24
name: nginx-domain-tld
25
namespace: username-vserver
26
spec:
27
selector:
28
matchLabels:
29
app: nginx-domain-tld
30
replicas: 1
31
template:
32
metadata:
33
labels:
34
app: nginx-domain-tld
35
spec:
36
containers:
37
- name: nginx
38
image: nginx:1.14.2
39
command:
40
- /bin/sh
41
- -c
42
- |
43
sed -i '/^nginx/d' /etc/passwd
44
sed -i '/^nginx/d' /etc/group
45
echo "nginx:x:101:101:nginx user,,,:/nonexistent:/bin/false" >> /etc/passwd
46
echo "nginx:x:101:" >> /etc/group
47
nginx -g 'daemon off;'
48
ports:
49
- containerPort: 80
50
volumeMounts:
51
- name: nfs-public-html
52
mountPath: /usr/share/nginx/html
53
volumes:
54
- name: nfs-public-html
55
nfs:
56
server: 10.1.0.2
57
path: /home/username/public_html/domain.tld
58
---
59
apiVersion: v1
60
kind: Service
61
metadata:
62
name: nginx-domain-tld
63
namespace: vserver
64
spec:
65
ports:
66
- port: 80
67
targetPort: 80
68
protocol: TCP
69
selector:
70
app: nginx-domain-tld
71
---
72
apiVersion: networking.k8s.io/v1
73
kind: Ingress
74
metadata:
75
name: nginx-domain-tld
76
namespace: vserver
77
annotations:
78
cert-manager.io/cluster-issuer: "letsencrypt-production"
79
nginx.ingress.kubernetes.io/ssl-redirect: "true"
80
nginx.ingress.kubernetes.io/server-alias: "www.domain.tld"
81
spec:
82
ingressClassName: "nginx"
83
tls:
84
- hosts:
85
- domain.tld
86
- www.domain.tld
87
secretName: domain-tld-tls
88
rules:
89
- host: domain.tld
90
http:
91
paths:
92
- path: /
93
pathType: Prefix
94
backend:
95
service:
96
name: nginx-domain-tld
97
port:
98
number: 80
99
100
```