parent
98ce0e8c2e
commit
b724f520cd
@ -0,0 +1,22 @@
|
||||
# syntax = docker/dockerfile:latest
|
||||
FROM docker.io/node:18-alpine
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY --link package.json pnpm-lock.yaml* ./
|
||||
|
||||
RUN <<EOF
|
||||
set -xe
|
||||
apk add libc6-compat
|
||||
apk add --virtual .gyp python3 make g++
|
||||
npm install -g pnpm
|
||||
npm install -g next
|
||||
EOF
|
||||
|
||||
RUN --mount=type=cache,id=pnpm-store,target=/root/.local/share/pnpm/store pnpm fetch | grep -v "cross-device link not permitted\|Falling back to copying packages from store"
|
||||
|
||||
RUN --mount=type=cache,id=pnpm-store,target=/root/.local/share/pnpm/store pnpm install -r --offline
|
||||
|
||||
COPY . .
|
||||
|
||||
CMD ["npx", "next", "dev"]
|
@ -0,0 +1,2 @@
|
||||
#shellcheck disable=SC2148,SC2155
|
||||
export KUBECONFIG=$(readlink -f ./kubeconfig)
|
@ -0,0 +1,2 @@
|
||||
kubeconfig
|
||||
|
@ -0,0 +1,64 @@
|
||||
# Kubernetes Development
|
||||
|
||||
These configs and scripts attempt to simplify spinning up a kubernetes cluster
|
||||
for development and testing purposes. It leverages [k3d](https://k3d.io) to create
|
||||
a [k3s](https://k3s.io) cluster in Docker. Homepage can then be deployed either via
|
||||
the `k3d-deploy.sh` script, or [tilt](https://tilt.dev) can be used to spin up a
|
||||
local CI loop that will automatically update the deployment.
|
||||
|
||||
All the commands in the document should be run from the `k3d` directory.
|
||||
|
||||
## Requisite Tools
|
||||
|
||||
| Tool | Description |
|
||||
|-------------------------------------------------------------|----------------------------------------------------------|
|
||||
| [docker](https://docker.io) | Docker container runtime |
|
||||
| [kubectl](https://kubernetes.io/releases/download/#kubectl) | Kubernetes CLI |
|
||||
| [helm](https://helm.sh) | Kubernetes package manager |
|
||||
| [k3d](https://k3d.io) | Kubernetes on Docker - used to create the cluster |
|
||||
| [k9s](https://k9scli.io) | (Optional) Command line view for kubernetes cluster |
|
||||
| [tilt](https://tilt.dev) | (Optional) Local CI loop for kubernetes deployment |
|
||||
| [direnv](https://direnv.net/) | (Optional) Automatically loads `kubeconfig` via `.envrc` |
|
||||
|
||||
|
||||
## One-off Test Deployments
|
||||
|
||||
Create a cluster:
|
||||
|
||||
```sh
|
||||
./k3d-up.sh
|
||||
```
|
||||
|
||||
Build and deploy:
|
||||
|
||||
```sh
|
||||
./k3d-deploy.sh
|
||||
```
|
||||
|
||||
Open the Homepage deployment:
|
||||
|
||||
```sh
|
||||
xdg-open http://homepage.k3d.localhost:8080/
|
||||
```
|
||||
|
||||
## Continuous Deployment
|
||||
|
||||
Create a cluster:
|
||||
|
||||
```sh
|
||||
./k3d-up.sh
|
||||
```
|
||||
|
||||
Kick off tilt:
|
||||
|
||||
```sh
|
||||
tilt up
|
||||
```
|
||||
|
||||
Press space bar to open the tilt web UI, which is quite informative.
|
||||
|
||||
Open the Homepage deployment:
|
||||
|
||||
```sh
|
||||
xdg-open http://homepage.k3d.localhost:8080/
|
||||
```
|
@ -0,0 +1,24 @@
|
||||
docker_build('k3d-registry.localhost:55000/homepage:local', '..',
|
||||
dockerfile = "../Dockerfile-tilt",
|
||||
build_args={'node_env': 'development'},
|
||||
#entrypoint='pnpm run nodemon /app/server.js',
|
||||
live_update=[
|
||||
sync('.', '/app'),
|
||||
run('cd /app && pnpm install', trigger=['.package.json', './pnpm-lock.yaml'])
|
||||
]
|
||||
)
|
||||
load('ext://helm_resource', 'helm_resource', 'helm_repo')
|
||||
helm_repo('jameswynn', 'https://jameswynn.github.io/helm-charts')
|
||||
|
||||
helm_resource('homepage', 'jameswynn/homepage',
|
||||
image_deps=[
|
||||
"k3d-registry.localhost:55000/homepage:local"
|
||||
],
|
||||
image_keys=[
|
||||
("image.repository", "image.tag")
|
||||
],
|
||||
# image_selector= "k3d-registry.localhost:55000/homepage:local",
|
||||
flags=[
|
||||
"-f", "k3d-helm-values.yaml"
|
||||
]
|
||||
)
|
@ -0,0 +1,14 @@
|
||||
#!/bin/bash
|
||||
|
||||
DOCKER_BUILDKIT=1 docker build -t k3d-registry.localhost:55000/homepage:local .
|
||||
docker push k3d-registry.localhost:55000/homepage:local
|
||||
|
||||
HELM_REPO_NAME=jameswynn
|
||||
HELM_REPO_URL=https://jameswynn.github.io/helm-charts
|
||||
|
||||
if ! helm repo list | grep $HELM_REPO_URL > /dev/null; then
|
||||
helm repo add $HELM_REPO_NAME $HELM_REPO_URL
|
||||
helm repo update
|
||||
fi
|
||||
|
||||
helm upgrade --install homepage jameswynn/homepage -f k3d-helm-values.yaml
|
@ -0,0 +1,4 @@
|
||||
#!/bin/bash
|
||||
|
||||
k3d cluster delete homepage
|
||||
rm kubeconfig
|
@ -0,0 +1,77 @@
|
||||
image:
|
||||
repository: k3d-registry.localhost:55000/homepage
|
||||
tag: local
|
||||
pullPolicy: IfNotPresent
|
||||
|
||||
config:
|
||||
bookmarks:
|
||||
- Developer:
|
||||
- Github:
|
||||
- abbr: GH
|
||||
href: https://github.com/
|
||||
services:
|
||||
- My First Group:
|
||||
- My First Service:
|
||||
href: http://localhost/
|
||||
description: Homepage is awesome
|
||||
|
||||
- My Second Group:
|
||||
- My Second Service:
|
||||
href: http://localhost/
|
||||
description: Homepage is the best
|
||||
|
||||
- My Third Group:
|
||||
- My Third Service:
|
||||
href: http://localhost/
|
||||
description: Homepage is 😎
|
||||
widgets:
|
||||
# show the kubernetes widget, with the cluster summary and individual nodes
|
||||
- kubernetes:
|
||||
cluster:
|
||||
show: true
|
||||
cpu: true
|
||||
memory: true
|
||||
showLabel: true
|
||||
label: "cluster"
|
||||
nodes:
|
||||
show: true
|
||||
cpu: true
|
||||
memory: true
|
||||
showLabel: true
|
||||
- search:
|
||||
provider: duckduckgo
|
||||
target: _blank
|
||||
kubernetes:
|
||||
mode: cluster
|
||||
docker:
|
||||
settings:
|
||||
|
||||
serviceAccount:
|
||||
create: true
|
||||
name: homepage
|
||||
|
||||
enableRbac: true
|
||||
|
||||
ingress:
|
||||
main:
|
||||
enabled: true
|
||||
annotations:
|
||||
gethomepage.dev/enabled: "true"
|
||||
gethomepage.dev/name: "Homepage"
|
||||
gethomepage.dev/description: "Dynamically Detected Homepage"
|
||||
gethomepage.dev/group: "Dynamic"
|
||||
gethomepage.dev/icon: "homepage.png"
|
||||
hosts:
|
||||
- host: homepage.k3d.localhost
|
||||
paths:
|
||||
- path: /
|
||||
pathType: Prefix
|
||||
|
||||
persistence:
|
||||
# this persists the .next directory which greatly improves successive pod startup times
|
||||
dotnext:
|
||||
enabled: true
|
||||
type: pvc
|
||||
accessMode: ReadWriteOnce
|
||||
size: 1Gi
|
||||
mountPath: /app/.next
|
@ -0,0 +1,9 @@
|
||||
#!/bin/bash
|
||||
|
||||
k3d cluster create --config k3d.yaml --wait
|
||||
k3d kubeconfig get homepage > kubeconfig
|
||||
chmod 600 kubeconfig
|
||||
export KUBECONFIG=$(pwd)/kubeconfig
|
||||
|
||||
echo "Waiting for traefik install job to complete (CTRL+C is safe if you're impatient)"
|
||||
kubectl wait jobs/helm-install-traefik -n kube-system --for condition=complete --timeout 90s && echo "Completed" || echo "Timed out"
|
@ -0,0 +1,59 @@
|
||||
kind: Simple
|
||||
apiVersion: k3d.io/v1alpha3
|
||||
name: homepage
|
||||
servers: 1
|
||||
agents: 2
|
||||
kubeAPI:
|
||||
hostIP: 0.0.0.0
|
||||
hostPort: "6443"
|
||||
image: rancher/k3s:v1.25.5-k3s1
|
||||
volumes:
|
||||
- volume: /tmp:/tmp/k3d-homepage
|
||||
nodeFilters:
|
||||
- all
|
||||
ports:
|
||||
- port: 8080:80
|
||||
nodeFilters:
|
||||
- loadbalancer
|
||||
- port: 0.0.0.0:8443:443
|
||||
nodeFilters:
|
||||
- loadbalancer
|
||||
options:
|
||||
k3d:
|
||||
wait: true
|
||||
timeout: 6m0s
|
||||
disableLoadbalancer: false
|
||||
disableImageVolume: false
|
||||
disableRollback: false
|
||||
k3s:
|
||||
extraArgs:
|
||||
- arg: --tls-san=127.0.0.1
|
||||
nodeFilters:
|
||||
- server:*
|
||||
nodeLabels: []
|
||||
kubeconfig:
|
||||
updateDefaultKubeconfig: false
|
||||
switchCurrentContext: false
|
||||
runtime:
|
||||
gpuRequest: ""
|
||||
serversMemory: "1024Mi"
|
||||
agentsMemory: "1024Mi"
|
||||
labels:
|
||||
- label: foo=bar
|
||||
nodeFilters:
|
||||
- server:0
|
||||
- loadbalancer
|
||||
env:
|
||||
- envVar: bar=baz
|
||||
nodeFilters:
|
||||
- all
|
||||
registries:
|
||||
create:
|
||||
name: k3d-registry
|
||||
# host: 0.0.0.0
|
||||
hostPort: "55000"
|
||||
config: |
|
||||
mirrors:
|
||||
"k3d-registry.localhost:55000":
|
||||
endpoint:
|
||||
- http://k3d-registry:5000
|
Loading…
Reference in new issue