docker build -t flask-api-jowett . docker build -t frontend-jowett .
- ingress constroller
- https://kubernetes.github.io/ingress-nginx/deploy/
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.3.0/deploy/static/provider/cloud/deploy.yamlkubectl apply -f .\ingress-service.yaml
minikube -p minikube docker-env --shell powershell | Invoke-Expressionminikube addons enable ingressminikube tunnel
tutorial-env\Scripts\activate.bat
This repo contains code that
- Deploys a MySQL server on a Kubernetes cluster
- Attaches a persistent volume to it, so the data remains contained if pods are restarting
- Deploys a Flask API to add, delete and modify users in the MySQL database
- Have
Dockerand theKubernetes CLI(kubectl) installed together withMinikube(https://kubernetes.io/docs/tasks/tools/)
- Clone the repository
- Configure
Dockerto use theDocker daemonin your kubernetes cluster via your terminal:eval $(minikube docker-env) - Pull the latest mysql image from
Dockerhub:Docker pull mysql - Build a kubernetes-api image with the Dockerfile in this repo:
docker build -t jowettc/flask-api-jowett .
Kubernetes Secrets can store and manage sensitive information. For this example we will define a password for the
root user of the MySQL server using the Opaque secret type. For more info: https://kubernetes.io/docs/concepts/configuration/secret/
- Encode your password in your terminal:
echo -n super-secret-passwod | base64 - Add the output to the
secrets.ymlfile at thedb_root_passwordfield
Get the secrets, persistent volume in place and apply the deployments for the MySQL database and Flask API
- Add the secrets to your
kubernetes cluster:kubectl apply -f secrets.yml - Create the
persistent volumeandpersistent volume claimfor the database:kubectl apply -f mysql-pv.yml - Create the
MySQLdeployment:kubectl apply -f mysql-deployment.yml - Create the
Flask APIdeployment:kubectl apply -f flaskapp-deployment.yml
You can check the status of the pods, services and deployments.
The API can only be used if the proper database and schemas are set. This can be done via the terminal.
- Connect to your
MySQL databaseby setting up a temporary pod as amysql-client:kubectl run -it --rm --image=mysql --restart=Never mysql-client -- mysql --host mysql --password=<super-secret-password>make sure to enter the (decoded) password specified in thesecrets.yml - Create the database and table
CREATE DATABASE mydb_shop;USE mydb_shop;CREATE TABLE shop(shop_id INT PRIMARY KEY AUTO_INCREMENT, shop_name VARCHAR(255), location VARCHAR(255));
The API can be accessed by exposing it using minikube: minikube service flask-service-jowett. This will return a URL. If you paste this to your browser you will see the hello world message. You can use this service_URL to make requests to the API
Now you can use the API to CRUD your database
- add a user:
curl -H "Content-Type: application/json" -d '{"name": "<user_name>", "email": "<user_email>", "pwd": "<user_password>"}' <service_URL>/create - get all users:
curl <service_URL>/users - get information of a specific user:
curl <service_URL>/user/<user_id> - delete a user by user_id:
curl -H "Content-Type: application/json" <service_URL>/delete/<user_id> - update a user's information:
curl -H "Content-Type: application/json" -d {"name": "<user_name>", "email": "<user_email>", "pwd": "<user_password>", "user_id": <user_id>} <service_URL>/update
helm install elasticsearch elastic/elasticsearch -f values.yaml --namespace=elk --create-namespace --waithelm install kibana elastic/kibana --namespace=elk --waithelm install filebeat elastic/filebeat --namespace=elk --wait
- kibana runs on 5601 port
kubectl port-forward deployment/kibana-kibana 5601 --namespace=elk - elk runs on 9200 port
kubectl port-forward service/elasticsearch-master 9200 --namespace=elk
$Env:KUBECONFIG=("C:\Users\PM\OneDrive\Documents\GitHub\elkstackApplicationTest\kubeconfig-jowett-tkg.yml")
hb53toMlm1g9x135HQ8uOX22curl -u "elastic:hb53toMlm1g9x135HQ8uOX22" -k "https://localhost:9200"rm alias:curlhb53toMlm1g9x135HQ8uOX22jowett.cnasg.net