HomeTutorsContact
commandline
Kubernetes Introduction
Konrad Kuśmierz
Konrad Kuśmierz
June 21, 2022
1 min
Kubernetes Introduction

Common Options

In kubectl you can specify optional flags for use with various commands.

alias – Set an alias for kubectl.
alias k=kubectl
echo 'alias k=kubectl' >>~/.bashrc
-o=json – Output format in JSON.
kubectl get pods -o=json
-o=yaml – Output format in YAML.

kubectl get pods -o=yaml -o=wide Output in the plain-text format with any additional information, and for pods, the node name is included.

kubectl get pods -o=wide -n – Alias for namespace.

kubectl get pods -n=<namespace_name> -f – Filename, directory, or URL to files to use to create a resource.

kubectl create -f ./<file name> -l – Filter using a specified label.

kubectl logs -l name=<label name> -h – Help for kubectl.

kubectl -h
Configuration Files (Also referred to as Manifest or YAML Files)
Configuration Files (Also referred to as Manifest or YAML Files.) – Kubernetes objects can be created, updated, and deleted by storing multiple object configuration files in a directory and using kubectl apply to recursively create and update those objects as needed. This method retains writes made to live objects without merging the changes back into the object configuration files. kubectl diff also gives you a preview of what changes apply will make.
kubectl apply -f <configuration file>
kubectl create -f <configuration file> – Create objects.
kubectl create -f <configuration file directory> – Create objects in all manifest files in a directory.
kubectl create -f <‘url’> – Create objects from a URL.
kubectl delete -f <configuration file> – Delete an object.
Read more about Kubectl Apply vs. Kubectl Create – What’s the Difference?.
Cluster Management and Context
Cluster management refers to querying information about the K8S cluster itself.
kubectl cluster-info – Display endpoint information about the master and services in the cluster.
kubectl version – Display the Kubernetes version running on the client and server.
kubectl config view – Get the configuration of the cluster.
kubectl config view -o jsonpath='{.users[*].name}' – Get a list of users.
kubectl config current-context – Display the current context.
kubectl config get-contexts – Display a list of contexts.
kubectl config use-context <cluster name> – Set the default context.
kubectl api-resources – List the API resources that are available.
kubectl api-versions – List the API versions that are available.
-A – List pods, services, daemonsets, deployments, replicasets, statefulsets, jobs, and CronJobs in all namespaces, not custom resource types. Note the alias for --all-namespaces is -A
kubectl get all --all-namespaces

Tags

Share

Konrad Kuśmierz

Konrad Kuśmierz

Software Engineer

Founder

Expertise

devops
ai

Social Media

instagramtwitterwebsite

Related Posts

Awk Introduction
Awk Introduction
June 21, 2023
2 min