How To Handle Minikube(Cheatsheet)-3? K8s – Part: 9

Missed the previous cheatsheets? Here are the links:
Cheatsheet-1
Cheatsheet-2

This is last but the not the least Cheatsheet – 3

COMMAND 25: To Get the URL for any service

Syntax: minikube service --url SERVICE_NAME

[root@kmaster ~]# minikube service --url=true nginx-test
http://192.168.99.100:30184

This is actually <nodeip: port>

COMMAND 26: Get Cluster IP and port

[root@kmaster ~]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 1h
nginx-test NodePort 10.108.249.9 <none> 80:30184/TCP 2m

COMMAND 27: To Get Access deployed service

Syntax: minikube service <srv-name>

[root@kmaster ~]# minikube service nginx-test
Opening kubernetes service default/nginx-test in default browser...

It will pop up in your browser in this case as we have deployed Nginx




COMMAND 28: To get the number of running pods

[root@kmaster ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-test-55494f998-r42s6 1/1 Running 0 11m

COMMAND 29: To scale any Running deployment

[root@kmaster ~]# kubectl scale --replicas=3 deployment/nginx-test
deployment.extensions/nginx-test scaled
[root@kmaster ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-test-55494f998-ctrfm 0/1 ContainerCreating 0 4s
nginx-test-55494f998-r42s6 1/1 Running 0 13m
nginx-test-55494f998-vhzp4 0/1 ContainerCreating 0 4s
previously there were 1 pod running now its have three pods

COMMAND 30: To get attach and get inside any pod

[root@kmaster ~]# kubectl exec -it nginx-test-55494f998-vhzp4 -- /bin/bash
root@nginx-test-55494f998-vhzp4:/#

Section 3: Clean Up

In this section, we will learn about clean up your deployments.

COMMAND 31: To Delete And Deployment

[root@kmaster ~]# kubectl delete deployment nginx-test
deployment.extensions "nginx-test" deleted

COMMAND 32: To Delete Service

[root@kmaster ~]# kubectl delete service nginx-test
service "nginx-test" deleted




Section 4: Minikube Troubleshoot

This section is related to the basic troubleshooting of the minikube setup.

ISSUE 1: Sometimes the IP of Minikube get changed so if somehow it’s not working then check by running the below command.

[root@kmaster ~]# minikube status
minikube: Running
localkube: Running
kubectl: Misconfigured: pointing to stale minikube-vm.
Solution

The above command says that kubectl: Misconfigured: pointing to stale minikube-vm

Solution: 
[root@kmaster ~]# minikube update-context
Kubeconfig IP correctly configured, pointing at 192.168.99.100

ISSUE 2: When it says there is a network issue while start Minikube like the below issue

Error : E0830 11:44:45.720895 51788 start.go:180] Error starting host: Error starting stopped host: Error creating VM: virError(Code=55, Domain=19, Message=’Requested operation is not valid: network ‘minikube-net’ is not active’)

Solution:

[root@kmaster ~]# virsh
virsh #
virsh # net-list --all 
Name State Autostart Persistent
----------------------------------------------------------
default active yes yes
minikube-net inactive no yes

– Should see that minikube-net is inactive. Now run the below command on virsh shell

virsh # net-start minikube-net 
virsh # exit

If got successful then exit virsh and start minikube

[root@kmaster ~]# start minikube

If you get an error message about “Network is already in use by interface virbr1” or something similar then

[root@kmaster ~]# ifconfig virbr1 down
[root@kmaster ~]# brctl delbr virbr1
[root@kmaster ~]# virsh
virsh # net-start minikube-net 
virsh # net-list --all 
Name State Autostart Persistent
----------------------------------------------------------
default active yes yes
minikube-net active yes yes
virsh # exit
[root@kmaster ~]#




Should now start-up

[root@kmaster ~]# minikube start

ISSUE 3: When Minikube is not starting and get hang on getting started

[root@kmaster ~]# minikube start
Starting local Kubernetes v1.10.0 cluster...
Starting VM...

Solution: 

[root@kmaster ~]# minikube stop
[root@kmaster ~]# minkube delete
[root@kmaster ~]# rm -rf ~/.minikube
[root@kmaster ~]# minikube start

Suggestion: You can also use cluster dump this really helpful in troubleshooting for Minikube
To Dump All the Cluster Info

[root@kmaster ~]# kubectl cluster-info dump > 1.txt

You may use the cat command to see all the information.

Section 5: Important File Directory Information

Critical minikube folder /var/lib/localkube, /var/lib/docker
Check minikube config in your host OS desktop ~/.minikube/machines/minikube/config.json

This brings us to the end of the minikube and minikube command cheat sheet.

Kubernetes Series Links:

Understanding Kubernetes Concepts RHEL/CentOs K8s Part-1
Understanding Kubernetes Concepts RHEL/CentOs k8s: Part-2
How to Install Kubernetes on CentOS/RHEL k8s?: Part-3
How to Install Kubernetes on CentOS/RHEL k8s?: Part-4
How To Bring Up The Kubernetes Dashboard? K8s-Part: 5
How to Run Kubernetes Cluster locally (minikube)? K8s – Part: 6
How To Handle Minikube(Cheatsheet)-3? K8s – Part: 7
How To Handle Minikube(Cheatsheet)-3? K8s – Part: 8
How To Handle Minikube(Cheatsheet)-3? K8s – Part: 9