-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(nfs): cleanup RWX experiments (refs #57)
- Loading branch information
Showing
14 changed files
with
239 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# nfs-demo | ||
|
||
Illustrates the use of a "nfs" storage class providing ReadWriteMany support. | ||
|
||
## How it works? | ||
|
||
* [manifest/pvc.yaml](manifest/pvc.yaml) claims a RWX PersistentVolume for nginx data | ||
* [manifest/deployment.yaml](manifest/deployment.yaml) creates a nginx server | ||
* [manifest/service.yaml](manifest/services.yaml) exposes nginx as services | ||
* [manifest/cronjob.yaml](manifest/cronjob.yaml) periodically updates index.html | ||
|
||
## Usage with Kubernetes | ||
|
||
```bash | ||
# Deploy nfs-demo | ||
bash nfs-demo/k8s-install.sh | ||
|
||
# Test service | ||
kubectl -n nfs-demo run --rm -ti busybox --image=busybox --restart=Never -- /bin/sh -c "wget -q -O- http://nfs-demo" | ||
``` | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/bin/bash | ||
|
||
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) | ||
|
||
DEVBOX_HOSTNAME=${DEVBOX_HOSTNAME:-dev.localhost} | ||
DEVBOX_INGRESS=${DEVBOX_INGRESS:-traefik} | ||
DEVBOX_ISSUER=${DEVBOX_ISSUER:-mkcert} | ||
|
||
# Create namespace nfs-demo if not exists | ||
kubectl create namespace nfs-demo --dry-run=client -o yaml | kubectl apply -f - | ||
|
||
# Deploy nfs-demo with Kustomize | ||
kubectl -n nfs-demo apply -k ${SCRIPT_DIR}/manifest | ||
|
||
# Wait for Pods to be ready | ||
kubectl -n nfs-demo wait \ | ||
--for=condition=ready pod \ | ||
--selector=component=server \ | ||
--timeout=60s | ||
|
||
# Create Ingress with dynamic hostname | ||
cat <<EOF | kubectl -n nfs-demo apply -f - | ||
apiVersion: networking.k8s.io/v1 | ||
kind: Ingress | ||
metadata: | ||
name: nfs-demo | ||
annotations: | ||
cert-manager.io/cluster-issuer: "${DEVBOX_ISSUER}" | ||
spec: | ||
ingressClassName: ${DEVBOX_INGRESS} | ||
rules: | ||
- host: nfs-demo.$DEVBOX_HOSTNAME | ||
http: | ||
paths: | ||
- pathType: ImplementationSpecific | ||
path: "/" | ||
backend: | ||
service: | ||
name: nfs-demo | ||
port: | ||
number: 80 | ||
tls: | ||
- hosts: | ||
- nfs-demo.$DEVBOX_HOSTNAME | ||
secretName: nfs-demo-cert | ||
EOF | ||
|
||
# Display resources | ||
kubectl -n nfs-demo get pvc,pods,svc,ingress | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/bash | ||
|
||
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) | ||
|
||
# Uninstall nfs-demo | ||
kubectl -n nfs-demo delete -k ${SCRIPT_DIR}/manifest | ||
|
||
# Remove Ingress | ||
kubectl -n nfs-demo delete ingress nfs-demo | ||
|
||
# Remove namespace | ||
kubectl delete namespace nfs-demo | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
apiVersion: batch/v1 | ||
kind: CronJob | ||
metadata: | ||
name: nfs-demo-update | ||
spec: | ||
jobTemplate: | ||
metadata: | ||
name: nfs-demo-update | ||
spec: | ||
template: | ||
metadata: | ||
labels: | ||
component: backend | ||
spec: | ||
containers: | ||
- image: busybox | ||
name: update | ||
command: ["/bin/sh","-c","echo $(date) -- update index.html ... ; date > /usr/share/nginx/html/index.html"] | ||
volumeMounts: | ||
- name: nfs-demo-data | ||
mountPath: /usr/share/nginx/html | ||
volumes: | ||
- name: nfs-demo-data | ||
persistentVolumeClaim: | ||
claimName: nfs-demo-pvc | ||
restartPolicy: OnFailure | ||
schedule: '* * * * *' | ||
successfulJobsHistoryLimit: 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
labels: | ||
app: nfs-demo | ||
name: nfs-demo | ||
spec: | ||
replicas: 3 | ||
selector: | ||
matchLabels: | ||
app: nfs-demo | ||
template: | ||
metadata: | ||
labels: | ||
app: nfs-demo | ||
component: server | ||
spec: | ||
containers: | ||
- image: nginx | ||
name: nginx | ||
volumeMounts: | ||
- name: nfs-demo-data | ||
mountPath: /usr/share/nginx/html | ||
volumes: | ||
- name: nfs-demo-data | ||
persistentVolumeClaim: | ||
claimName: nfs-demo-pvc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
apiVersion: kustomize.config.k8s.io/v1beta1 | ||
kind: Kustomization | ||
|
||
resources: | ||
- pvc.yaml | ||
- deployment.yaml | ||
- service.yaml | ||
- cronjob.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Claims a PersistentVolume using "nfs" storage class. | ||
# As a network file system, it can be mounted on Pods | ||
# running on multiple nodes (ReadWriteMany) | ||
kind: PersistentVolumeClaim | ||
apiVersion: v1 | ||
metadata: | ||
name: nfs-demo-pvc | ||
spec: | ||
storageClassName: "nfs" | ||
accessModes: | ||
- ReadWriteMany | ||
resources: | ||
requests: | ||
storage: 100Mi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
labels: | ||
app: nfs-demo | ||
name: nfs-demo | ||
spec: | ||
ports: | ||
- port: 80 | ||
selector: | ||
app: nfs-demo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/bash | ||
|
||
helm -n nfs-system uninstall nfs-server | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters