Skip to content

Commit

Permalink
Add docker run-time for kic driver (#6436)
Browse files Browse the repository at this point in the history
* Add docker container run time for kic
  • Loading branch information
medyagh authored Jan 30, 2020
1 parent eeb867f commit 4bf3fc4
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -494,8 +494,8 @@ storage-provisioner-image: out/storage-provisioner-$(GOARCH) ## Build storage-pr

.PHONY: kic-base-image
kic-base-image: ## builds the base image used for kic.
docker rmi -f $(REGISTRY)/kicbase:v0.0.2-snapshot || true
docker build -f ./hack/images/kicbase.Dockerfile -t $(REGISTRY)/kicbase:v0.0.2-snapshot --build-arg COMMIT_SHA=${VERSION}-$(COMMIT) .
docker rmi -f $(REGISTRY)/kicbase:v0.0.3-snapshot || true
docker build -f ./hack/images/kicbase.Dockerfile -t $(REGISTRY)/kicbase:v0.0.3-snapshot --build-arg COMMIT_SHA=${VERSION}-$(COMMIT) .



Expand Down
3 changes: 2 additions & 1 deletion hack/images/kicbase.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ RUN apt-get update && apt-get install -y \
sudo \
dnsutils \
openssh-server \
docker.io \
&& apt-get clean -y
# based on https://github.com/rastasheep/ubuntu-sshd/blob/master/18.04/Dockerfile
# making SSH work for docker container
Expand All @@ -28,7 +29,7 @@ RUN rm -rf \
/kind/bin/kubeadm /kind/bin/kubelet /kind/systemd /kind/images /kind/manifests
RUN echo "kic! Build: ${COMMIT_SHA} Time :$(date)" > "/kic.txt"
# for minikube ssh. to match VM using docker username
RUN adduser --disabled-password --gecos '' docker
RUN adduser --ingroup docker --disabled-password --gecos '' docker
RUN adduser docker sudo
RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
USER docker
Expand Down
6 changes: 5 additions & 1 deletion pkg/drivers/kic/kic.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const DefaultPodCIDR = "10.244.0.0/16"
const DefaultBindIPV4 = "127.0.0.1"

// BaseImage is the base image is used to spin up kic containers created by kind.
const BaseImage = "gcr.io/k8s-minikube/kicbase:v0.0.2@sha256:8f531b90901721a7bd4e67ceffbbc7ee6c4292b0e6d1a9d6eb59f117d57bc4e9"
const BaseImage = "gcr.io/k8s-minikube/kicbase:v0.0.3@sha256:34db5e30f8830c0d5e49b62f3ea6b2844f805980592fe0084cbea799bfb12664"

// OverlayImage is the cni plugin used for overlay image, created by kind.
const OverlayImage = "kindest/kindnetd:0.5.3"
Expand Down Expand Up @@ -109,6 +109,10 @@ func (d *Driver) Create() error {
ListenAddress: DefaultBindIPV4,
ContainerPort: constants.SSHPort,
},
oci.PortMapping{
ListenAddress: DefaultBindIPV4,
ContainerPort: constants.DockerDaemonPort,
},
)
_, err := node.CreateNode(params)
if err != nil {
Expand Down
26 changes: 20 additions & 6 deletions pkg/minikube/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ import (
"github.com/shirou/gopsutil/mem"
"github.com/spf13/viper"

"k8s.io/minikube/pkg/drivers/kic"
"k8s.io/minikube/pkg/drivers/kic/oci"
"k8s.io/minikube/pkg/minikube/command"
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/constants"
Expand Down Expand Up @@ -534,21 +536,33 @@ func createHost(api libmachine.API, cfg config.MachineConfig) (*host.Host, error

// GetHostDockerEnv gets the necessary docker env variables to allow the use of docker through minikube's vm
func GetHostDockerEnv(api libmachine.API) (map[string]string, error) {
host, err := CheckIfHostExistsAndLoad(api, viper.GetString(config.MachineProfile))
pName := viper.GetString(config.MachineProfile)
host, err := CheckIfHostExistsAndLoad(api, pName)
if err != nil {
return nil, errors.Wrap(err, "Error checking that api exists and loading it")
}
ip, err := host.Driver.GetIP()
if err != nil {
return nil, errors.Wrap(err, "Error getting ip from host")

ip := kic.DefaultBindIPV4
if !driver.IsKIC(host.Driver.DriverName()) { // kic externally accessible ip is different that node ip
ip, err = host.Driver.GetIP()
if err != nil {
return nil, errors.Wrap(err, "Error getting ip from host")
}

}

tcpPrefix := "tcp://"
port := "2376"
port := constants.DockerDaemonPort
if driver.IsKIC(host.Driver.DriverName()) { // for kic we need to find out what port docker allocated during creation
port, err = oci.HostPortBinding(host.Driver.DriverName(), pName, constants.DockerDaemonPort)
if err != nil {
return nil, errors.Wrapf(err, "get hostbind port for %d", constants.DockerDaemonPort)
}
}

envMap := map[string]string{
"DOCKER_TLS_VERIFY": "1",
"DOCKER_HOST": tcpPrefix + net.JoinHostPort(ip, port),
"DOCKER_HOST": tcpPrefix + net.JoinHostPort(ip, fmt.Sprint(port)),
"DOCKER_CERT_PATH": localpath.MakeMiniPath("certs"),
}
return envMap, nil
Expand Down
2 changes: 2 additions & 0 deletions pkg/minikube/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (
)

const (
// DockerDaemonPort is the port Docker daemon listening inside a minikube node (vm or container).
DockerDaemonPort = 2376
// SSHPort is the SSH serviceport on the node vm and container
SSHPort = 22
// APIServerPort is the default API server port
Expand Down
1 change: 0 additions & 1 deletion pkg/minikube/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ func FlagDefaults(name string) FlagHints {
fh.CacheImages = true
// only for kic, till other run-times are available we auto-set containerd.
if name == Docker {
fh.ContainerRuntime = "containerd"
fh.ExtraOptions = append(fh.ExtraOptions, fmt.Sprintf("kubeadm.pod-network-cidr=%s", kic.DefaultPodCIDR))
}
return fh
Expand Down

0 comments on commit 4bf3fc4

Please sign in to comment.