This repo use git submodules, so you need know how manipulate them.
Submodules allow you to keep a Git repository as a subdirectory of another Git repository. This lets you clone another repository into your project and keep your commits separate.
https://git-scm.com/book/en/v2/Git-Tools-Submodules
Submodule(s) used in this repository have been added just likes the following example:
Submodules properties are stored at repo's root dir into a file named: .gitmodules
Example:
Submodules need to be initialized when you clone a repo. Use following command in order to initialize submodules of this repository.
git submodule update \
--init \
--recursive
Output:
Read documentation here: https://github.com/OuestFrance-Multimedia/doe-tool-bash-k8s-lab
Use following command in order to install k8s lab's tools.
make -f modules/doe-tool-bash-k8s-lab/Makefile install
Generate .env file just as explain here: https://github.com/OuestFrance-Multimedia/doe-tool-bash-k8s-lab#prerequisite
Example for .env file:
KIND_CLUSTER_NAME=demo
cat << EOF > .env
KIND_CLUSTER_NAME=$KIND_CLUSTER_NAME
KIND_CLUSTER_IMAGE=kindest/node:v1.19.7
KUBE_CONTEXT=kind-${KIND_CLUSTER_NAME}
NETWORK_PREFIX=143.25
METALLB_SPEAKER_SECRET_VALUE=$(openssl rand -base64 256|tr -d '\n')
EOF
Generate kind-config.yaml file just as explain here: https://github.com/OuestFrance-Multimedia/doe-tool-bash-k8s-lab#configuration
Example for kind-config.yaml file:
cat << EOF > kind-config.yaml
---
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: worker
EOF
.env and kind-config.yaml are used by submodule: doe-tool-bash-k8s-lab, so we need symbolic links.
Use following command in order to create required symbolic links:
make create-symbolic-links
We can check symbolic links and contents
In order to create a kubernetes cluster thanks kind, we need :
- create a docker network with: subnet, gateway etc
- create a kubernetes cluster
- deploy a container resource metrics - Metrics Server
- deploy a Load Balancer implementation - MetalLB
- deploy a Ingress controller - Nginx Ingress Controller
make create-docker-network
We can inspect our network ...
make create-kind
We will show the following output
We can list running containers
We can show 2 containers :
- demo-control-plane: which represents a master node and deliver API server used by kubectl or lens. In this example, we can see than API server is exposed locally (127.0.0.1) on port 38841.
- demo-worker: which represents a worker node in a kubernetes cluster. Worker node(s) will host our apps.
Now we can consume API Server of kubernetes with kubectl or lens.
And we use crictl in order to list containers hosted in our worker node.
Deploy a container resource metrics - Metrics Server
make deploy-metrics-server
Following output can be viewed when finished.
Deploy a Load Balancer implementation - MetalLB
make deploy-metallb
Following output can be viewed when finished.
Deploy a Ingress controller - Nginx Ingress Controller
make deploy-nginx-ingress-controller
Output ...
Use following command in order to destroy cluster.
make destroy-cluster
Output ...
You can create: docker network, KIND and deploy Metrics Server, MetalLB and Nginx Ingress Controller in one step:
make create-cluster
Syntax:
git submodule add \
--branch master \
git@${HOST}:${GROUP}/${PATH}/${TEAM}/content-app-${APP}.git \
modules/content-app-${APP}
Example:
git submodule add \
--branch demo \
https://github.com/OuestFrance-Multimedia/doe-scaffold-content-app.git \
modules/content-app-demo
Syntax:
git submodule add \
--branch unrestricted \
git@${HOST}:${GROUP}/${PATH}/${TEAM}/platform-configuration-helm-${APP}.git \
modules/platform-configuration-helm-${APP}
Example:
git submodule add \
--branch demo \
https://github.com/OuestFrance-Multimedia/doe-scaffold-platform-configuration-helm.git \
modules/platform-configuration-helm-demo
Use following command in order to create your App env's file.
Example:
cat << EOF > demo.env
APP=demo
EOF
Somes predefined variables are defined into file: common.env
Theses variables are used during build & deploy steps.
var | definition | more | example |
---|---|---|---|
KIND_NODES | nodes that will accommodate pods | substract from nodes list control-planes | kind get nodes --name ${KIND_CLUSTER_NAME} |
DOCKER_BUILD_REPOSITORY | container repository | the choice is arbitrary and predictable (image will be pushed into kind registry) | docker.io/ofm/${APP}${APP_SUFFIX:+-$APP_SUFFIX} |
DOCKER_BUILD_TAG | container tag | the choice is arbitrary and predictable (image will be pushed into kind registry) | ((git ls-files -o --exclude-standard -z | xargs -r0 cat) && git rev-parse --verify HEAD && git diff --patch-with-raw |
DOCKER_BUILD_CONTEXT | build context | this field is predictable | $(pwd)/modules/content-app-$APP |
DOCKER_BUILD_DOCKERFILE | dockerfile | this field is predictable | $(pwd)/modules/content-app-$APP/build/Dockerfile |
HELM_NAMESPACE | namespace that will accommodate pods | this field is predictable | ${APP}${APP_SUFFIX:+-$APP_SUFFIX} |
HELM_RELEASE | helm release | this field is predictable | ${KIND_CLUSTER_NAME}-${APP}${APP_SUFFIX:+-$APP_SUFFIX} |
HELM_CHART | helm chart | this field is predictable | $(pwd)/modules/platform-configuration-helm-$APP |
HELM_VALUES_01 | helm values file (common for each env) | this field is predictable | $(pwd)/modules/platform-configuration-helm-$APP/values.yaml |
HELM_VALUES_02 | helm values file | this field is predictable | $(pwd)/modules/platform-configuration-helm-$APP/values-kind${APP_SUFFIX:+-$APP_SUFFIX}.yaml |
HELM_SET_01 | helm set value for image.repository | this field is predictable | "image.repository=$DOCKER_BUILD_REPOSITORY" |
HELM_SET_02 | helm set value for image.tag | this field is predictable | "image.tag=$DOCKER_BUILD_TAG" |
Build Process will Build images with BuildKit
You can add arguments or secrets into your App env's file
You can use 20 arguments in following range: [01-20]
Example:
DOCKER_BUILD_ARG_01="ENV=prod"
DOCKER_BUILD_ARG_02="APP_ENV=prod"
You can use 20 secrets in following range: [01-20]
Example:
DOCKER_BUILD_SECRET_01="id=github_token,src=/home/foo/secrets/composer_github_personal_access_token.json"
This example allows the user to pass secret information to be used in the Dockerfile for building docker images in a safe way that will not end up stored in the final image.
You can add yaml files or set parameters into your App env's file
Example:
HELM_VALUES_03=$(pwd)/modules/platform-configuration-helm-$APP/values-foo.yaml
Example:
HELM_SET_03="image.pullPolicy=Never"