Skip to content

Instantly share code, notes, and snippets.

@misskecupbung
Last active November 15, 2021 04:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save misskecupbung/ea2eb5ead021b10426f3658195cd73a4 to your computer and use it in GitHub Desktop.
Save misskecupbung/ea2eb5ead021b10426f3658195cd73a4 to your computer and use it in GitHub Desktop.

This is a simple guide to get started with BuildKit using Minikube

Requirements:

  • Internet Connections
  • Virtual Machine
  • Package: curl, wget, git, apt-transport-https

Install Minikube

sudo apt-get install curl apt-transport-https wget curl git docker.io -y
sudo systemctl start docker
sudo systemctl status docker
sudo usermod -aG docker ubuntu

wget https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo cp minikube-linux-amd64 /usr/local/bin/minikube
sudo chmod 755 /usr/local/bin/minikube
minikube version

Install k8s with minikube

curl -LO https://storage.googleapis.com/kubernetes-release/release/`\
curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl

minikube start --cpus 4 --memory 8192 --driver=docker --container-runtime=containerd
kubectl get nodes

Build with Docker

git clone https://github.com/misskecupbung/nginx-helloworld
cd ~/nginx-helloworld/
docker build -t nginx-hello .

BuildKit Installation

wget -c https://github.com/moby/buildkit/releases/download/v0.9.2/buildkit-v0.9.2.linux-amd64.tar.gz
tar -xvzf buildkit-v0.9.2.linux-amd64.tar.gz
sudo mv ./bin/buildctl /usr/local/bin/
sudo mv ./bin/buildkitd /usr/local/bin/
sudo vim /etc/systemd/system/buildkitd.service
...
[Unit]
Description=BuildKit Daemon

[Service]
User=root
ExecStart=/usr/local/bin/buildkitd --oci-worker=false --containerd-worker=true

[Install]
WantedBy=default.target
...

sudo systemctl daemon-reload
sudo systemctl start buildkitd
sudo systemctl status buildkitd

BuildKit with buildctl command

cd ~/nginx-helloworld/
sudo buildctl build     \
--frontend=dockerfile.v0     \
--local context=.     \
--local dockerfile=.

BuildKit with Docker

cd ~/nginx-helloworld/
DOCKER_BUILDKIT=1 docker build .

BuildKit with buildx

wget -c https://github.com/docker/buildx/releases/download/v0.7.0/buildx-v0.7.0.linux-amd64
mkdir -p ~/.docker/cli-plugins/
mv buildx-v0.7.0.linux-amd64 ~/.docker/cli-plugins/docker-buildx
chmod +x ~/.docker/cli-plugins/docker-buildx
cd ~/nginx-helloworld/
docker buildx build .

BuildKit with kubectl command

wget -c https://github.com/vmware-tanzu/buildkit-cli-for-kubectl/releases/download/v0.1.4/kubectl-buildkit_0.1.4_amd64.deb
sudo apt install ./kubectl-buildkit*.deb
cd ~/nginx-helloworld/
kubectl build -t nginx-hello .
kubectl build -t nginx-hello:v1 .
kubectl run nginx-hello --image=nginx-hello
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment