Skip to content

Commit 7150414

Browse files
Add document to configure podman to use tilt (#1398)
Co-authored-by: Karthik K N <[email protected]>
1 parent f04f55d commit 7150414

File tree

4 files changed

+153
-0
lines changed

4 files changed

+153
-0
lines changed

Makefile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ PULL_BASE_REF ?= $(RELEASE_TAG) # PULL_BASE_REF will be provided by Prow
5656
RELEASE_ALIAS_TAG ?= $(PULL_BASE_REF)
5757
RELEASE_DIR := out
5858

59+
# kind
60+
CAPI_KIND_CLUSTER_NAME ?= capi-test
61+
5962
# image name used to build the cmd/capibmadm
6063
TOOLCHAIN_IMAGE := toolchain
6164

@@ -548,3 +551,18 @@ clean-release: ## Remove the release folder
548551
.PHONY: clean-generated-conversions
549552
clean-generated-conversions: ## Remove files generated by conversion-gen from the mentioned dirs
550553
(IFS=','; for i in $(SRC_DIRS); do find $$i -type f -name 'zz_generated.conversion*' -exec rm -f {} \;; done)
554+
555+
.PHONY: clean-kind
556+
clean-kind: ## Cleans up the kind cluster with the name $CAPI_KIND_CLUSTER_NAME
557+
kind delete cluster --name="$(CAPI_KIND_CLUSTER_NAME)" || true
558+
559+
## --------------------------------------
560+
## Kind
561+
## --------------------------------------
562+
563+
##@ kind:
564+
565+
.PHONY: kind-cluster
566+
kind-cluster: ## Create a new kind cluster designed for development with Tilt
567+
hack/kind-install.sh
568+

docs/book/src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
- [Image Commands](./topics/capibmadm/vpc/image.md)
2828
- [Key Commands](./topics/capibmadm/vpc/key.md)
2929
- [Developer Guide](./developer/index.md)
30+
- [Podman setup for tilt](./developer/tilt-with-podman.md)
3031
- [Rapid iterative development with Tilt](./developer/tilt.md)
3132
- [Guide for API conversions](./developer/conversion.md)
3233
- [Release Process](./developer/release.md)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Podman setup to use tilt
2+
3+
4+
## Prerequisites
5+
6+
1. Install Podman: Instruction can be found [here](https://podman.io/docs/installation)
7+
2. Emulate docker cli with Podman: Instructions can be found [here](https://podman-desktop.io/docs/migrating-from-docker/emulating-docker-cli-with-podman)
8+
9+
## 1. Create Podman machine
10+
11+
```shell
12+
$ podman machine init
13+
$ podman machine start
14+
```
15+
16+
## 2. Configure podman to use local registry
17+
18+
```shell
19+
$ podman machine ssh
20+
$ sudo vi /etc/containers/registries.conf
21+
22+
## at the end of the file add below content
23+
24+
[[registry]]
25+
location = "localhost:5001"
26+
insecure = true
27+
```
28+
Restart Podman machine
29+
30+
```shell
31+
podman machine stop
32+
podman machine start
33+
```
34+
35+
## 3. Create a kind cluster
36+
37+
```shell
38+
$ make kind-cluster
39+
```

hack/kind-install.sh

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#!/bin/sh
2+
3+
# Copyright 2023 The Kubernetes Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -o errexit
18+
set -o nounset
19+
set -o pipefail
20+
21+
KIND_CLUSTER_NAME=${CAPI_KIND_CLUSTER_NAME:-"capi-test"}
22+
23+
24+
# 1. If kind cluster already exists exit.
25+
if [[ "$(kind get clusters)" =~ .*"${KIND_CLUSTER_NAME}".* ]]; then
26+
echo "kind cluster already exists, moving on"
27+
exit 0
28+
fi
29+
30+
31+
32+
# 2. Create registry container unless it already exists
33+
reg_name='kind-registry'
34+
reg_port='5001'
35+
if [ "$(docker inspect -f '{{.State.Running}}' "${reg_name}" 2>/dev/null || true)" != 'true' ]; then
36+
docker run \
37+
-d --restart=always -p "127.0.0.1:${reg_port}:5000" --name "${reg_name}" \
38+
registry:2
39+
fi
40+
41+
# 3. Create kind cluster with containerd registry config dir enabled
42+
# TODO: kind will eventually enable this by default and this patch will
43+
# be unnecessary.
44+
#
45+
# See:
46+
# https://github.com/kubernetes-sigs/kind/issues/2875
47+
# https://github.com/containerd/containerd/blob/main/docs/cri/config.md#registry-configuration
48+
# See: https://github.com/containerd/containerd/blob/main/docs/hosts.md
49+
cat <<EOF | kind create cluster --name="$KIND_CLUSTER_NAME" --config=-
50+
kind: Cluster
51+
apiVersion: kind.x-k8s.io/v1alpha4
52+
nodes:
53+
- role: control-plane
54+
- role: worker
55+
containerdConfigPatches:
56+
- |-
57+
[plugins."io.containerd.grpc.v1.cri".registry]
58+
config_path = "/etc/containerd/certs.d"
59+
EOF
60+
61+
# 4. Add the registry config to the nodes
62+
#
63+
# This is necessary because localhost resolves to loopback addresses that are
64+
# network-namespace local.
65+
# In other words: localhost in the container is not localhost on the host.
66+
#
67+
# We want a consistent name that works from both ends, so we tell containerd to
68+
# alias localhost:${reg_port} to the registry container when pulling images
69+
REGISTRY_DIR="/etc/containerd/certs.d/localhost:${reg_port}"
70+
for node in $(kind get nodes --name "$KIND_CLUSTER_NAME"); do
71+
docker exec "${node}" mkdir -p "${REGISTRY_DIR}"
72+
cat <<EOF | docker exec -i "${node}" cp /dev/stdin "${REGISTRY_DIR}/hosts.toml"
73+
[host."http://${reg_name}:5000"]
74+
EOF
75+
done
76+
77+
# 5. Connect the registry to the cluster network if not already connected
78+
# This allows kind to bootstrap the network but ensures they're on the same network
79+
if [ "$(docker inspect -f='{{json .NetworkSettings.Networks.kind}}' "${reg_name}")" = 'null' ]; then
80+
docker network connect "kind" "${reg_name}"
81+
fi
82+
83+
# 5. Document the local registry
84+
# https://github.com/kubernetes/enhancements/tree/master/keps/sig-cluster-lifecycle/generic/1755-communicating-a-local-registry
85+
cat <<EOF | kubectl apply -f -
86+
apiVersion: v1
87+
kind: ConfigMap
88+
metadata:
89+
name: local-registry-hosting
90+
namespace: kube-public
91+
data:
92+
localRegistryHosting.v1: |
93+
host: "localhost:${reg_port}"
94+
help: "https://kind.sigs.k8s.io/docs/user/local-registry/"
95+
EOF

0 commit comments

Comments
 (0)