Skip to content

Instantly share code, notes, and snippets.

@JoelSpeed
Last active March 25, 2024 19:06
Show Gist options
  • Save JoelSpeed/fccade2a4f4d4181e137def5ca011d38 to your computer and use it in GitHub Desktop.
Save JoelSpeed/fccade2a4f4d4181e137def5ca011d38 to your computer and use it in GitHub Desktop.
Expose Kind docker daemon
---
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
#!/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"
@JoelSpeed
Copy link
Author

JoelSpeed commented Jan 3, 2019

Steps to get a Kind cluster up and running and expose the Docker daemon to your local terminal:

  1. Install Kind: go get sigs.k8s.io/kind
  2. Create a cluster: kind create cluster --name <give-your-cluster-a-name>
  3. Run the kind-environment.sh script: eval $(KIND_CLUSTER=<your_kind_cluster_name> ./kind-environment.sh)
  4. Install the docker-proxy: kubectl apply -f kind-docker-proxy.yaml
  5. Wait until the docker-proxy pod has started and then docker ps and you should be pointing at the docker daemon running within your Kind cluster

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment