Commands
# | Commands | What it does |
1 | sysctl -a | grep machdep.cpu.features | grep VMX | Minikube requires that VT-x/AMD-v virtualization is enabled in BIOS. To check that this is enabled on OSX / macOS ru |
2 | brew update && brew install kubectl && brew cask install docker minikube virtualbox | use brew to install kubectl, docker, minikube and virtualbox |
3 | docker –version
docker-compose –version docker-machine –version minikube version kubectl version –client |
verify the installation |
4 | minikube start | start minikube
a local kubernetes cluster with one node |
5 | kubectl get nodes | should show only one node |
6 | eval $(minikube docker-env) | Use minikube’s built-in docker daemon: |
7 | docker ps | |
8 | docker run -d -p 5000:5000 –restart=always –name registry registry:2 | First setup a local registry, so Kubernetes can pull the image(s) from there. |
9 | docker build . –tag my-app | build the Dockerfile below locally if you want to follow this guide to the letter. Store the Dockerfile locally, preferably in an empty directory and run: |
10 | docker tag my-app localhost:5000/my-app:0.1.0 | You should now have an image named ‘my-app’ locally, check by using docker images (or your own image of course). You can then publish it to your local docker registry: |
11 | docker images | |
12 | kubectl create -f my-app.yml | deployment “my-app” created
service “my-app” created |
13 | kubectl get all | show the pod and service |
14 | minikube service my-app –url | The configuration exposes my-app outside of the cluster, you can get the address to access it by running |
15 | minikube dashboard | start gui dashboard
URL is something like http://192.168.99.100:30000/ |
minikube ssh | ssh to minikube | |
16 | kubectl delete deploy my-app
kubectl delete service my-app |
Delete deployment of my-app |
17 | minikube stop;
minikube delete; rm -rf ~/.minikube .kube; brew uninstall kubectl; brew cask uninstall docker virtualbox minikube; |
clean up everything |
mysql-wordpress
# | Commands | What it does |
1 | kubectl version | check version |
2 | kubectl create secret generic mysql-pass –from-literal=password=michelle | create secret
use ‘michelle’ as password |
3 | kubectl get secrets | verify secret |
4 | kubectl create -f mysql-deployment.yaml | Deploy MySQL from the mysql-deployment.yaml file
The MYSQL_ROOT_PASSWORD environment variable sets the database password from the Secret |
5 | kubectl get pvc | Verify that a PersistentVolume got dynamically provisioned |
6 | kubectl create -f wordpress-deployment.yaml | Create a WordPress Service and Deployment from the wordpress-deployment.yaml file |
7 | kubectl get pvc | kubectl get pvc |
8 | kubectl get services wordpress | Verify that the Service is running by running the command |
9 | minikube service wordpress –url | |
10 | kubectl delete secret mysql-pass
kubectl delete deployment -l app=wordpress kubectl delete service -l app=wordpress kubectl delete pvc -l app=wordpress |
delete secret
delete all deployments and services delete the PersistentVolumeClaims. The dynamically provisioned PersistentVolumes will be automatically deleted. |
expose mysql to local | ||
11 | kubectl get pods | retrieve the name of mysql pod |
12 | kubectl port-forward wordpress-mysql-86987f6b9-9zvbx 3306:3306 | port forwarding
https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#port-forward/ |
13 | connect to it | use mysql workbench to connect via localhost:3306 |
References
- https://gist.github.com/kevin-smets/b91a34cea662d0c523968472a81788f7
- https://kubernetes.io/docs/tutorials/stateful-application/mysql-wordpress-persistent-volume/#objectives
- Kubectl https://kubernetes.io/docs/tasks/tools/install-kubectl/#configure-kubectl
- Minikube https://kubernetes.io/docs/tutorials/stateless-application/hello-minikube/