DEV Community

Jasper Rodda
Jasper Rodda

Posted on • Edited on

Kubernetes commands for beginners

minikube start --driver=docker
minikube start --driver=virtualbox

minikube start --driver=virtualbox --no-vtx-check
minikube start --driver=virtualbox --no-vtx-check --memory=4098

minikube start --memory=4098 --driver=hyperkit
minikube start --memory=4098 --driver=hyperv
Enter fullscreen mode Exit fullscreen mode
  • 1.a View Context
kubectl config view
Enter fullscreen mode Exit fullscreen mode
  • 1.b Switch context to Mini-Kube
kubectl config use-context minikube
kubectl config use-context arn:aws:eks:us-east-1:917165987323:cluster/demo-cluster

Enter fullscreen mode Exit fullscreen mode
  • 1.c Set Default
  • To make docker/Virtual the default driver:
minikube config set driver docker
minikube config set driver virtualbox
Enter fullscreen mode Exit fullscreen mode
  • 2. View cluster info
PS C:\WINDOWS\system32> kubectl cluster-info
Kubernetes control plane is running at https://192.168.XX.XXX:8443
CoreDNS is running at https://192.168.XX.XXX:8443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'
Enter fullscreen mode Exit fullscreen mode
  • 3. Get nodes
PS C:\WINDOWS\system32> kubectl get nodes
NAME       STATUS   ROLES           AGE   VERSION
minikube   Ready    control-plane   13m   v1.27.4 
Enter fullscreen mode Exit fullscreen mode
  • 4. Get namespaces
PS C:\WINDOWS\system32> kubectl get namespaces
NAME              STATUS   AGE
default           Active   14m
kube-node-lease   Active   14m
kube-public       Active   14m
kube-system       Active   14m
Enter fullscreen mode Exit fullscreen mode
  • 5. Get All pods
PS C:\WINDOWS\system32> kubectl get pods -A
NAMESPACE     NAME                               READY   STATUS    RESTARTS      AGE
kube-system   coredns-5d78c9869d-df2qj           1/1     Running   0             14m
kube-system   etcd-minikube                      1/1     Running   0             14m
kube-system   kube-apiserver-minikube            1/1     Running   0             14m
kube-system   kube-controller-manager-minikube   1/1     Running   0             14m
kube-system   kube-proxy-8zw65                   1/1     Running   0             14m
kube-system   kube-scheduler-minikube            1/1     Running   0             14m
kube-system   storage-provisioner                1/1     Running   1 (13m ago)   14m
Enter fullscreen mode Exit fullscreen mode
  • 6. get all services
PS C:\WINDOWS\system32> kubectl get services -A
NAMESPACE     NAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)                  AGE
default       kubernetes   ClusterIP   10.96.0.1    <none>        443/TCP                  15m
kube-system   kube-dns     ClusterIP   10.96.0.10   <none>        53/UDP,53/TCP,9153/TCP   15m
Enter fullscreen mode Exit fullscreen mode
  • 7. get namespaces
PS C:\WINDOWS\system32> kubectl get namespaces
NAME              STATUS   AGE
default           Active   31m
kube-node-lease   Active   31m
kube-public       Active   31m
kube-system       Active   31m
Enter fullscreen mode Exit fullscreen mode
  • 8. delete namespaces through a yaml file
PS C:\WINDOWS\system32> kubectl delete -f namespace.yaml
Enter fullscreen mode Exit fullscreen mode
  • 9. get pods in "development" namespace
PS C:\WINDOWS\system32> kubectl get pods -n development
NAME                                   READY   STATUS    RESTARTS   AGE
pod-info-deployment-869667679b-b9k5s   1/1     Running   0          72s
pod-info-deployment-869667679b-kgkk4   1/1     Running   0          72s
pod-info-deployment-869667679b-snhnz   1/1     Running   0          72s
Enter fullscreen mode Exit fullscreen mode
  • 10. get pods in "default" namespace
PS C:\WINDOWS\system32> kubectl get pods
Enter fullscreen mode Exit fullscreen mode
  • 11. #delete pod with its NAME Before:
PS C:\WINDOWS\system32> kubectl get pods -n development
NAME                                   READY   STATUS    RESTARTS   AGE
pod-info-deployment-869667679b-b9k5s   1/1     Running   0          9m16s
pod-info-deployment-869667679b-kgkk4   1/1     Running   0          9m16s
pod-info-deployment-869667679b-snhnz   1/1     Running   0          9m16s
Enter fullscreen mode Exit fullscreen mode

After:

PS C:\WINDOWS\system32> kubectl delete pod pod-info-deployment-869667679b-snhnz -n development
pod "pod-info-deployment-869667679b-snhnz" deleted
Enter fullscreen mode Exit fullscreen mode
  • 12. get namespaces
PS C:\WINDOWS\system32> kubectl get ns
NAME              STATUS   AGE
default           Active   68m
development       Active   24m
kube-node-lease   Active   68m
kube-public       Active   68m
kube-system       Active   68m
production        Active   21m

Enter fullscreen mode Exit fullscreen mode
  • 13. get deployment list by namespace
PS C:\WINDOWS\system32> kubectl get deployments -n development
NAME                  READY   UP-TO-DATE   AVAILABLE   AGE
pod-info-deployment   3/3     3            3           15m
Enter fullscreen mode Exit fullscreen mode
  • 14. get pods by namespace
PS C:\WINDOWS\system32> kubectl get pods -n development
NAME                                   READY   STATUS    RESTARTS   AGE
pod-info-deployment-869667679b-b9k5s   1/1     Running   0          15m
pod-info-deployment-869667679b-f5dcv   1/1     Running   0          3m11s
pod-info-deployment-869667679b-rd72p   1/1     Running   0          4m35s
Enter fullscreen mode Exit fullscreen mode
  • 15. describe pod
PS C:\WINDOWS\system32> kubectl describe pod pod-info-deployment-869667679b-b9k5s -n development
Name:             pod-info-deployment-869667679b-b9k5s
Namespace:        development
Priority:         0
Service Account:  default
Node:             minikube/192.168.59.100
Start Time:       Fri, 25 Aug 2023 12:33:35 -0500
Enter fullscreen mode Exit fullscreen mode
  • 16. ssh into a container via busybox - through an interactive terminal --> kubectl exec -it busybox-55fdb79844-94tf8 -- /bin/sh
PS C:\WINDOWS\system32> kubectl exec -it busybox-55fdb79844-94tf8 -- /bin/sh
/ # ls
bin    dev    etc    home   lib    lib64  proc   root   sys    tmp    usr    var
/ # wget 10.244.0.4:3000
Connecting to 10.244.0.4:3000 (10.244.0.4:3000)
saving to 'index.html'
index.html           100% |**************************************************************************************************************|   103  0:00:00 ETA
'index.html' saved
/ # cat index.html
{"pod_name":"pod-info-deployment-869667679b-b9k5s","pod_namespace":"development","pod_ip":"10.244.0.4"}/ # exit

Enter fullscreen mode Exit fullscreen mode
  • 17. get pods IP address
kubectl get pods -n development -o wide
NAME                                   READY   STATUS    RESTARTS   AGE   IP            NODE       NOMINATED NODE   READINESS GATES
pod-info-deployment-869667679b-b9k5s   1/1     Running   0          90m   10.244.0.4    minikube   <none>           <none>
pod-info-deployment-869667679b-crx5q   1/1     Running   0          73m   10.244.0.9    minikube   <none>           <none>
pod-info-deployment-869667679b-rd72p   1/1     Running   0          78m   10.244.0.7    minikube   <none>           <none>
quote-service-5d654676cc-n7c4j         1/1     Running   0          74s   10.244.0.12   minikube   <none>           <none>
quote-service-5d654676cc-qzxx2         1/1     Running   0          74s   10.244.0.11   minikube   <none>           <none>

Enter fullscreen mode Exit fullscreen mode
  • 18. get pods in default namespace - you will find busybox-55fdb79844-94tf8
PS C:\WINDOWS\system32> kubectl get pods
NAME                       READY   STATUS    RESTARTS   AGE
busybox-55fdb79844-94tf8   1/1     Running   0          99m
Enter fullscreen mode Exit fullscreen mode
  • 19. Errors/ Troubleshooting:
  • If you get below error, run minikube start --driver=virtualbox --no-vtx-check click here for more details
minikube v1.25.1 on Microsoft Windows 10 Home Single Language 10.0.19043 Build 19043
MINIKUBE_HOME=C:\os\minikube\Minikube
Automatically selected the virtualbox driver
Starting control plane node minikube in cluster minikube
Creating virtualbox VM (CPUs=2, Memory=4000MB, Disk=20000MB) ... ! StartHost failed, but will try again: creating host: create: precreate: This computer doesn't have VT-X/AMD-v enabled. Enabling it in the BIOS is mandatory
Creating virtualbox VM (CPUs=2, Memory=4000MB, Disk=20000MB) ...
Failed to start virtualbox VM. Running "minikube delete" may fix it: creating host: create: precreate: This computer doesn't have VT-X/AMD-v enabled. Enabling it in the BIOS is mandatory
Enter fullscreen mode Exit fullscreen mode
  • 20. Minikube commands
  • Config:
  • minikube config view
minikube config view
- driver: virtualbox
Enter fullscreen mode Exit fullscreen mode
  • Show Docker context: docker context show

- Show docker context: docker context ls

  • 21. Delete Minikube Cluster
    • minikube delete
    • minikube delete --all
    • minikube delete -o
    • minikube delete -purge
--all=false:
        Set flag to delete all profiles

    -o, --output='text':
        Format to print stdout in. Options include: [text,json]

    --purge=false:
        Set this flag to delete the '.minikube' folder from your user directory.
Enter fullscreen mode Exit fullscreen mode

Top comments (0)