Shared Flashcard Set

Details

KUBECTL Study Commands
KubeCTL Commands you should know
96
Computer Science
Professional
11/29/2022

Additional Computer Science Flashcards

 


 

Cards

Term
Kube-api Server
Definition
- Auth User
- Val req
- Retrieve data
- Only service that updates ETCD
- Talks to Scheduler
- Talks to Kubelet
Term
Kube-Controller-Manager
Definition
Single process that manages all controllers
Term
Kube-Scheduler
Definition
- Decides which pods go on which nodes
- Filters based on # cpu's, mem, etc.
- Ranks remaining nodes (0-10) where nodes with larger # remaining resources after pod install gets higher score
Term
Kubelet
Definition
- control actions on nodes
- loads pods
- talks to kube-apiserver
- talks to docker
Term
kube-proxy
Definition
- process that runs on each node
- allows nodes to access each other without IP's in the POD NW
- uses ip tables
Term
PODs
Definition
- encapsulates docker containers
- single instance of an app
- different containers can exist in same pod but not same container in same pod
- share same localhost and memory in a single pod and have same fate (are created or die together)
Term
yaml sections
Definition
apiVersion: v1
kind: Pod
metadata:
name: "pod name"
labels:
app: "label"
spec:
containers:
- name: "container name"
image: "image name"
Term
To see what nodes a pod is running on
Definition
kubectl get pods -o wide
Term
pod logs
Definition
kubectl logs "pod"
Term
Delete rs
Definition
kubectl delete replicaset rs-name
Term
To edit running rs
Definition
kubectl edit rs rs-name
Term
kubectl create vs apply
Definition
- create = creates whole new object
- apply = updates existing object
Term
Imperative vs Declarative
Definition
- imp
- kubectl app
- yaml files
- Dec
- all kubectl cmds except apply
Term
kubectl replace -f file.yaml
Definition
- to apply changes in yaml to running config (saved locally)
- --force will delete and recreate
Term
kubectl apply
Definition
- -f file.yaml
- -f /path_to_files/*
- no need to worry if objs already exist
Term
To see if a scheduler is running
Definition
kubectl -n kube-system get pods
Term
Service shortcuts
Definition
- kubectl get svc
- kubectl get ep
- endpoints
Term

Display endpoint information regarding the services and master in the cluster

How to display cluster information?

Definition

 

What is the kubectl cluster-info 

Term

Show the Kubernetes version functioning on the client and server

What command shows the version of KubeCTL you are using? 

Definition
kubectl version
Term

Get the configuration of the cluster

What command will get you the configuration of the cluster? 

Definition
kubectl config view
Term

Make a list of the available API resources

What command will give you a list of available API resources? 

Definition
kubectl api-resources
Term
what command will Make a list of the available API versions 
Definition
kubectl api-versions
Term
What command will get you a list of everything, for the cluster?
Definition
kubectl get all –all-namespaces
Term

 

Shortcode = ns

What command would you use to creat a namespce <name>

Definition
kubectl create namespace <namespace_name>
Term
How would you list List one or more namespaces
Definition
kubectl get namespace <namespace_name>
Term
Show the detailed condition of one or more namespace
Definition
kubectl describe namespace <namespace_name>
Term
Delete a namespace
Definition
kubectl delete namespace <namespace_name>
Term
Edit and modify the namespace’s definition
Definition
kubectl edit namespace <namespace_name>
Term
Display Resource (CPU/Memory/Storage) usage for a namespace
Definition
kubectl top namespace <namespace_name>
Term

Node operations A Node is a worker machine in Kubernetes and can either be a virtual or a physical machine, which depends on the cluster. Every Node is handled by the control plane. A Node can contain several pods, and the Kubernetes control plane handles scheduling the pods automatically across the Nodes in the cluster. Following commands can be utilised for Node Operations.

How do you Revise the taints on one or more nodes?

Definition
kubectl taint node <node_name>
Term
List one or more nodes
Definition
kubectl get node
Term
Delete a node or multiple nodes
Definition
kubectl delete node <node_name>
Term
Display Resource usage (CPU/Memory/Storage) for nodes
Definition
kubectl top node
Term
How to display Resource allocation per node
Definition
kubectl describe nodes | grep Allocated -A 5
Term
Pods running on a node
Definition
kubectl get pods -o wide | grep <node_name>
Term
Annotate a node
Definition
kubectl annotate node <node_name>
Term
kubectl cordon node <node_name>
Definition
Mark a node as unschedulable
Term
Mark node as schedulable
Definition
kubectl uncordon node <node_name>
Term
Drain a node in preparation for maintenance
Definition
kubectl drain node <node_name>
Term
Add the labels of one or more nodes
Definition
kubectl label node
Term

Listing Resources Kubernets resources also regarded as Kubernetes objects related to a certain namespace, you can either utilise individual kubectl get command to jot down every resource one by one, or you can jot down all the resources in a Kubernetes namespace by executing a single command. Mentioned below are the list of commands to get the resources information.

Create a plain-text list of all namespaces

Definition
kubectl get namespaces
Term
Create a plain-text list of all pods
Definition
kubectl get pods
Term
Create a comprehensive plain-text list of all pods
Definition
kubectl get pods -o wide
Term
Create a list of all pods functioning on a certain node server
Definition
kubectl get pods–field-selector=spec. nodeName=[server-name]
Term
In plain text, make a lst a specific replication controller
Definition
kubectl get replicationcontroller [replication-controller-name]
Term
Generate a plain-text list of all replication services and controllers 
Definition
kubectl get replicationcontroller, services
Term

 

Daemonsets A Daemonset assures that some or all  Nodes run a copy of a Pod. As nodes are incorporated to the cluster, Pods are implemented to them. As nodes are erased  from the cluster, those Pods are garbage collected. Erasing a DaemonSet will clean up the Pods it created.

List one or more daemonsets

Definition
kubectl get daemonset
Term
Edit and modify the definition of one or more daemonset
Definition
kubectl edit daemonset <daemonset_name>
Term
Delete a daemonset
Definition
kubectl delete daemonset <daemonset_name>
Term
Create a new daemonset
Definition
kubectl create daemonset <daemonset_name>
Term
Manage the rollout of a daemonset
Definition
kubectl rollout daemonset
Term
Show the comprehensive state of daemonsets within a namespace
Definition
kubectl describe ds <daemonset_name> -n <namespace_name>
Term

Events Kubernetes events are objects that displays what is happening within a cluster, like what decisions were implemented by the scheduler or why some pods were erased from the node.Events are the first thing to look at for application, along with infrastructure operations when something is not functioning as anticipated. Mentioned below are the kubectl commands to get the events.

Shortcode = ev

 

How to List current events for all resources in the system

Definition
kubectl get events
Term
List Warnings only
Definition
kubectl get events –field-selector type=Warning
Term
List events but exclude Pod events
Definition
kubectl get events –field-selector involvedObject.kind!=Pod
Term
Pull events for a single node with a distinct name
Definition
kubectl get events –field-selector involvedObject.kind=Node, involvedObject.name=<node_name>
Term
From a list of events, filter out normal events
Definition
kubectl get events –field-selector type!=Normal
Term

Logs

You can use Kubernets logs commands to monitor, log and debug the pods

How would you print KubeCTL Logs?

Definition
kubectl logs <pod_name>
Term
Print the logs for a pod for the last hour 
Definition
kubectl logs –since=1h <pod_name>
Term
Get the current 20 lines of logs
Definition
kubectl logs –tail=20 <pod_name>
Term
Get logs from a service and choose which container optionally
Definition
kubectl logs -f <service_name> [-c <$container>]
Term
Adhere to new logs and print the logs for a pod
Definition
kubectl logs -f <pod_name>
Term
For a container in a pod, Print the logs 
Definition
kubectl logs -c <container_name> <pod_name>
Term
Output the logs for a pod into a ‘pod.log’ file 
Definition
kubectl logs <pod_name> pod.log
Term
  • View the logs for the last failed pod
Definition

kubectl logs –previous <pod_name>

Term

Deployments

Shortcode = deploy.

A Kubernetes Deployment is utilised to inform Kubernetes how to design or change instances of the pods that hold a containerized application. Deployments can enhance the number of replica pods, enable rollout of revised code in a controlled way, or roll back to an earlier deployment version if required.

How do you list one or more deployments

Definition
kubectl get deployment
Term
Show the in-depth state of one or more deployments
Definition
kubectl describe deployment <deployment_name>
Term

Edit and revise the definition of one or more deployment on the server
Definition
kubectl edit deployment <deployment_name>
Term
 Generate one a new deployment
Definition
kubectl create deployment <deployment_name>
Term
Delete deployments
Definition
kubectl delete deployment <deployment_name>
Term
Check the rollout status of a deployment
Definition
 kubectl rollout status deployment <deployment_name>
Term

Replication Controllers

Shortcode = rc

Make a list of  the replication controllers

Definition
kubectl get rc
Term
Make a list of  the replication controllers by namespace
Definition
kubectl get rc –namespace=”<namespace_name>” 
Term

ReplicaSets

Shortcode = rs

List ReplicaSets

Definition
kubectl get replicasets
Term
Show the detailed state of one or more ReplicaSets
Definition
kubectl describe replicasets <replicaset_name>
Term
Scale a ReplicaSet
Definition
kubectl scale –replicas=[x]
Term

11. Secrets

A Kubernets Secret is an object that comprises minor portion of sensitive data like a token, a key or password.. Such data might otherwise be inserted in an image or in a Pod specification. Users can build Secrets and the system also generates a few Secrets with the help of the following kubectl commands.

How to creat a secret? 

Definition
kubectl create secret
Term
List secrets
Definition
kubectl get secrets
Term
List details about secrets
Definition
kubectl describe secrets
Term
Delete a secret
Definition
kubectldelete secret <secret_name>
Term

 Services and Service Accounts: 

A Kubernetes service is a logical abstraction for a deployed group of pods in a cluster (which all perform the same function) and Service accounts are used to provide an identity for pods. Pods that want to interact with the API server will authenticate with a particular service account.

Make a list of  one or more services

 

Definition
kubectl get services
Term
Show the detailed state of a service
Definition
kubectl describe services
Term
Reveal a replication controller, service, deployment or pod as a new Kubernetes service
Definition
kubectl expose deployment [deployment_name]
Term

 

Edit and modify the definition of one or more services

Definition
kubectl edit services
Term
List service accounts
Definition
kubectl get serviceaccounts
Term
Show the in-depth state of one or more service accounts
Definition
kubectl describe serviceaccounts
Term
Replace a service account
Definition
kubectl replace serviceaccount
Term
Delete a service account
Definition
kubectl delete serviceaccount <service_account_name>
Term

Kubectl commands adhere to syntax or a common structure, which lets administrators to read and verify every kubectl command entered in the terminal window. There are four important parameters to each kubectl call:

 

what is the order of a KubeCTL Syntax call? 

Definition
kubectl <command> <type> <name> <flags>

The <command> parameter is the operation that should be executed on a resource. Kubectl backs several operations, such as describe, create, get, execute and delete.

The <type> parameter specifies the resource type, like pods, bindings, and nodes. Usually, Resource type designations make use of abbreviations to streamline the command line. For instance, the “persistentvolumeclaims” type can be shortened to “pvc.” The <type> parameter is strong, since there are several resource types, which also include namespaces, services, jobs, resource quotas, replication controllers, leases and events. Programmers and Kubernetes administrators should be acquainted with a complete list of resource types.

The <name> parameter defines the name of the resource in the environment. If we omit the name parameter, the details for all resources are returned, similarly like a wildcard argument. Also, administrators can point out multiple resource types and names in the exact command line, as mentioned below.

kubectl <command> <type> <name1> <name2> … <nameX>

This is effective when the names are all the same resource type, for instance:

kubectl get pod test-pod1 test-pod2

Kubectl syntax also backs the combination of several resource types and names on the exact command line in two ways:

kubectl <command> <type1/name1> <type2/name2> … <typeX/nameX>

or:

kubectl get pod/test-pod1 replicationcontroller/xyzcorp-rc1

Lastly, the <flags> parameter incorporates optional flags to the command line. Flags differ with the command, so not all flags are available for all commands. For instance, the -s, (one dash shorthand notation) or –server (two dashes, longhand notation) flags designate the port and address of the Kubernetes API server.

The -o or –output <flag> sends responses to a terminal window in a certain format. For instance, the -o yaml flag will output a YAML-formatted API object, whereas the -o json flag will output a JSON-formatted API object.

Term

Learn how to use help

Definition
kubectl help 
Term
kubectl scale deployment -n <namespace> --replicas 0 --all
Definition

Kubectl Command to scale down all deployments in the namespace

You cannot keep scaling down each deployment in a namespace.

You can instead use the following command  to scale down all the pods and deployments in your namespace to 0

Term
As is clear by the name, the kubectl edit command is used to edit a deployed resource in your Kubernetes cluster
Definition

kubectl edit <resource type> <resource name>

 

The <resource type> could be anything from a deployment to a ReplicaSet. It is specified in the key kind in the resource file. The <resource name> is defined under the key metadata.

You could also edit a resource file directly by using the following syntax:

kubectl edit -f <file path>

Term
How to edit the NSP crn-accounts2 in the nspapp namespace
Definition
KubeCTL Edit deployments crn-accounts2-service-aks -n nspapp
Term

How to roll out a deployment to a namespace 

 

Kubectl rollout restart makes it simple to implement updates without a complete reboot in the middle of an environment. You can include the command in a scheduled job, making it easier to automate, which can be great for sporadic deployments.

Definition

KubeCTL Rollout restart deployment crn-account2-service-aks -n nspapp

 

  1. Make changes to your code base.
  2. Build and push a new docker image.
  3. Update your deployments config to use the new image.
  4. Run kubectl rollout restart on the deployment in question.
Term
How to delete Pod
Definition

KubeCTL delete pods crm-order2-service-aks-86494d8654-ws2tn -n nspapp

 

 

kubectl delete pod pod-name
Term


The given node will be marked unschedulable to prevent new pods from arriving this command evicts the pods if the API server supports https://kubernetes.io/docs/concepts/workloads/pods/disruptions/ . Otherwise, it will use normal DELETE to delete the pods. The command evicts or deletes all pods except mirror pods (which cannot be deleted through the API server). If there are daemon set-managed pods, the command will not proceed without --ignore-daemonsets, and regardless it will not delete any daemon set-managed pods, because those pods would be immediately replaced by the daemon set controller, which ignores unschedulable markings. If there are any pods that are neither mirror pods nor managed by a replication controller, replica set, daemon set, stateful set, or job, then drain will not delete any pods unless you use --force. --force will also allow deletion to proceed if the managing resource of one or more pods is missing.
Definition

Drain node in preparation for maintenance.

 

$ kubectl drain NODE

Supporting users have an ad free experience!