Skip to content

Commit

Permalink
chore: update the doc on how to work locally
Browse files Browse the repository at this point in the history
  • Loading branch information
mavimo committed Oct 7, 2023
1 parent 814932d commit 54d9b60
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 40 deletions.
13 changes: 13 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/.github
/bin
/charts
/kubernetes

/.gitignore
/.goreleaser.yaml
/CONTRIBUTING.md
/ct.yaml
/skaffold.yaml
/README.md
/Makefile
/LICENSE.txt
44 changes: 12 additions & 32 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,20 @@
## Requirements

- A running kubernetes cluster (if you don't have one see *Setup a local cluster* section)
- [skaffold](https://skaffold.dev/) installed on your machine
- [helm 3](https://helm.sh/) installed on your machine
- [kubectl](https://kubernetes.io/docs/tasks/tools/#kubectl/) installed on your machine
- [skaffold](https://skaffold.dev/) installed on your machine

### Setup a local cluster

- You need a machine with [docker](https://docker.io) up & running
- You need to install [kind](https://kind.sigs.k8s.io/) on your machine

Then we can create a two nodes cluster (one master and one worker):

```bash
cat <<EOF | kind create cluster --config=-
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: worker
EOF
```
and activate the `kubectl` config via:
```
kind export kubeconfig
```
- If you are using Docker Desktop enable the kubernetes cluster from the config (see [docs](https://docs.docker.com/desktop/kubernetes/) here)

## Setup development env
Otherwise you can decide to use [kind]() or [minukube]()

Replace also the domain name to use in `kubernetes/sample/example-ingress.yaml` from `kubernetes.localhost` to your domain (ensure also that the subdomain `example1` and `example2` are resolved to the server public IP)

Create a namespace to host the caddy ingress controller:
```
kubectl create ns caddy-system
```
## Setup development env

Then we can start skaffold using:
Start `skaffold` using the command:
```
make dev
```
Expand All @@ -48,17 +27,18 @@ this will automatically:

You can test that all work as expected with:
```
curl -H 'Host: example1.kubernetes.localhost http://127.0.0.1:80/hello1
curl -H 'Host: example1.kubernetes.localhost http://127.0.0.1:80/hello2
curl -H 'Host: example2.kubernetes.localhost http://127.0.0.1:80/hello1
curl -H 'Host: example2.kubernetes.localhost http://127.0.0.1:80/hello2
curl -D - -s -k https://example1.kubernetes.localhost:8443/hello1 --resolve example1.kubernetes.localhost:8443:127.0.0.1
curl -D - -s -k https://example1.kubernetes.localhost:8443/hello2 --resolve example1.kubernetes.localhost:8443:127.0.0.1
curl -D - -s -k https://example2.kubernetes.localhost:8443/hello1 --resolve example2.kubernetes.localhost:8443:127.0.0.1
curl -D - -s -k https://example2.kubernetes.localhost:8443/hello2 --resolve example2.kubernetes.localhost:8443:127.0.0.1
```

You can change domains defined in `kuberentes/sample` folder with some domain that are risolved on your local machine or you can add them in the `/etc/host` file to be automatically resolved as localhost.

## Notes

- You can change local port forwarded by skaffold by changing the port values in the `skaffold.yaml` file on section `portForward` `localPort`. Remind that you can forward only port greater than 1024 if you execute it as non-root user
- You can delete your local cluster with the command `kind delete cluster`
- To use TLS your domain should be publicly resolved to your cluster IP in order to allow Let's Encrypt to validate the domain
- We use an internal CA for test to simplify the installation, but then you can decide to use external CA for tests, see the `values.yaml` in the helm chart for the info on how to configure it.

## Releasing new helm chart version

Expand Down
19 changes: 19 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM golang:1.21 as build

ENV CGO_ENABLED=0

WORKDIR /go/ingress-controller

COPY go.mod go.sum /go/ingress-controller/
RUN go mod download

COPY . .
RUN go build -o ./bin/ingress-controller ./cmd/caddy

FROM gcr.io/distroless/static-debian11

EXPOSE 80 443

COPY --from=build /go/ingress-controller/bin/ingress-controller /ingress-controller

ENTRYPOINT ["/ingress-controller"]
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ build:
@mkdir -p bin
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ./bin/ingress-controller ./cmd/caddy

dev: build
dev:
skaffold dev --port-forward
18 changes: 11 additions & 7 deletions skaffold.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,24 @@ metadata:
name: caddy-ingress-controller
build:
artifacts:
- image: caddy/ingress
- image: caddy-ingress
context: .
docker:
dockerfile: Dockerfile.dev
deploy:
helm:
releases:
- name: caddy-ingress-development
namespace: caddy-system
chartPath: charts/caddy-ingress-controller
recreatePods: true
createNamespace: true
setValueTemplates:
image:
repository: {{.IMAGE_FULLY_QUALIFIED_caddy_ingress}}
# kubectl:
# manifests:
# - kubernetes/sample/*.yaml
repository: "{{ .IMAGE_REPO_NO_DOMAIN_caddy_ingress }}"
tag: "{{.IMAGE_TAG_caddy_ingress}}@{{.IMAGE_DIGEST_caddy_ingress}}"
manifests:
rawYaml:
- ./kubernetes/sample/*.yaml
portForward:
- resourceType: service
resourceName: caddy-ingress-development-caddy-ingress-controller
Expand All @@ -30,4 +34,4 @@ portForward:
namespace: caddy-system
address: 0.0.0.0
port: 443
localPort: 8443
localPort: 8443

0 comments on commit 54d9b60

Please sign in to comment.