Skip to content

Commit

Permalink
WIP with ingress
Browse files Browse the repository at this point in the history
  • Loading branch information
byrnedo committed Jul 15, 2024
1 parent 3c38ff6 commit 0edc5e7
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ spec:
Service resources are ignored and it's implicit that a pod has a service with url: `<labels.name>.<metadata.namespace>.cluster.skate`

Plan:
- Nginx container mounts /etc/skate/ingress.conf
- Nginx container mounts /var/lib/skate/ingress/nginx.conf
- nginx reloads on file change
- skatelet updates the file on ingress resource change
- use letsencrypt and http verification
Expand Down
2 changes: 1 addition & 1 deletion hack/test-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ metadata:
labels:
app: nginx
spec:
replicas: 3
replicas: 1
selector:
matchLabels:
app: nginx
Expand Down
6 changes: 3 additions & 3 deletions images/coredns/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.PHONY: build-and-push
build-and-push:
GOOS=linux GOARCH=arm GOARM=6 CGO_ENABLED=0 go build -ldflags="-w -s" -o build/armv6/coredns .
GOOS=linux GOARCH=arm GOARM=7 CGO_ENABLED=0 go build -ldflags="-w -s" -o build/armv7/coredns .
# GOOS=linux GOARCH=arm GOARM=6 CGO_ENABLED=0 go build -ldflags="-w -s" -o build/armv6/coredns .
# GOOS=linux GOARCH=arm GOARM=7 CGO_ENABLED=0 go build -ldflags="-w -s" -o build/armv7/coredns .
GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build -ldflags="-w -s" -o build/arm64/coredns .
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags="-w -s" -o build/amd64/coredns .
docker buildx build --platform linux/arm/v6,linux/arm/v7,linux/arm64,linux/amd64 -t ghcr.io/skateco/coredns:latest --push .
docker buildx build --platform linux/arm64,linux/amd64 -t ghcr.io/skateco/coredns:latest --push .
7 changes: 4 additions & 3 deletions images/nginx-ingress/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ RUN DEBIAN_FRONTEND=noninteractive \
curl \
unzip \
make \
python3 \
bsdmainutils && \
rm -rf /var/lib/apt/lists/* && \
curl -L https://luarocks.org/releases/luarocks-3.11.1.tar.gz --output /tmp/luarocks-3.11.1.tar.gz && \
Expand All @@ -38,9 +39,9 @@ RUN DEBIAN_FRONTEND=noninteractive \

COPY docker_entrypoint.sh /docker_entrypoint.sh

COPY error.html /etc/skate/ingress/
#COPY nginx.conf.tmpl /etc/skate/ingress/
#COPY test/ /etc/skate/ingress/test
COPY error.html /etc/nginx-ingress/
#COPY nginx.conf.tmpl /etc/nginx-ingress
#COPY test/ /etc/nginx-ingress/test


COPY lua $RESTY_ROOT/nginx/lua
Expand Down
3 changes: 3 additions & 0 deletions images/nginx-ingress/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.PHONY: build-and-push
build-and-push:
docker buildx build --platform linux/arm64,linux/amd64 -t ghcr.io/skateco/nginx-ingress:latest --push .
6 changes: 5 additions & 1 deletion images/nginx-ingress/docker_entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ set -eu


# the path openresty will look for the nginx config
CONF_PATH="/etc/skate/ingress/nginx.conf"
CONF_PATH="/var/lib/skate/ingress/nginx.conf"

if [ ! -f "$CONF_PATH" ]; then
cp /etc/openresty/nginx.conf $CONF_PATH
fi

pidfile=/usr/local/openresty/nginx/logs/nginx.pid

Expand Down
4 changes: 2 additions & 2 deletions images/nginx-ingress/lua/error_page.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ local function getVars(code)
end

local template = require "resty.template".new({
root = "/etc/skate/ingress",
location = "/etc/skate/ingress"
root = "/etc/nginx-ingress/",
location = "/etc/nginx-ingress"
})

function _M.go(err_code)
Expand Down
14 changes: 7 additions & 7 deletions manifests/ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: nginx
name: nginx-ingress
namespace: skate
labels:
app: nginx
app: nginx-ingress
spec:
selector:
matchLabels:
app: nginx
app: nginx-ingress
template:
metadata:
labels:
app: nginx
app: nginx-ingress
spec:
hostNetwork: true
volumes:
- name: cni
- name: ingress
hostPath:
path: /var/lib/skate/ingress
containers:
- name: coredns
image: ghcr.io/skateco/coredns
- name: nginx
image: ghcr.io/skateco/nginx-ingress
volumeMounts:
- mountPath: /var/lib/skate/ingress
name: ingress
20 changes: 17 additions & 3 deletions src/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use crate::ssh::{cluster_connections, node_connection, SshClient, SshClients};
use crate::util::{CHECKBOX_EMOJI, CROSS_EMOJI};

const COREDNS_MANIFEST: &str = include_str!("../manifests/coredns.yaml");
const INGRESS_MANIFEST: &str = include_str!("../manifests/ingress.yaml");

#[derive(Debug, Args)]
pub struct CreateArgs {
Expand Down Expand Up @@ -176,6 +177,7 @@ async fn create_node(args: CreateNodeArgs) -> Result<(), Box<dyn Error>> {
let all_conns = &all_conns.unwrap_or(SshClients { clients: vec!() });


_ = conn.execute("sudo mkdir -p /var/lib/skate/ingress").await?;
_ = conn.execute("sudo podman rm -fa").await;

setup_networking(&conn, &all_conns, &cluster, &node).await?;
Expand All @@ -192,19 +194,18 @@ async fn create_node(args: CreateNodeArgs) -> Result<(), Box<dyn Error>> {
}

async fn install_manifests(args: &CreateNodeArgs, config: &Cluster, node: &Node) -> Result<(), Box<dyn Error>> {

/// COREDNS
/// coredns listens on port 53 and 5533
/// port 53 serves .cluster.skate by forwarding to all coredns instances on port 5553
/// uses fanout plugin
let coredns_yaml_path = format!("/tmp/skate-coredns-{}.yaml", node.name);
let mut file = File::create(&coredns_yaml_path)?;
// replace forward list in coredns config with that of other hosts
let fanout_list = config.nodes.iter().map(|n| n.host.clone() + ":5553").join(" ");

let coredns_yaml = COREDNS_MANIFEST.replace("%%fanout_list%%", &fanout_list);

let coredns_yaml_path = format!("/tmp/skate-coredns-{}.yaml", node.name);
let mut file = File::create(&coredns_yaml_path)?;
file.write_all(coredns_yaml.as_bytes())?;


Expand All @@ -214,6 +215,19 @@ async fn install_manifests(args: &CreateNodeArgs, config: &Cluster, node: &Node)
config: args.config.clone(),
}).await?;

// nginx ingress

let nginx_yaml_path = format!("/tmp/skate-nginx-ingress-{}.yaml", node.name);
let mut file = File::create(&nginx_yaml_path)?;
file.write_all(INGRESS_MANIFEST.as_bytes())?;


apply(ApplyArgs {
filename: vec![nginx_yaml_path],
grace_period: 0,
config: args.config.clone(),
}).await?;

Ok(())
}

Expand Down

0 comments on commit 0edc5e7

Please sign in to comment.