Skip to content

Commit

Permalink
Add get-kubeconfig script that will wait for, then cat kubeconfig.
Browse files Browse the repository at this point in the history
Useful with docker exec to get the fully formed kubeconfig
  • Loading branch information
mvachhar committed May 20, 2019
1 parent f8f32bf commit 63fea6b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ ENV K3S_VERSION=v0.5.0
EXPOSE 8443

ADD https://github.com/rancher/k3s/releases/download/${K3S_VERSION}/k3s /usr/local/bin/k3s
COPY kubectl start-k3s.sh /usr/local/bin/
COPY kubectl start-k3s.sh get-kubeconfig.sh /usr/local/bin/

# Note: the k3s kubectl command unpacks the k3s binaries as a side effect
RUN apk --no-cache add bash && \
chmod a+x \
/usr/local/bin/k3s \
/usr/local/bin/start-k3s.sh \
/usr/local/bin/get-kubeconfig.sh \
/usr/local/bin/kubectl \
&& \
k3s kubectl --help > /dev/null
Expand Down
19 changes: 19 additions & 0 deletions get-kubeconfig.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

while [ ! -f /kubeconfig ]; do
sleep 1
done

if [ "$1" = "-json" ]; then
cfg=$(kubectl config view -o json --merge=true --flatten=true)
else
cfg=$(kubectl config view -o yaml --merge=true --flatten=true)
fi

if [ -z "$2" ]; then
hostname="localhost"
else
hostname="$2"
fi

echo "$cfg" | sed -e "s/0\.0\.0\.0/$hostname/g"
3 changes: 2 additions & 1 deletion start-k3s.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ function waitForKubeconfig {
cfg=$(getKubeconfig)
done

echo "${cfg}" > /kubeconfig
echo "${cfg}" > /tmp/kubeconfig
mv /tmp/kubeconfig /kubeconfig
}


Expand Down

0 comments on commit 63fea6b

Please sign in to comment.