Spring Boot Microservices labs on K8s
- Install Docker Desktop and enable kubernetes service
Note : For new versions of Docker Desktop, run the below command
Spring Cloud Kubernetes requires access to Kubernetes API in order to be able to retrieve a list of addresses of pods running for a single service. If you use Kubernetes you should just execute the following command:
kubectl create clusterrolebinding admin --clusterrole=cluster-admin --serviceaccount=default:default
- execute the below steps to run the applications on K8s
kubectl create deployment simple-rest-api --image=jbossramana/microservices:simple
kubectl expose deployment simple-rest-api --type=LoadBalancer --port=8080
kubectl create deployment other-rest-api --image=jbossramana/microservices:other
kubectl expose deployment other-rest-api --type=LoadBalancer --port=8081
- Take a replication controller, service or pod and expose it as a new Kubernetes Service
- Test the appliction url's
http://localhost:8080/simple
http://localhost:8081/other [this service calls simple service using Ribbon Client and K8s service registry]
- Explain K8s commands
kubectl explain deployment(s)
kubectl explain pod(s)
kubectl explain service(s)
- K8s commands to get deployment, service and pods information :
kubectl get pod(s)
kubectl get service(s)
kubectl get deployment(s)
kubectl get event(s)
kubectl get replicaset(s)
-
To edit the deployment kubectl edit deployment simple-rest-api #minReadySeconds: 15
-
K8s commands to delete the deployment and services
kubectl delete service other-rest-api
kubectl delete deployment other-rest-api -
To scale the application
kubectl scale deployment simple-rest-api --replicas=3
To autoscale: kubectl autoscale deployment simple-rest-api --max=5 --cpu-percent=50
-
Finding a Pod’s Cluster IP kubectl get pod -o wide
-
Finding a Service’s IP kubectl get service --all-namespaces
-
Other useful K8s commands
kubectl explain pods
kubectl describe pod simple-rest-api-678ddff668-d9pmt
kubectl get componentstatuses
kubectl get all
kubectl get all -o wide
kubectl rollout history deployment simple-rest-api
kubectl logs simple-rest-api-678ddff668-d9pmt
kubectl delete all -l app=hello-world-rest-api
kubectl delete all -l app=simple-rest-api
- Enable virtualization @ BIOS
- In windows -> Advanced settings -> Advanced -> Performance -> Data Execution Prevention -> Turn on DEP for all programs and sevices except those i select
- uncheck Hyper-V
- uncheck Windows Hypervisor Platform
- uncheck Virtual Machine Platform
- uninstall vmware
- restart the server
- enable Hyper-V
- restart the server
- Install docker desktop
- right click -> docker-desktop
- select settings
- kubernetes -> select all options
kubectl version
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v1.10.1/src/deploy/recommended/kubernetes-dashboard.yaml
We can access Dashboard using the kubectl command-line tool by running the following command:
kubectl proxy Starting to serve on 127.0.0.1:8001
curl http://localhost:8001/api
Go to http://localhost:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/ on Browser
kubectl apply -f dashboard-adminuser.yml
kubectl apply -f admin-role-binding.yml
kubectl -n kube-system describe secret
$(kubectl -n kube-system get secret | grep admin-user | awk '{print $1}')
Copy the data -> token In the browser => select token option -> paste the above token