Before going thorugh configuration and build of kubernetes packages, we should install minikube or Kubernetes. My primary goal was to try Kubernetes on VMs the simplest way. I have chosen minimal version of k8s called minikube and used a Virtualbox VM with Ubuntu 18.04. minikube creates a single-node cluster.
There is a problem with minikube on VirtualBox VM: minikube uses VirtualBox hypervisor for virtualization and thus requires VT-X support on host. However VirtualBox doesn’t support VT-X/AMD-v. That could be solved by using vm-driver=none option and Docker on host.
Install Minikube
$ curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 && chmod +x minikube
$ sudo mkdir -p /usr/local/bin/
$ sudo install minikube /usr/local/bin/
$ minikube start
$ minikube status
you can follow the official link as well: https://kubernetes.io/docs/tasks/tools/install-minikube/
To start minikube in none driver mode to solve hypervisor issue you cal force to start it with below command:
sudo minikube start --vm-driver=none
Assume we have an application compose of 2 layer of frontend and backend. Therefore, before make the entire application into a single package, we will start to containarize the each layer by creating proper Dockerfile for each frontend and backend.
Then your environment would be like this:
No it is turn to build your images and push to proper hub. if you are a bash user you can make both in once user this command:
#!/usr/bin/env bash
set -e
OWNER="<Yor Hub's path>"
BASE_NAME="<Application name>"
PACKAGES=( "backoffice" "frontend" )
version=<Specify tag or leave latest>
package=
usage() {
cat <<EOF
usage: ./build.sh [--version <version> | -v <version>] [--package <package> | -p <package>] [--help | -h]
Build <Application name> project
Options:
-v, --version string Set the build version for the Docker images
-p, --package string Build only single package. If this option is not provided, build all packages
-h, --help Print help message
EOF
}
build() {
echo "---> Start building ${OWNER}/${BASE_NAME}-${package}:${version}"
docker build "${package}" -t "${OWNER}/${BASE_NAME}-${package}:${version}" || {
echo "---> Failed building ${OWNER}/${BASE_NAME}-${package}:${version}"
exit 1
}
echo "---> Done building ${OWNER}/${BASE_NAME}-${package}:${version}"
}
while [ "$1" != "" ]; do
case $1 in
-v | --version ) shift
version=$1
;;
-p | --package ) shift
package=$1
;;
-h | --help ) usage
exit
;;
* ) usage
exit 1
esac
shift
done
if [ -z "${package}" ]; then
for package in "${PACKAGES[@]}"
do
build
done
else
build
fi
This bash script will build the image and store it locally, you need o push it in your container repository hub. If you are using aws registry account easily follow belows:
eval $(aws ecr get-login --no-include-email) && \
docker push <Yor registry's path>/backoffice:<tag> && \
docker push <Yor registry's path>/frontend:<tag> # && \
Since the containers are ready, let’s create and run kubernetes deployment and services: Before that make sure your minikube is running properly:
minikube status
We need to prepare deployment config file and run it for each layer separately, So we start from frontend: You run below command to generate the deployment file for frontend automaticaly and easy:
kubectl run frontend --image=<Yor registry's path>/frontend:<tag> --image-pull-policy=IfNotPresent -o yaml > manifests/frontend-deployment.yaml
Now we need to run services and generate config file as well (make sure the port defined based on dockerfile):
kubectl expose deployment frontend --port=8080 --type=NodePort -o yaml > manifests/frontend-service.yaml
if you run ( kubectl get pod && kubectl get service
) you can see the pod and service for frontend are ready and running and by checking the config files in manifests folder ( ls manifests
) the configuration files also generated as well.
So it it time to prapre backend environment, therefore we need to do the same for that:
kubectl run backend --image=<Yor registry's path>/backend:<tag> --image-pull-policy=IfNotPresent -o yaml > manifests/backend-deployment.yaml
Now we need to run services and generate config file as well (make sure the port defined based on dockerfile):
kubectl expose deployment backend --port=5000 --type=NodePort -o yaml > manifests/backend-service.yaml
if you run ( kubectl get pod && kubectl get service
) you can see the pod and service for backend are ready and running and by checking the config files in manifests folder ( ls manifests
) the configuration files also generated as well.
Your k8s environment is ready to use, you can easily work on config files and folders to maachive what exactly you are looking for.
good luck