- Installation of Minikube & Kubectl on Window
- Create Single-Node Cluster and use Adhoc cmds
- Create Multi-Node Cluster
- Kubernetes Resources YAML file
- Kubernetes Secret
- Check and Explain K8s resources
- Minikube Dashboard
There are many ways to create K8s cluster:
- EKS
- AKS
- GKE
- Kubeadm
- Minikube
Here I use Minikube for Multi-Node Cluster: Note: The Cluster is creating is automatic by Minikube we just put our requirement but this is not give fully customize option like Kubeadm.
-
Minikube install on window:
- Search on Browser "kubernetes minikube install" and then Click on -> 'latest release'
Minikube-Download-link
- After Download Extract exe file then, add "Path in System Environment variable".
- Note: Install Oracle VirtualBox on Window download-virtualBox-Link
- Search on Browser "kubernetes minikube install" and then Click on -> 'latest release'
Minikube-Download-link
-
Now Install Client side/ User side command that is "kubectl" for managing K8s Cluster:
- Search on Browser:-> "kubectl install" -> then click on "Install and Set Up kubectl on Windows" kubectl-Download-cmd-Link
- Note: If CLI show error then put both minikube & kubectl file in same folder of window.
Here i create Single-node cluster that is means on single node Master & Worker Node work done.
To Create Single-Node Culster using minikube command is:
minikube start
Create Deployment and svc using CLI adhoc commands:
-
Now create deployment using image:
kubectl create deployment myweb --image=pratikshinde55/apache-webserver:v1
-
Use describe:
kubectl describe deployment myweb
-
Print list of Deployment & Pod:
kubectl get pods kubectl get deployment
-
Get Full lenght information:
kubectl get pods myweb-b77b85fb9-bghs9 -o wide kubectl get deployment myweb -o wide
Load Balancer: [expose] for CLI way
-
Create service or expose our deployment app to outside world:
kubectl expose deployment myweb --type=NodePort --port=80
-
Print list of LB:
kubectl get svc kubectl get service
-
Note:
--type=NodePort
is define give Public_IP &--port=80
=> This is port number of Container or If any app running inside pod/Container then give that port no for example Python-flask app port 5000.kubectl describe svc myweb
-
Here, We see all three pods are attached to the Load Balancer, If we Scale-out or Scale-in that will automatic upadte to Load Balancer Service
-
Command for manual scale:
kubectl scale deployment myweb --replicas=3
-
delete command for delete all k8s resources:
kubectl delete all -all
minikube delete
- Note: After deleted cluster then Go to windows file manager then go to C:\ then -> Users -> ownuser ->
.minikube
then delete this minikube file
Now here create multi-node cluster using minikube.
Interact with Kubernetes:
- CLI (Adhoc commands)
- Code (YAML - Yet Another Markup Language , Declarative Language)
- API
Start Minikube Multi-node Cluster Command:
minikube start -n 2 -p pscluster2
Basic Format of K8s yaml manifest file: (Use .yml extention for code file)
apiVersion:
kind:
metadata:
name:
labels:
spec:
containers:
- name:
image:
-
When we want to manage desired stage of pods with current stage of pods then we use Replication Controller K8s resource type.
-
replicas
,selector
,template
are rc modules/attributes -
While launching a pod using rc, we can give labels to pods, We also provides this pod labels to ReplicationController, So it helps to manage this pods with help of pods labels.
-
Check list of rc command:
kubectl get rc
-
ReplicationController manifest file apply:
notepad rc.yml kubectl create -f rc.yml
-
Describe rc: ( rc --launch--> Pods )
kubectl describe rc myrc
-
show lables command:
kubectl get pods --show-labels
-
selector with show labels:
kubectl get pods --selector team=prod --show-labels
-
If we want scale the replicas then we have Three way, 1st is go to yaml offline file add desired replicas and use
kubectl apply
command , 2nd usekubectl scale rc myrc --replicas=5
command, & 3rd iskubectl edit rc myrc
command this gives online edit file to us we just add replicas there. -
get all command show all resources lists which created till now:
kubectl get all
-
ReplicaSet support both equality-based selector & set-based selector.
-
When we want to manage desired stage of pods with current stage of pods then we use ReplicaSet K8s resource type
-
Replication Controller don't supprot set-based selector, So most of cases ReplicaSet is used.
-
In 99 % cases, In K8s ReplicaSet is used.
kubectl get rs
kubectl describe rs my-rs1
-
Load balancer distribute incomming application traffic across the multiple backend Pods is called as Load Balancer or Reverse proxy, But In Kubernetes it is known as Sevice, Short form is svc.
-
There are three types K8s service types:
- ClusterIP (Private LB)
- NodePort (Public LB)
- LoadBalancer/ExternalName
-
ClusterIP:
- This is Private IP Service, We know that all pods are isolated from outside world but they internally connected to each other, This type of service Load Balancer used for DataBase.
- This is default type of Load Balancre of K8s.
- This service don't allow outside world client to come inside, But they have internally connectivity.
- Labels & Selector is very important to asssign the pods to the service.
-
NodePort:
-
This is Public Load Balancer Service type.
-
This allows outside world to connect to svc.
-
Client connect the IP of Cluste and NodePort port number, Then NodePort divert to the svc port number, then svc port number divert to the targetPort number that is port number of Pod or app.
-
NodePort able to allow outside connectivity because of Kube-proxy.
-
-
Create secret.yml file: (Created generic secret that is used as password for myqsl image)
-
Now This secret we use by this way:(Here i use deployment resource type & pod launch by using MySQL image, so MySQL env pass by using secret)
-
Show all types resources:
kubectl api-resources
-
api versions list:
kubectl api-versions
-
Kubectl explain command:
kubectl explain ReplicationController
-
use explain cmd with option:
kubectl explain ReplicationController.spec
-
more deep explain:
kubectl explain ReplicationController.spec.template
-
This minikube dashboard command launch GUI dashboard of our cluster on browser:
minikube dashboard -p pscluster2
-
Delete all resources in one command:
kubectl delete all --all
-
Delete cluster:
minikube delete -p pscluster2