Add additional localkube-dind docker image.

pull/1750/head
Aaron Prindle 2017-06-12 12:03:21 -07:00
parent 4fd5f4797b
commit 20f99fc500
6 changed files with 268 additions and 0 deletions

View File

@ -229,6 +229,20 @@ localkube-image: out/localkube
@echo "${REGISTRY}/localkube-image:$(TAG) succesfully built"
@echo "See https://github.com/kubernetes/minikube/tree/master/deploy/docker for instructions on how to run image"
localkube-dind-image: out/localkube
# TODO(aprindle) make addons placed into container configurable
docker build -t $(REGISTRY)/localkube-dind-image:$(TAG) -f deploy/docker/localkube-dind/Dockerfile .
@echo ""
@echo "${REGISTRY}/localkube-dind-image:$(TAG) succesfully built"
@echo "See https://github.com/kubernetes/minikube/tree/master/deploy/docker for instructions on how to run image"
localkube-dind-image-devshell: out/localkube
# TODO(aprindle) make addons placed into container configurable
docker build -t $(REGISTRY)/localkube-dind-image-devshell:$(TAG) -f deploy/docker/localkube-dind/Dockerfile .
@echo ""
@echo "${REGISTRY}/localkube-dind-image-devshell:$(TAG) succesfully built"
@echo "See https://github.com/kubernetes/minikube/tree/master/deploy/docker for instructions on how to run image"
buildroot-image: $(ISO_BUILD_IMAGE) # convenient alias to build the docker container
$(ISO_BUILD_IMAGE): deploy/iso/minikube-iso/Dockerfile
docker build $(ISO_DOCKER_EXTRA_ARGS) -t $@ -f $< $(dir $<)

View File

@ -0,0 +1,70 @@
# Copyright 2016 The Kubernetes Authors All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
FROM debian:jessie
ARG CNI_VERSION=v0.5.2
ENV ARCH amd64
RUN DEBIAN_FRONTEND=noninteractive apt-get update -y \
&& DEBIAN_FRONTEND=noninteractive apt-get -yy -q install \
iptables \
ebtables \
ethtool \
ca-certificates \
conntrack \
util-linux \
socat \
git \
nfs-common \
glusterfs-client \
cifs-utils \
apt-transport-https \
ca-certificates \
curl \
gnupg2 \
software-properties-common \
bridge-utils \
ipcalc \
&& DEBIAN_FRONTEND=noninteractive apt-get upgrade -y \
&& DEBIAN_FRONTEND=noninteractive apt-get autoremove -y \
&& DEBIAN_FRONTEND=noninteractive apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN mkdir -p /etc/cni/net.d && \
mkdir -p /opt/cni/bin && \
curl -sSL --retry 5 https://github.com/containernetworking/cni/releases/download/${CNI_VERSION}/cni-${ARCH}-${CNI_VERSION}.tgz | \
tar -C /opt/cni/bin -xz
# Install docker
RUN curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -
RUN add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/debian \
$(lsb_release -cs) \
stable"
RUN apt-get update && apt-get install -yy -q docker-ce
# Copy over important files
COPY out/localkube /localkube
COPY deploy/docker/localkube-dind/start.sh /start.sh
COPY deploy/docker/localkube-dind/dindnet /dindnet
COPY deploy/addons/addon-manager.yaml /etc/kubernetes/manifests/addon-manager.yaml
COPY deploy/addons/dashboard /etc/kubernetes/addons
COPY deploy/addons/kube-dns /etc/kubernetes/addons
RUN chmod +x /localkube
RUN chmod +x /start.sh
RUN chmod +x /dindnet
CMD /start.sh

View File

@ -0,0 +1,30 @@
### Run localkube in a docker container (experimental)
**Warning:** This is experimental code at the moment.
#### How to build
From root minikube/ directory run:
```console
$ make localkube-image #optional env-vars: TAG=LOCALKUBE_VERSION REGISTRY=gcr.io/k8s-minikube
```
#### How to run
##### Linux
```console
$ docker run -it \
--privileged \
-p 127.0.0.1:8080:8080 \
-v /boot:/boot \
-v /lib/modules:/lib/modules \
gcr.io/k8s-minikube/localkube-image:v1.7.0 \
/start.sh
```
Then to setup `kubectl` to use this cluster:
```console
kubectl config set-cluster localkube-image --server=http://127.0.0.1:8080 --api-version=v1
kubectl config set-context localkube-image --cluster=localkube-image
kubectl config use-context localkube-image
```
Now `kubectl` should be configured to properly access your local k8s environment

View File

@ -0,0 +1,98 @@
#!/bin/bash
# Copyright 2016 The Kubernetes Authors All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -o errexit
set -o nounset
set -o pipefail
set -o errtrace
IP_CIDR=$(ip addr show eth0 | grep -w inet | awk '{ print $2; }')
IP=$(echo $IP_CIDR | sed 's,/.*,,')
function dind::setup-bridge {
# create dind0 bridge and attach it to the veth interface eth0
brctl addbr dind0
brctl addif dind0 eth0
ip link set dind0 up
# move ip to the bridge and restore routing via the old gateway
NETWORK_SIZE=$(echo $IP_CIDR | sed 's,.*/,,')
DEFAULT_ROUTE=$(ip route | grep default | sed 's/eth0/dind0/')
DEFAULT_GW=$(echo $DEFAULT_ROUTE|awk '{print $3;}')
ip addr del $IP_CIDR dev eth0
ip addr add $IP_CIDR dev dind0
ip route add $DEFAULT_ROUTE
# compute a network for the containers to live in
# by adding CNI_BRIDGE_NETWORK_OFFSET to the current IP and cutting off
# non-network bits according to CNI_BRIDGE_NETWORK_SIZE
CNI_BRIDGE_NETWORK_SIZE=${CNI_BRIDGE_NETWORK_SIZE:-24}
NETWORK=$(ip route | grep dind0 | grep -v default | sed 's,/.*,,')
WILDCARD=$(ipcalc $IP_CIDR | grep Wildcard | awk '{print $2;}')
IFS=. read -r i1 i2 i3 i4 <<< ${IP}
IFS=. read -r n1 n2 n3 n4 <<< ${NETWORK}
IFS=. read -r o1 o2 o3 o4 <<< ${CNI_BRIDGE_NETWORK_OFFSET}
IFS=. read -r w1 w2 w3 w4 <<< ${WILDCARD}
IP_PLUS_OFFSET=$(printf "%d.%d.%d.%d\n" \
"$(( n1 + ((i1 - n1 + o1) & w1) ))" \
"$(( n2 + ((i2 - n2 + o2) & w2) ))" \
"$(( n3 + ((i3 - n3 + o3) & w3) ))" \
"$(( n4 + ((i4 - n4 + o4) & w4) ))")
HOST_MIN=$(ipcalc $IP_PLUS_OFFSET/$CNI_BRIDGE_NETWORK_SIZE | grep HostMin | awk '{print $2;}')
HOST_MAX=$(ipcalc $IP_PLUS_OFFSET/$CNI_BRIDGE_NETWORK_SIZE | grep HostMax | awk '{print $2;}')
echo "Using ${HOST_MIN} .. ${HOST_MAX} for docker containers"
cat >/etc/cni/net.d/cni.conf <<EOF
{
"name": "dindnet",
"type": "bridge",
"bridge": "dind0",
"ipam": {
"type": "host-local",
"subnet": "${NETWORK}/${NETWORK_SIZE}",
"rangeStart": "${HOST_MIN}",
"rangeEnd": "${HOST_MAX}",
"gateway": "${DEFAULT_GW}",
"routes": [
{ "dst": "0.0.0.0/0" }
]
}
}
EOF
}
if [[ "${CNI_BRIDGE_NETWORK_OFFSET:-}" ]]; then
dind::setup-bridge
fi
# make docker's kube-dns friendly
old_ns="$(awk '/^nameserver/ {print $2; exit}' /etc/resolv.conf)"
if [[ ${old_ns} ]]; then
# sed -i doesn't work here because of docker's handling of /etc/resolv.conf
sed "s/^nameserver.*/nameserver ${IP}/" /etc/resolv.conf >/etc/resolv.conf.updated
cat /etc/resolv.conf.updated >/etc/resolv.conf
# rm /tmp/resolv.conf.updated
while true; do
socat udp4-recvfrom:53,reuseaddr,fork,bind=${IP} UDP:${old_ns}:53 || true
echo "WARNING: restarting socat" >&2
done
else
echo "WARNING: couldn't get nameserver" >&2
exit 1
fi

View File

@ -0,0 +1,43 @@
#!/bin/bash
# Copyright 2016 The Kubernetes Authors All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
mount --make-shared /
export CNI_BRIDGE_NETWORK_OFFSET="0.0.1.0"
/dindnet &> /dev/null &
mkdir -p /etc/localkube
base=/etc/localkube/docker
/usr/bin/dockerd \
--exec-root=$base.exec \
--graph=$base.graph \
--host=unix://$base.socket \
--pidfile=$base.pid &> /dev/null &
mkdir -p /etc/kubernetes/manifests
/localkube start \
--apiserver-insecure-address=0.0.0.0 \
--apiserver-insecure-port=8080 \
--network-plugin=cni \
--extra-config=kubelet.DockerEndpoint=unix:///$base.socket \
--extra-config=kubelet.KubeletFlags.ContainerRuntimeOptions.CNIConfDir="/etc/cni/net.d" \
--extra-config=kubelet.KubeletFlags.ContainerRuntimeOptions.CNIBinDir="/opt/cni/bin" \
--extra-config=kubelet.ClusterDNS="10.96.0.10" \
--extra-config=kubelet.ClusterDomain="cluster.local" \
--extra-config=kubelet.AllowPrivileged="true"

View File

@ -56,3 +56,16 @@ gsutil cp out/minikube_${DEB_VERSION}.deb gs://$BUCKET/releases/$TAGNAME/
# Bump latest
gsutil cp -r gs://$BUCKET/releases/$TAGNAME/* gs://$BUCKET/releases/latest/
# Build and upload localkube containers
make localkube-image
TAG="$(docker images "gcr.io/k8s-minikube/localkube-image" --format="{{.Tag}}" | head -n 1)"
gcloud docker -- push gcr.io/k8s-minikube/localkube-image:$TAG
make localkube-dind-image
TAG="$(docker images "gcr.io/k8s-minikube/localkube-dind-image" --format="{{.Tag}}" | head -n 1)"
gcloud docker -- push gcr.io/k8s-minikube/localkube-dind-image:$TAG
make localkube-dind-image-devshell
TAG="$(docker images "gcr.io/k8s-minikube/localkube-dind-image-devshell" --format="{{.Tag}}" | head -n 1)"
gcloud docker -- push gcr.io/k8s-minikube/localkube-dind-image-devshell:$TAG