From aa230f92f8d4087fa0c6885d91b66e3e667e64e1 Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Sun, 9 Jun 2024 15:36:50 -0700 Subject: [PATCH] Retool the demo Rather than hugo, which I really don't know much about and don't care to maintain, it now is just a trivial HTTP server (python) serving content from this repo. --- demo/README.md | 36 +++++++++--------------- demo/blog/archetypes/.keep | 0 demo/blog/config.toml | 3 -- demo/blog/content/about.md | 9 ------ demo/blog/content/post/first.md | 9 ------ demo/blog/layouts/.keep | 0 demo/blog/static/.keep | 0 demo/config/deployment.yaml | 49 -------------------------------- demo/deployment.yaml | 50 +++++++++++++++++++++++++++++++++ demo/html/index.html | 9 ++++++ demo/hugo/Dockerfile | 26 ----------------- demo/hugo/README.md | 12 -------- demo/hugo/run-hugo | 21 -------------- demo/{config => }/service.yaml | 7 +++-- 14 files changed, 76 insertions(+), 155 deletions(-) delete mode 100644 demo/blog/archetypes/.keep delete mode 100644 demo/blog/config.toml delete mode 100644 demo/blog/content/about.md delete mode 100644 demo/blog/content/post/first.md delete mode 100644 demo/blog/layouts/.keep delete mode 100644 demo/blog/static/.keep delete mode 100644 demo/config/deployment.yaml create mode 100644 demo/deployment.yaml create mode 100644 demo/html/index.html delete mode 100644 demo/hugo/Dockerfile delete mode 100644 demo/hugo/README.md delete mode 100755 demo/hugo/run-hugo rename demo/{config => }/service.yaml (60%) diff --git a/demo/README.md b/demo/README.md index 4a00e6f32..d7484ef77 100644 --- a/demo/README.md +++ b/demo/README.md @@ -1,35 +1,25 @@ -# git-blog-demo +# git-sync-demo -This demo shows how to use the `git-sync` sidekick container along side `volumes` and `volumeMounts` to create a markdown powered blog. +This demo shows how to use a `git-sync` container alongside an HTTP server to +serve static content. ## How it works -The pod is composed of 3 containers that share directories using 2 volumes: +The pod is composed of 2 containers that share a volume. -- The `git-sync` container clones a git repo into the `markdown` volume -- The `hugo` container read from the `markdown` volume and render it into the `html` volume. -- The `nginx` container serve the content from the `html` volume. +- The `git-sync` container clones a git repo into the `content` volume +- The `http` container serves that content -## Usage - -### Build demo containers (Optional) - -Build the demo containers, and push them to a registry - -``` -docker build -t /git-sync .. -docker build -t /hugo hugo/ -docker push /hugo /git-sync -``` +For the purposes of this demo, it's about as trivial as it can get. -If you end up using a different registry, be sure to update `config/deployment.yaml`. - -### +## Usage -Create the pod and the service for the blog +Apply the deployment and the service files: ``` -kubectl create -f config +kubectl apply -f deployment.yaml +kubectl apply -f service.yaml ``` -Open the service external ip in your browser +Wait for the service to be assigned a LoadBalancer IP, then open that IP in +your browser. diff --git a/demo/blog/archetypes/.keep b/demo/blog/archetypes/.keep deleted file mode 100644 index e69de29bb..000000000 diff --git a/demo/blog/config.toml b/demo/blog/config.toml deleted file mode 100644 index ab3aa9e44..000000000 --- a/demo/blog/config.toml +++ /dev/null @@ -1,3 +0,0 @@ -baseurl = "http://example.com" -languageCode = "en-us" -title = "example blog" diff --git a/demo/blog/content/about.md b/demo/blog/content/about.md deleted file mode 100644 index afb2ac0f4..000000000 --- a/demo/blog/content/about.md +++ /dev/null @@ -1,9 +0,0 @@ -+++ -date = "2014-12-19T15:29:48-08:00" -draft = true -title = "about" -+++ - -## A headline - -Some content about the blog. diff --git a/demo/blog/content/post/first.md b/demo/blog/content/post/first.md deleted file mode 100644 index 630bbbd01..000000000 --- a/demo/blog/content/post/first.md +++ /dev/null @@ -1,9 +0,0 @@ -+++ -date = "2014-12-19T15:30:18-08:00" -draft = true -title = "first" -+++ - -## first port - -This is the first post. diff --git a/demo/blog/layouts/.keep b/demo/blog/layouts/.keep deleted file mode 100644 index e69de29bb..000000000 diff --git a/demo/blog/static/.keep b/demo/blog/static/.keep deleted file mode 100644 index e69de29bb..000000000 diff --git a/demo/config/deployment.yaml b/demo/config/deployment.yaml deleted file mode 100644 index 769342348..000000000 --- a/demo/config/deployment.yaml +++ /dev/null @@ -1,49 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: blog -spec: - replicas: 1 - selector: - matchLabels: - name: blog - template: - metadata: - labels: - name: blog - spec: - containers: - - name: git-sync - image: registry.k8s.io/git-sync:v3.1.3 - volumeMounts: - - name: markdown - mountPath: /tmp/git - env: - - name: GITSYNC_REPO - value: https://github.com/kubernetes/git-sync.git - - name: GITSYNC_LINK - value: git-sync - - name: hugo - image: registry.k8s.io/hugo - volumeMounts: - - name: markdown - mountPath: /src - - name: html - mountPath: /dest - env: - - name: HUGO_SRC - value: /src/git-sync/demo/blog - - name: HUGO_BUILD_DRAFT - value: "true" - - name: HUGO_BASE_URL - value: example.com - - name: nginx - image: nginx - volumeMounts: - - name: html - mountPath: /usr/share/nginx/html - volumes: - - name: markdown - emptyDir: {} - - name: html - emptyDir: {} diff --git a/demo/deployment.yaml b/demo/deployment.yaml new file mode 100644 index 000000000..b318b9874 --- /dev/null +++ b/demo/deployment.yaml @@ -0,0 +1,50 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: static-server +spec: + replicas: 1 + selector: + matchLabels: + app: static-server + template: + metadata: + labels: + app: static-server + spec: + volumes: + - name: content + emptyDir: {} + containers: + # This container pulls a git repo into the "content" volume. If this + # were a "real" app it would probably have livenessProbe and resources, + # and maybe a secret to get credentials for your git server. + - name: git-sync + image: registry.k8s.io/git-sync/git-sync:v4.2.3 + args: + - --repo=https://github.com/kubernetes/git-sync + - --root=/git + - --period=60s + - --link=head + - --max-failures=1000000000 + - -v=2 + volumeMounts: + - name: content + mountPath: /git + # This container is a trivial HTTP server for the content. + # If this were a "real" app it would not be so trivial. For example, + # nginx or apache are much more robust web servers! It's missing a + # livenessProbe, resources, and many other things you would want for + # running in production. Also, you would probably have a git repo + # dedicated to holding your content. + - name: http + image: python:alpine + args: + - python3 + - -m + - http.server + - -d=/git/head/demo/html + volumeMounts: + - name: content + mountPath: /git + readOnly: true diff --git a/demo/html/index.html b/demo/html/index.html new file mode 100644 index 000000000..1b0178168 --- /dev/null +++ b/demo/html/index.html @@ -0,0 +1,9 @@ + + + + +

That's it, that's the demo

+

Impressive, right?

+ + + diff --git a/demo/hugo/Dockerfile b/demo/hugo/Dockerfile deleted file mode 100644 index 88d3b4350..000000000 --- a/demo/hugo/Dockerfile +++ /dev/null @@ -1,26 +0,0 @@ -# Copyright 2014 Google Inc. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -FROM golang -RUN go get -v github.com/spf13/hugo -RUN git clone --recursive https://github.com/spf13/hugoThemes.git /themes -VOLUME ["/src", "/dest"] -EXPOSE 1313 -ENV HUGO_SRC /src -ENV HUGO_DEST /dest -ENV HUGO_THEME hyde -ENV HUGO_BUILD_DRAFT false -ENV HUGO_BASE_URL "" -ADD run-hugo /run-hugo -ENTRYPOINT ["/run-hugo"] -CMD ["server", "--source=${HUGO_SRC}", "--theme=${HUGO_THEME}", "--buildDrafts=${HUGO_BUILD_DRAFT}", "--baseUrl=${HUGO_BASE_URL}", "--watch", "--destination=${HUGO_DEST}", "--appendPort=false"] diff --git a/demo/hugo/README.md b/demo/hugo/README.md deleted file mode 100644 index d5510e3eb..000000000 --- a/demo/hugo/README.md +++ /dev/null @@ -1,12 +0,0 @@ -# hugo - -`hugo` is a container that convert markdown into html using [hugo static site generator](http://gohugo.io/). - -## Usage - -``` -# build the container -docker build -t hugo . -# run the hugo container -docker run -e HUGO_BASE_URL=example.com -v /path/to/md:/src -v /path/to/html:/dest hugo -``` diff --git a/demo/hugo/run-hugo b/demo/hugo/run-hugo deleted file mode 100755 index 784efad43..000000000 --- a/demo/hugo/run-hugo +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash - -# Copyright 2014 Google Inc. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -set -ex -if [ ! -d ${HUGO_SRC}/themes ]; then - ln -s /themes ${HUGO_SRC}/themes -fi -hugo $(eval echo $*) # force default CMD env expansion diff --git a/demo/config/service.yaml b/demo/service.yaml similarity index 60% rename from demo/config/service.yaml rename to demo/service.yaml index e50a38121..912c7b51a 100644 --- a/demo/config/service.yaml +++ b/demo/service.yaml @@ -1,10 +1,11 @@ apiVersion: v1 kind: Service metadata: - name: blog-service + name: static-server spec: + selector: + app: static-server type: LoadBalancer ports: - port: 80 - selector: - name: blog + targetPort: 8000