Fork this project by clicking https://gitlab.com/DmyMi/k8s-simple-task/-/forks/new
Follow this article https://nira.com/how-to-migrate-from-gitlab-to-github/ to copy the project to your Github.
Doing the lab requires you to know how to use Git :)
- Install Docker by following this link: Docker Install
- Install MicroK8S
- Enable MicroK8s addons:
# You need to provide a valid IP range in your local network.
# Can be as few as 1, but better to have some to spare
# Following IP range is for an example.
microk8s enable dns registry metallb:192.168.0.10-192.168.0.20
- Configure insecure registry access for Docker as described in this dockumentation
- Install Docker by following this link: Docker Install
- Install K3S
curl -sfL https://get.k3s.io | sh -s - --write-kubeconfig-mode 644
- You should already have Docker for Mac
- Install kubectl
- You should already have Docker for Windows
- Install kubectl
- Clone the repository
git clone https://gitlab.com/DmyMi/k8s-simple-task.git
- Change to directory
cd k8s-simple-task
- Apply already provided manifests
# Ubuntu
microk8s kubectl apply -f ./k8s
# Centos
k3s kubectl apply -f ./k8s
# Mac & Windows
kubectl apply -f ./k8s
- Wait up to 5 minutes (depending on your internet and pc it might take some time to start) and check if everything is working. In the terminal write:
# I will simply write kubectl, you need a prefix for your environment
kubectl port-forward svc/backend 8080:8080
Leave this terminal working, and OPEN A NEW TERMINAL (or use your browser). In new terminal run:
curl http://localhost:8080/api/books
If everything is fine yo should see a list of books.
First, write a Docker file for express-fe
application.
Create account on Docker Hub. Go to Security and create a new access token. Follow the instructions to login your Docker to Docker Hub.
Note: Make sure you save the token if you will do the Jenkins part
Tag the image with your docker hub repository, e.g. dmytro/express-fe
. Example
Write a frontend-deployment.yaml
. Remember that express-fe
needs some environment variables set. Check its readme. Example
Write a frontend-service.yaml
. For Ubuntu it can be LoadBalancer
, for others - NodePort
. Example
Apply these manifests and try to check if the Express works.
kubectl apply -f ./k8s
# Get the services
kubectl get svc
For Ubuntu check loadbalancer ip and visit it, for example: 192.168.0.10:3000/api-docs
For other OS, check node port and visit it, for example: localhost:32758/api-docs
You need to have a local K8s Cluster created (using Docker for Desktop, Microk8s, k3s, etc.). You need to have kubectl
installed (not covered here).
cd jenkins
./deploy.sh
# Wait 5 minutes
export SERVICE_IP=$(kubectl get svc --namespace jenkins jenkins --template "{{ range (index .status.loadBalancer.ingress 0) }}{{ . }}{{ end }}")
echo http://$SERVICE_IP:80/login
Running previous commands ill create a playground with Jenkins Controller configured using Jenkins Configuration as Code with access to K8S cluster.
Login: admin
Password: verysecret
After creating Jenkins deployment - create DockerHub credentials secret using the dockerconfig.sh
script.
./dockerconfig.sh -u "vasya" -p "your-dockerhub-token-or-password"
Write missing pieces of Jenkinsfile. Mainly:
- "testing" the application
- Deploying the application
- Testing the deployment using curl :)
kubectl delete -f ./k8s
kubectl delete ns jenkins
All i need is a link to your Github/Gitlab project in Classroom.