Browse Source

initial commit

pull/1/head
fillkalpa 6 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 @@

# After-Dark on k3s (lightweight Kubernetes by Rancher)

>## **<https://k3s.io/>**

## Install K3s on your host

``$ curl -sfL https://get.k3s.io | sh -``
Check for Ready node, takes maybe 30 seconds
``$ kubectl get node``

## Deploy After-Dark

Download deployment files on your host:
``$ git clone https://git.habd.as/teowood/after-dark-k3s-amd64.git``
Apply deployment files:
``$ cd after-dark-k3s-amd64`` then ``$ kubectl apply -f .``

## Basic explanation of deployment

This is a multi tier deployment:

* ``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.
* ``after-dark-nginx.yaml`` deploys an nginx server that servers our rendered site.
* ``after-dark-service.yaml`` exposes our nginx to a nodeport so we can actually reach the site.

## Operate your k3s after-dark site

* 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}')``
* Create a new post
``$ 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
* Apply custom styling
``$ kubectl cp custom.css $AD_POD:/after-dark/flying-toasters/assets/css/custom.css``
* Build your draft posts
``$ kubectl exec $AD_POD -- hugo -D -c /posts -d /output``
* 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.
* Edit your posts ``$ kubectl exec -it $AD_POD -- vi /posts/my-post.md`` or directly inside your host's ``/posts``

## Browse to your site

Locate the nodeport we exposed our nginx for after-dark
``$ kubectl get svc``
The port we are looking for is the the one next to ``8080:``
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.

| Name | Type | Cluster-IP | External-IP | Port(s) | Age |
|--------------------|----------|---------------|-------------|----------------|-----|
| 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 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: after-dark-hugo-64
labels:
tier: backend
spec:
replicas: 1
selector:
matchLabels:
app: after-dark-hugo
tier: backend
template:
metadata:
labels:
app: after-dark-hugo
tier: backend
spec:
containers:
- image: tkalpakid/after-dark-themed-hugo-64-v2
name: after-dark-hugo-container
ports:
- containerPort: 1313
env:
- name: HUGO_WATCH # changed to real time build
value: "true"
volumeMounts:
- name: site-content
mountPath: /posts
- name: rendered-site
mountPath: /output
- name: repo
mountPath: /after-dark
initContainers:
- name: init-repo
image: alpine/git
command:
- git
- "clone"
- "https://git.habd.as/teowood/after-dark.git"
- "/after-dark/."
volumeMounts:
- name: repo
mountPath: /after-dark
volumes:
- name: repo
emptyDir: {}
- name: site-content
hostPath:
path: /posts
type: DirectoryOrCreate
- name: rendered-site
hostPath:
path: /rendered-site
type: DirectoryOrCreate

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

@@ -0,0 +1,36 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: after-dark-nginx
labels:
tier: frontend
spec:
replicas: 1
selector:
matchLabels:
app: after-dark-nginx
tier: frontend
template:
metadata:
labels:
app: after-dark-nginx
tier: frontend
spec:
containers:
- image: jojomi/nginx-static
ports:
- containerPort: 80
name: after-dark-nginx-container
env:
- name: VIRTUAL_HOST
value: "localhost"
volumeMounts:
- mountPath: /var/www
name: output
volumes:
- name: output
hostPath:
# directory location on host
path: /rendered-site
# this field is optional
type: Directory

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

@@ -0,0 +1,16 @@
apiVersion: v1
kind: Service
metadata:
name: after-dark-service
labels:
app: after-dark-service
tier: frontend
spec:
type: NodePort
ports:
- port: 8080
targetPort: 80
protocol: TCP
selector:
app: after-dark-nginx
tier: frontend

Loading…
Cancel
Save