Skip to content

Commit

Permalink
kind-create-cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieu-benoit committed Jun 5, 2024
1 parent 00bc1e3 commit ec7d0ff
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 8 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,29 @@ jobs:
- name: make compose-test
run: |
make compose-test
score-k8s:
runs-on: ubuntu-24.04
env:
SCORE_K8S_VERSION: 'latest'
steps:
- name: checkout code
uses: actions/checkout@v4
- name: install score-k8s
uses: score-spec/setup-score@v3
with:
file: score-k8s
token: ${{ secrets.GITHUB_TOKEN }}
version: ${{ env.SCORE_K8S_VERSION }}
- name: make kind-create-cluster
run: |
make kind-create-cluster
- name: make k8s-up
id: k8s-up
run: |
make k8s-up
- name: catch k8s-up errors
if: ${{ failure() && steps.k8s-up.outcome == 'failure' }}
run: |
kubectl get events
kubectl logs \
-l score-workload=${{ env.WORKLOAD_NAME }}
23 changes: 15 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ compose.yaml: apps/ad/score.yaml apps/cart/score.yaml apps/checkout/score.yaml a
.PHONY: compose-up
compose-up: compose.yaml
docker compose up --build -d --remove-orphans
sleep 5

## Generate a compose.yaml file from the score spec, launch it and test (curl) the exposed container.
.PHONY: compose-test
compose-test: compose-up
sleep 5
curl $$(score-compose resources get-outputs dns.default#frontend.dns --format '{{ .host }}:8080')

## Delete the containers running via compose down.
Expand All @@ -63,24 +63,31 @@ manifests.yaml: apps/ad/score.yaml apps/cart/score.yaml apps/checkout/score.yaml
apps/recommendation/score.yaml \
apps/shipping/score.yaml

## Create a local Kind cluster.
.PHONY: kind-create-cluster
kind-create-cluster:
./scripts/setup-kind-cluster.sh

NAMESPACE ?= default
## Generate a manifests.yaml file from the score spec and apply it in Kubernetes.
.PHONY: k8s-up
k8s-up: manifests.yaml
$(MAKE) compose-down || true
kubectl apply \
-f manifests.yaml \
-n ${NAMESPACE}

## Expose the container deployed in Kubernetes via port-forward.
.PHONY: k8s-test
k8s-test: k8s-up
kubectl wait deployments/frontend \
-n ${NAMESPACE} \
--for condition=Available
kubectl wait pods \
-n ${NAMESPACE} \
-l score-workload=frontend \
-l app.kubernetes.io/name=frontend \
--for condition=Ready \
--timeout=90s
kubectl -n nginx-gateway port-forward service/ngf-nginx-gateway-fabric 8080:80

## Expose the container deployed in Kubernetes via port-forward.
.PHONY: k8s-test
k8s-test: k8s-up
curl $$(score-k8s resources get-outputs dns.default#frontend.dns --format '{{ .host }}')

## Delete the deployment of the local container in Kubernetes.
.PHONY: k8s-down
Expand Down
35 changes: 35 additions & 0 deletions scripts/setup-kind-cluster.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash
set -o errexit

cat <<EOF | kind create cluster --config=-
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
extraPortMappings:
- containerPort: 31000
hostPort: 80
protocol: TCP
EOF

kubectl apply \
-f https://github.com/kubernetes-sigs/gateway-api/releases/download/v1.1.0/standard-install.yaml

helm install ngf oci://ghcr.io/nginxinc/charts/nginx-gateway-fabric \
--create-namespace \
-n nginx-gateway \
--set service.type=NodePort \
--set-json 'service.ports=[{"port":80,"nodePort":31000}]'

kubectl apply -f - <<EOF
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: default
spec:
gatewayClassName: nginx
listeners:
- name: http
port: 80
protocol: HTTP
EOF

0 comments on commit ec7d0ff

Please sign in to comment.