Browse Source

initial commit

fillkalpa 7 months ago
commit
b75432792a
4 changed files with 155 additions and 0 deletions
  1. 48
    0
      README.md
  2. 55
    0
      after-dark-k3s-hugo.yaml
  3. 36
    0
      after-dark-nginx.yaml
  4. 16
    0
      after-dark-service.yaml

+ 48
- 0
README.md View File

@@ -0,0 +1,48 @@
1
+
2
+# After-Dark on k3s (lightweight Kubernetes by Rancher) 
3
+
4
+>## **<https://k3s.io/>**
5
+
6
+## Install K3s on your host  
7
+
8
+``$ curl -sfL https://get.k3s.io | sh -``
9
+Check for Ready node, takes maybe 30 seconds
10
+``$ kubectl get node``  
11
+
12
+## Deploy After-Dark  
13
+
14
+Download deployment files on your host:  
15
+``$ git clone https://git.habd.as/teowood/after-dark-k3s-amd64.git``  
16
+Apply deployment files:  
17
+``$ cd after-dark-k3s-amd64`` then ``$ kubectl apply -f .``  
18
+
19
+## Basic explanation of deployment
20
+
21
+This is a multi tier deployment:  
22
+
23
+* ``after-dark-k3s-hugo.yaml`` deploys a pod with two containers. First an  init container which downloads the after-dark repository and finally the actual hugo container which kicks in and installs the site. When done it fires hugo in watch mode.  
24
+* ``after-dark-nginx.yaml`` deploys an nginx server that servers our rendered site.
25
+* ``after-dark-service.yaml`` exposes our nginx to a nodeport so we can actually reach the site.
26
+
27
+## Operate your k3s after-dark site  
28
+
29
+* First retrieve your pod name and store it in a variable for your convinience ``$ AD_POD=$(kubectl get pods -l app=after-dark-hugo -o jsonpath='{.items[0].metadata.name}')``  
30
+* Create a new post  
31
+``$ kubectl exec $AD_POD -- hugo new -k post /posts/new-post.md``  or you can go ahead and copy your stuff under ``/posts`` on your host  
32
+* Apply custom styling  
33
+``$ kubectl cp custom.css $AD_POD:/after-dark/flying-toasters/assets/css/custom.css``  
34
+* Build your draft posts  
35
+``$ kubectl exec  $AD_POD -- hugo  -D -c /posts -d /output``
36
+* Full rebuilt your site e.g after new styles appied ``$ kubectl exec  $AD_POD -- hugo -c /posts -d /output`` Note this will also revert drafts.  
37
+* Edit your posts ``$ kubectl exec -it $AD_POD -- vi /posts/my-post.md`` or directly inside your host's ``/posts``
38
+
39
+## Browse to your site  
40
+
41
+Locate the nodeport we exposed our nginx for after-dark  
42
+``$ kubectl get svc``
43
+The port we are looking for is the the one next to ``8080:``
44
+For instance in the example below, you would point your browser to <http://your-node-IP:32146>. Ignore the Cluster-IP shown, you want the real IP of your host.
45
+
46
+| Name | Type | Cluster-IP | External-IP | Port(s) | Age |
47
+|--------------------|----------|---------------|-------------|----------------|-----|
48
+| after-dark-service | NodePort | 10.43.129.249 | <none> | 8080:32146/TCP | 1h |  

+ 55
- 0
after-dark-k3s-hugo.yaml View File

@@ -0,0 +1,55 @@
1
+apiVersion: apps/v1
2
+kind: Deployment
3
+metadata:
4
+  name: after-dark-hugo-64
5
+  labels:
6
+    tier: backend
7
+spec:
8
+  replicas: 1
9
+  selector:
10
+    matchLabels:
11
+      app: after-dark-hugo
12
+      tier: backend
13
+  template:
14
+    metadata:
15
+      labels:
16
+        app: after-dark-hugo
17
+        tier: backend
18
+    spec:
19
+      containers:
20
+      - image: tkalpakid/after-dark-themed-hugo-64-v2
21
+        name: after-dark-hugo-container
22
+        ports:
23
+        - containerPort: 1313
24
+        env:
25
+        - name: HUGO_WATCH # changed to real time build
26
+          value: "true"
27
+        volumeMounts:
28
+        - name: site-content
29
+          mountPath: /posts
30
+        - name: rendered-site
31
+          mountPath: /output
32
+        - name: repo
33
+          mountPath: /after-dark
34
+      initContainers:
35
+      - name: init-repo
36
+        image: alpine/git
37
+        command:
38
+        - git
39
+        - "clone"
40
+        - "https://git.habd.as/teowood/after-dark.git"
41
+        - "/after-dark/."
42
+        volumeMounts:
43
+        - name: repo
44
+          mountPath: /after-dark
45
+      volumes:
46
+      - name: repo
47
+        emptyDir: {}
48
+      - name: site-content
49
+        hostPath:
50
+          path: /posts
51
+          type: DirectoryOrCreate
52
+      - name: rendered-site
53
+        hostPath:
54
+          path: /rendered-site
55
+          type: DirectoryOrCreate

+ 36
- 0
after-dark-nginx.yaml View File

@@ -0,0 +1,36 @@
1
+apiVersion: apps/v1
2
+kind: Deployment
3
+metadata:
4
+  name: after-dark-nginx
5
+  labels:
6
+    tier: frontend
7
+spec:
8
+  replicas: 1
9
+  selector:
10
+    matchLabels:
11
+      app: after-dark-nginx
12
+      tier: frontend 
13
+  template:
14
+    metadata:
15
+      labels:
16
+        app: after-dark-nginx
17
+        tier: frontend
18
+    spec:
19
+      containers:
20
+      - image: jojomi/nginx-static
21
+        ports:
22
+        - containerPort: 80
23
+        name: after-dark-nginx-container
24
+        env:
25
+        - name: VIRTUAL_HOST
26
+          value: "localhost"
27
+        volumeMounts:
28
+        - mountPath: /var/www
29
+          name: output
30
+      volumes:
31
+      - name: output
32
+        hostPath:
33
+      # directory location on host
34
+          path: /rendered-site
35
+      # this field is optional
36
+          type: Directory

+ 16
- 0
after-dark-service.yaml View File

@@ -0,0 +1,16 @@
1
+apiVersion: v1
2
+kind: Service
3
+metadata:
4
+  name: after-dark-service
5
+  labels:
6
+    app: after-dark-service
7
+    tier: frontend
8
+spec:
9
+  type: NodePort
10
+  ports:
11
+  - port: 8080
12
+    targetPort: 80
13
+    protocol: TCP
14
+  selector:
15
+    app: after-dark-nginx
16
+    tier: frontend

Loading…
Cancel
Save