Created
April 5, 2025 07:57
-
-
Save IJMacD/dc17fc62f4214160b499c5df4cffbeeb to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/bin/bash | |
set -e | |
usage () { | |
printf "Usage:\n $0 <directory> <domain.com> [<version>]\n" | |
} | |
if [ $# -lt 2 ]; then | |
usage | |
exit 1 | |
fi | |
dir=$1 | |
domain=$2 | |
version=${3:-1.0.0} | |
repo=ijmacd | |
image=$repo/$domain:$version | |
name=${domain%%.*} | |
echo "Deploying directory '$dir' as $image to https://$domain" | |
if [[ ! -d $dir ]]; then | |
echo "Cannot find directory '$dir'" | |
exit 1 | |
fi | |
docker build -t $image --push -f - . << EOF | |
FROM nginx:1.27.4 | |
COPY "$dir" /usr/share/nginx/html | |
EOF | |
kubectl apply -f - << EOF | |
apiVersion: apps/v1 | |
kind: Deployment | |
metadata: | |
name: "$name-web" | |
labels: | |
app.kubernetes.io/name: "static-to-cluster" | |
app.kubernetes.io/instance: "$domain" | |
app.kubernetes.io/version: "$version" | |
app.kubernetes.io/component: web | |
spec: | |
replicas: 1 | |
selector: | |
matchLabels: | |
app.kubernetes.io/component: web | |
app.kubernetes.io/instance: "$domain" | |
template: | |
metadata: | |
labels: | |
app.kubernetes.io/component: web | |
app.kubernetes.io/instance: "$domain" | |
spec: | |
containers: | |
- name: web | |
image: "$image" | |
ports: | |
- name: web | |
containerPort: 80 | |
--- | |
apiVersion: v1 | |
kind: Service | |
metadata: | |
name: "$name-web" | |
labels: | |
app.kubernetes.io/component: web | |
app.kubernetes.io/name: "static-to-cluster" | |
app.kubernetes.io/instance: "$domain" | |
spec: | |
selector: | |
app.kubernetes.io/component: web | |
app.kubernetes.io/instance: "$domain" | |
ports: | |
- protocol: TCP | |
name: "web" | |
port: 80 | |
targetPort: web | |
--- | |
apiVersion: gateway.networking.k8s.io/v1 | |
kind: HTTPRoute | |
metadata: | |
name: '$name-web' | |
spec: | |
hostnames: | |
- "$domain" | |
parentRefs: | |
- group: gateway.networking.k8s.io | |
kind: Gateway | |
name: gateway | |
namespace: default | |
sectionName: https | |
rules: | |
- backendRefs: | |
- group: '' | |
kind: Service | |
name: '$name-web' | |
port: 80 | |
weight: 1 | |
matches: | |
- path: | |
type: PathPrefix | |
value: / | |
EOF | |
echo "In a few minutes the site will be available at https://$domain" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment