Last active
March 25, 2024 19:06
Expose Kind docker daemon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
apiVersion: apps/v1 | |
kind: Deployment | |
metadata: | |
name: docker-proxy | |
namespace: kube-system | |
labels: | |
app: docker-proxy | |
spec: | |
selector: | |
matchLabels: | |
app: docker-proxy | |
template: | |
metadata: | |
labels: | |
app: docker-proxy | |
spec: | |
containers: | |
- image: alpine/socat | |
name: docker-proxy | |
args: | |
- -d | |
- -d | |
- TCP-L:2375,fork | |
- UNIX:/var/run/docker.sock | |
resources: | |
limits: | |
cpu: 20m | |
memory: 100Mi | |
requests: | |
cpu: 10m | |
memory: 50Mi | |
ports: | |
- name: http | |
containerPort: 2375 | |
volumeMounts: | |
- name: docker-sock | |
mountPath: /var/run/docker.sock | |
volumes: | |
- name: docker-sock | |
hostPath: | |
path: /var/run/docker.sock | |
--- | |
apiVersion: v1 | |
kind: Service | |
metadata: | |
name: docker-proxy | |
namespace: kube-system | |
labels: | |
app: docker-proxy | |
spec: | |
ports: | |
- port: 2375 | |
targetPort: 2375 | |
name: http | |
selector: | |
app: docker-proxy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
if [ -z $KIND_CLUSTER ]; then | |
echo "Please set KIND_CLUSTER in environment" | |
exit 1 | |
fi | |
if [ ! -f ~/.kube/kind-config-$KIND_CLUSTER ]; then | |
echo "No Kind cluster found for name $KIND_CLUSTER" | |
exit 1 | |
fi | |
if [ ! -x $(which yq) ]; then | |
echo "No yq installed, please `pip install yq`" | |
exit 1 | |
fi | |
mkdir -p ~/.kube/certs/kind-$KIND_CLUSTER | |
yq -r '.users[].user."client-certificate-data"' ~/.kube/kind-config-$KIND_CLUSTER | base64 --decode > ~/.kube/certs/kind-$KIND_CLUSTER/cert.pem | |
yq -r '.users[].user."client-key-data"' ~/.kube/kind-config-$KIND_CLUSTER | base64 --decode > ~/.kube/certs/kind-$KIND_CLUSTER/key.pem | |
yq -r '.clusters[].cluster."certificate-authority-data"' ~/.kube/kind-config-$KIND_CLUSTER | base64 --decode > ~/.kube/certs/kind-$KIND_CLUSTER/ca.pem | |
SERVER=$(yq -r '.clusters[].cluster.server' ~/.kube/kind-config-$KIND_CLUSTER | sed -e 's|https://||') | |
echo "# 'eval' the output of this script to set your environment to talk to your Kind cluster" | |
echo "# eval \$(KIND_CLUSTER=<cluster-name> ./kind-environment.sh)" | |
echo "export DOCKER_TLS_VERIFY=\"1\"" | |
echo "export DOCKER_HOST=\"$SERVER/api/v1/namespaces/kube-system/services/docker-proxy:http/proxy\"" | |
echo "export DOCKER_CERT_PATH=~/.kube/certs/kind-$KIND_CLUSTER" | |
echo "export KUBECONFIG=~/.kube/kind-config-$KIND_CLUSTER" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Steps to get a Kind cluster up and running and expose the Docker daemon to your local terminal:
go get sigs.k8s.io/kind
kind create cluster --name <give-your-cluster-a-name>
kind-environment.sh
script:eval $(KIND_CLUSTER=<your_kind_cluster_name> ./kind-environment.sh)
docker-proxy
:kubectl apply -f kind-docker-proxy.yaml
docker-proxy
pod has started and thendocker ps
and you should be pointing at the docker daemon running within your Kind cluster