DEV Community

Cover image for 3 Commands for Cracking the K8s Rosetta Stone
Brian Kirkpatrick
Brian Kirkpatrick

Posted on

3 Commands for Cracking the K8s Rosetta Stone

Honestly, these are more for my own notes than anything else. YMMV. Might add more than three, but we'll see.

See All Resources

...Even if you can't remember what all the resources are in the K8s ontology:

> kubectl get all

NAME                        READY   STATUS    RESTARTS   AGE
pod/demo-6b87cc7b85-7rblb   1/1     Running   0          2m15s

NAME                 TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)   AGE
service/kubernetes   ClusterIP   10.43.0.1       <none>        443/TCP   30d
service/demo         ClusterIP   10.43.181.226   <none>        80/TCP    2m3s

NAME                   READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/demo   1/1     1            1           2m15s

NAME                              DESIRED   CURRENT   READY   AGE
replicaset.apps/demo-6b87cc7b85   1         1         1       2m15s
Enter fullscreen mode Exit fullscreen mode

Assign Ingress for Local Domain

Often you will need to locally test a deployment that would otherwise rely on a remote/provider ingress controller like a LoadBalancer that can't be utilized on most local K8s environments like Rancher Desktop. This command creates an nginx-based ingress controller and assigns a specific local domain with which you can set up port forwarding rules to internal services.

> kubectl create ingress demo-localhost --class=nginx --rule="demo.localdev.me/*=demo:80"

ingress.networking.k8s.io/demo-localhost created

> kubectl port-forward --namespace=ingress-nginx service/ingress-nginx-controller 8080:80

Forwarding from 127.0.0.1:8080 -> 80
Forwarding from [::1]:8080 -> 80
Enter fullscreen mode Exit fullscreen mode

"SSH" Into a Running Container

Really, you aren't SSH-ing so much as running an interactive terminal via bash. Does require the name of the target pod (hence the first command here) and assumes it is running a single default container.

> kubectl get pods

NAME                    READY   STATUS    RESTARTS   AGE
demo-6b87cc7b85-7rblb   1/1     Running   0          7m4s

> kubectl exec -it demo-6b87cc7b85-7rblb -- /bin/bash

root@demo-6b87cc7b85-7rblb:/# 
Enter fullscreen mode Exit fullscreen mode

Top comments (1)

Collapse
 
easton profile image
Easton

Good references but they don't take long to memorize and honestly I feel there's something missing.