Kubernetes - on laptop using microK8s.io snap

List all containers in all namespaces

Source Ref for practice: https://kubernetes.io/docs/tutorials/kubernetes-basics/

List all containers in all namespaces

this will return all fields named image for all items returned
microk8s.kubectl get pods --all-namespaces -o jsonpath="{..image}" |\
tr -s '[[:space:]]' '\n' |\
sort |\
uniq -c

Get all pods (from all nodes?)

microk8s.kubectl get pods

Get info about a specific pod ... use the name provided by above command

microk8s.kubectl describe pod kubernetes-bootcamp-6bf84cb898-gmmwb

without pod names ...gory details of all pods

Get name of all pods

microk8s.kubectl get pods -o go-template --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}'

get logs from a specific pod

microk8s.kubectl logs <POD_NAME>

run command in a container in pod

microk8s.kubectl exec <POD_NAME> env microk8s.kubectl exec -ti <POD_NAME> bash

the -ti option ...same as docker: https://txt.icmp.co/2018/05/docker-cheat-sheet.html

4 Ways of exposing services to outside:

  1. ClusterIP (default): internal IP in the cluster...service reachable within k8 cluster
  2. NodePort: NATS on each selected node. Access service-> :
  3. LoadBalancer: creates an external load balancer; assigns fixed external IP if supported
  4. ExternalName: exposes service using by returning a CNAME record. Needs kube-dns service running. generally, set of pods targetted by a service are selected using LabelSelector

Comments