-
Label:
- Labels are key/value pairs that are attached to objects, such as pods.
- Labels can be attached to objects at creation time and subsequently added and modified at any time.
- Each object can have a set of key/value labels defined. Each Key must be unique for a given object.
-
Service:
- A Kubernetes Service is an abstraction which defines a logical set of Pods and a policy by which to access them - sometimes called a micro-service.
- Behind a service, pods come and go with autoscaling but service is by which we communicate.
-
Namespace:
- Within Namespaces level we can apply resource limits.
- Most Kubernetes resources (e.g. pods, services, replication controllers, and others) are in some namespaces.
- However namespace resources are not themselves in a namespace.
- And low-level resources, such as nodes and persistentVolumes, are not in any namespace.
- Service endpoint created has dns entry of form
<service-name>.<namespace-name>.svc.cluster.local.- So with namespace we can have similar services across multiple namespaces such as Development, Staging and Production
-
Get components(etcd, scheduler ...) status :
kubectl get cs
- Get all nodes in cluster :
kubectl get no - Watch nodes continuously:
kubectl get nodes -w
- Get pods running:
kubectl get po - Get pods with labels :
kubectl get pods --show-labels - Select pods with specific label :
kubectl get pod -l class - Get non-running pods:
kubectl get pods --field-selector=status.phase!=Running- Get only running pods:
kubectl get po --field-selector status.phase=Running - #Ref : https://kubernetes.io/docs/concepts/overview/working-with-objects/field-selectors/
- Get only running pods:
- Grep pod with specific name :
kubectl delete pod $(kubectl get pods --no-headers | grep "pod-name" | awk '{ print 0 }')- Little bash fun up ther^, if you know exact name use:
kubectl delete pod pod-name
- Little bash fun up ther^, if you know exact name use:
- Get pods not running in 'non-default' namespace:
kubectl get services --field-selector metadata.namespace!=default - Kubec
- Get all running services:
kubectl get svc
- Get all namespaces:
kubectl get namespaces - Get cluster info:
kubectl cluster-info - Get all contexts:
kubectl config get-contexts - More details on namespaces: https://gist.github.com/42e7be266195f8711ec59814d4db5b1e
-
Kubectl output with custom field and sorted:
kubectl get pod --sort-by .status.containerStatuses[].restartCount -o custom-columns=Name:.metadata.name,restartCount:.status.containerStatuses[].restartCount
-
Kubectl output filter with selected field
- #Ref : https://kubernetes.io/docs/concepts/overview/working-with-objects/field-selectors/`
kubectl get services --field-selector metadata.namespace!=defaultkubectl get po --field-selector status.phase=Running
-
Via a label selector, the client/user can identify a set of objects. The label selector is the core grouping primitive in Kubernetes.