Skip to content

Commit 5a29281

Browse files
Korifi installer for kind clusters
fixes cloudfoundry#2895 Co-authored-by: Georgi Sabev <georgethebeatle@gmail.com> Co-authored-by: Danail Branekov <danailster@gmail.com>
1 parent 6f457fc commit 5a29281

File tree

4 files changed

+208
-40
lines changed

4 files changed

+208
-40
lines changed

INSTALL.kind.md

+59-38
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,25 @@
33
44
# Install Korifi on kind
55

6-
This document integrates our [install instructions](./INSTALL.md) with specific tips to install Korifi locally using [kind](https://kind.sigs.k8s.io/).
6+
In order to install korifi on kind effortlessly we have prepared an installation job definition that you simply apply to your kind cluster. It will install korifi with reasonable defautls using a local docker registry (also running on your kind cluster).
77

8-
## Initial setup
9-
10-
Export the following environment variables:
11-
12-
```sh
13-
ROOT_NAMESPACE="cf"
14-
KORIFI_NAMESPACE="korifi-system"
15-
ADMIN_USERNAME="kubernetes-admin"
16-
BASE_DOMAIN="apps-127-0-0-1.nip.io"
17-
```
18-
19-
`apps-127-0-0-1.nip.io` will conveniently resolve to `127.0.0.1` using [nip.io](https://nip.io/), which is exactly what we need.
20-
21-
### Cluster creation
8+
## Cluster creation
229

2310
In order to access the Korifi API, we'll need to [expose the cluster ingress locally](https://kind.sigs.k8s.io/docs/user/ingress/). To do it, create your kind cluster using a command like this:
2411

2512
```sh
2613
cat <<EOF | kind create cluster --name korifi --config=-
2714
kind: Cluster
2815
apiVersion: kind.x-k8s.io/v1alpha4
16+
containerdConfigPatches:
17+
- |-
18+
[plugins."io.containerd.grpc.v1.cri".registry]
19+
[plugins."io.containerd.grpc.v1.cri".registry.mirrors]
20+
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."localregistry-docker-registry.default.svc.cluster.local:30050"]
21+
endpoint = ["http://127.0.0.1:30050"]
22+
[plugins."io.containerd.grpc.v1.cri".registry.configs]
23+
[plugins."io.containerd.grpc.v1.cri".registry.configs."127.0.0.1:30050".tls]
24+
insecure_skip_verify = true
2925
nodes:
3026
- role: control-plane
3127
extraPortMappings:
@@ -35,46 +31,71 @@ nodes:
3531
- containerPort: 443
3632
hostPort: 443
3733
protocol: TCP
34+
- containerPort: 30050
35+
hostPort: 30050
36+
protocol: TCP
3837
EOF
3938
```
4039

41-
### Container registry
40+
## Install Korifi
4241

43-
We recommend you use [DockerHub](https://hub.docker.com/) as your container registry.
42+
- Run the installer job:
4443

45-
## Dependencies
44+
```sh
45+
kubectl apply -f https://github.com/cloudfoundry/korifi/releases/latest/download/install-korifi-kind.yaml
46+
```
4647

47-
Follow the [common instructions](./INSTALL.md#dependencies), with the exception of Metrics Server.
48+
- If you want track the job progress, run:
4849

49-
### Metrics Server
50+
```sh
51+
kubectl -n korifi-installer logs --follow job/install-korifi
52+
```
5053

51-
Make sure you pass the following flags to the Metrics Server container (see [_Configuration_](https://github.com/kubernetes-sigs/metrics-server#configuration)):
54+
- **Optional** After the job is complete you can delete the `korifi-installer` namespace
5255

53-
- `--kubelet-insecure-tls`
54-
- `--kubelet-preferred-address-types=InternalIP`
56+
```sh
57+
kubectl delete namespace korifi-installer
58+
```
5559

56-
## Pre-install configuration
60+
## Test Korifi
5761

58-
No changes here, follow the [common instructions](./INSTALL.md#pre-install-configuration).
59-
For the container registry credentials `Secret`, we recommend you [create an access token](https://hub.docker.com/settings/security?generateToken=true) on DockerHub.
62+
- Target the api:
6063

61-
## Install Korifi
64+
```sh
65+
cf api https://localhost --skip-ssl-validation
66+
```
67+
68+
- Authenticate as the cf admin user:
69+
70+
```sh
71+
cf auth kind-korifi
72+
```
6273

63-
No changes here, follow the [common instructions](./INSTALL.md#install-korifi).
64-
If using DockerHub as recommended above, set the following values:
74+
- Create and target an org and a space
75+
76+
```sh
77+
cf create-org org && cf create-space -o org space && cf target -o org
78+
```
6579

66-
- `kpackImageBuilder.builderRepository`: `index.docker.io/<username>/kpack-builder`;
67-
- `containerRepositoryPrefix`: `index.docker.io/<username>/`;
80+
- Push a buildpack app and access it:
6881

69-
Remember to set `generateIngressCertificates` to `true` if you want to use self-signed TLS certificates.
82+
```sh
83+
make build-dorifi
84+
cf push dorifi -p tests/assets/dorifi
85+
curl -k https://dorifi.apps-127-0-0-1.nip.io
86+
```
7087

71-
If `$KORIFI_NAMESPACE` doesn't exist yet, you can add the `--create-namespace` flag to the `helm` invocation.
88+
- Push a docker app and access it:
7289

73-
## Post-install Configuration
90+
```sh
91+
cf push nginx --docker-image nginxinc/nginx-unprivileged:1.23.2
92+
curl -k https://nginx.apps-127-0-0-1.nip.io
93+
```
7494

75-
Yon can skip this section.
95+
## Cleanup
7696

77-
## Test Korifi
97+
When you no longer need korifi you can delete the whole kind cluster via:
7898

79-
No changes here, follow the [common instructions](./INSTALL.md#test-korifi).
80-
When running `cf login`, make sure you select the entry associated to your kind cluster (`kind-korifi` in our case).
99+
```sh
100+
kind delete cluster --name korifi
101+
```

INSTALL.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ This document was tested on:
1919

2020
- [EKS](https://aws.amazon.com/eks/), using AWS' [Elastic Container Registry (ECR)](https://aws.amazon.com/ecr/) (see [_Install Korifi on EKS_](./INSTALL.EKS.md));
2121
- [GKE](https://cloud.google.com/kubernetes-engine), using GCP's [Artifact Registry](https://cloud.google.com/artifact-registry);
22-
- [kind](https://kind.sigs.k8s.io/), using [DockerHub](https://hub.docker.com/) (see [_Install Korifi on kind_](./INSTALL.kind.md)).
22+
- [kind](https://kind.sigs.k8s.io/): see [_Install Korifi on kind_](./INSTALL.kind.md).
2323

2424
## Initial setup
2525

@@ -222,4 +222,4 @@ cf create-space -o org1 space1
222222
cf target -o org1
223223
cd <directory of a test cf app>
224224
cf push test-app
225-
```
225+
```

scripts/installer/Dockerfile

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
FROM ubuntu
2+
3+
ARG HELM_CHART_SOURCE
4+
5+
COPY scripts/install-dependencies.sh scripts/install-dependencies.sh
6+
COPY scripts/create-new-user.sh scripts/create-new-user.sh
7+
COPY tests/dependencies tests/dependencies
8+
COPY tests/vendor tests/vendor
9+
COPY ${HELM_CHART_SOURCE} helm/korifi
10+
11+
RUN apt-get update \
12+
&& apt-get install --yes \
13+
--no-install-recommends \
14+
apt-transport-https \
15+
ca-certificates \
16+
conntrack \
17+
gnupg2 \
18+
curl \
19+
git \
20+
sudo \
21+
&& rm -rf /var/lib/apt/lists/*
22+
23+
# helm
24+
RUN echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/helm.gpg] https://baltocdn.com/helm/stable/debian/ all main" >/etc/apt/sources.list.d/helm-stable-debian.list \
25+
&& curl -fsSL https://baltocdn.com/helm/signing.asc | gpg --dearmor >/usr/share/keyrings/helm.gpg
26+
27+
RUN apt-get update \
28+
&& apt-get install --yes \
29+
helm \
30+
&& rm -rf /var/lib/apt/lists/*
31+
32+
# kubectl
33+
RUN curl -fsSLo /usr/bin/kubectl "https://dl.k8s.io/release/$(curl -fsSL https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" \
34+
&& chmod +x /usr/bin/kubectl
+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
---
2+
apiVersion: v1
3+
kind: Namespace
4+
metadata:
5+
name: korifi-installer
6+
7+
---
8+
apiVersion: v1
9+
kind: Namespace
10+
metadata:
11+
name: cf
12+
labels:
13+
pod-security.kubernetes.io/audit: restricted
14+
pod-security.kubernetes.io/enforce: restricted
15+
16+
---
17+
apiVersion: v1
18+
kind: Namespace
19+
metadata:
20+
name: korifi
21+
labels:
22+
pod-security.kubernetes.io/audit: restricted
23+
pod-security.kubernetes.io/enforce: restricted
24+
25+
---
26+
apiVersion: v1
27+
data:
28+
.dockerconfigjson: eyJhdXRocyI6eyJsb2NhbHJlZ2lzdHJ5LWRvY2tlci1yZWdpc3RyeS5kZWZhdWx0LnN2Yy5jbHVzdGVyLmxvY2FsOjMwMDUwIjp7InVzZXJuYW1lIjoidXNlciIsInBhc3N3b3JkIjoicGFzc3dvcmQiLCJhdXRoIjoiZFhObGNqcHdZWE56ZDI5eVpBPT0ifX19
29+
kind: Secret
30+
metadata:
31+
name: image-registry-credentials
32+
namespace: cf
33+
type: kubernetes.io/dockerconfigjson
34+
35+
---
36+
apiVersion: v1
37+
kind: ServiceAccount
38+
metadata:
39+
name: korifi-installer
40+
namespace: korifi-installer
41+
42+
---
43+
apiVersion: rbac.authorization.k8s.io/v1
44+
kind: ClusterRoleBinding
45+
metadata:
46+
name: korifi-installer
47+
roleRef:
48+
apiGroup: rbac.authorization.k8s.io
49+
kind: ClusterRole
50+
name: cluster-admin
51+
subjects:
52+
- kind: ServiceAccount
53+
name: korifi-installer
54+
namespace: korifi-installer
55+
56+
---
57+
apiVersion: batch/v1
58+
kind: Job
59+
metadata:
60+
name: install-korifi
61+
namespace: korifi-installer
62+
spec:
63+
template:
64+
metadata:
65+
name: install-korifi
66+
spec:
67+
serviceAccountName: korifi-installer
68+
restartPolicy: Never
69+
containers:
70+
- name: install-korifi
71+
image: cloudfoundry/korifi-installer
72+
command:
73+
- bash
74+
- -c
75+
- |
76+
scripts/install-dependencies.sh --insecure-tls-metrics-server
77+
78+
helm repo add twuni https://helm.twun.io
79+
# the htpasswd value below is username: user, password: password encoded using `htpasswd` binary
80+
# e.g. `docker run --entrypoint htpasswd httpd:2 -Bbn user password`
81+
#
82+
helm upgrade --install localregistry twuni/docker-registry \
83+
--namespace default \
84+
--set service.type=NodePort,service.nodePort=30050,service.port=30050 \
85+
--set persistence.enabled=true \
86+
--set persistence.deleteEnabled=true \
87+
--set secrets.htpasswd='user:$2y$05$Ue5dboOfmqk6Say31Sin9uVbHWTl8J1Sgq9QyAEmFQRnq1TPfP1n2'
88+
89+
registry_status_code=""
90+
while [[ "$registry_status_code" != "200" ]]; do
91+
echo Waiting for the local docker registry to start...
92+
registry_status_code=$(curl -o /dev/null -w "%{http_code}" --user user:password http://localregistry-docker-registry.default.svc.cluster.local:30050/v2/_catalog 2>/dev/null)
93+
sleep 1
94+
done
95+
96+
helm upgrade --install korifi helm/korifi \
97+
--namespace korifi \
98+
--set=adminUserName="kubernetes-admin" \
99+
--set=defaultAppDomainName="apps-127-0-0-1.nip.io" \
100+
--set=generateIngressCertificates="true" \
101+
--set=logLevel="debug" \
102+
--set=debug="false" \
103+
--set=stagingRequirements.buildCacheMB="1024" \
104+
--set=api.apiServer.url="localhost" \
105+
--set=controllers.taskTTL="5s" \
106+
--set=jobTaskRunner.jobTTL="5s" \
107+
--set=containerRepositoryPrefix="localregistry-docker-registry.default.svc.cluster.local:30050/" \
108+
--set=kpackImageBuilder.clusterStackBuildImage="paketobuildpacks/build-jammy-base" \
109+
--set=kpackImageBuilder.clusterStackRunImage="paketobuildpacks/run-jammy-base" \
110+
--set=kpackImageBuilder.builderRepository="localregistry-docker-registry.default.svc.cluster.local:30050/kpack-builder" \
111+
--wait
112+
113+
kubectl wait --for=condition=ready clusterbuilder --all=true --timeout=15m

0 commit comments

Comments
 (0)