prompt
stringlengths
13
282
response
stringlengths
128
3.11k
List the specified resources by their type and names
Command: ```bash kubectl get rc/web service/gateway-rc pods/database-pod ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced yo...
Create a copy of the "email-service-pod" pod and start a debug session with a shell in the "stardust-shuttle" container
Command: ```bash kubectl debug email-service-pod -it --copy-to=my-custom-dbg --container=stardust-shuttle -- sh ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used...
Forward traffic from port 3000 on localhost and IP 10.19.21.23 to port 8000 in the pod named "api-service-pod"
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/api-service-pod 3000:8000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the cri...
Update the 'auth' pod by setting the annotation 'git-repo' to the value 'https://github.com/example/my-app'.
Command: ```bash kubectl annotate pods auth git-repo='https://github.com/example/my-app' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels ...
List all the environment variables defined on the 'notification-handler-deployment' deployment
Command: ```bash kubectl set env deployment/notification-handler-deployment --list ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more pod templates (...
Create a copy of e-commerce-pod using the kubectl debug command. Set the image of all containers in the copied pod to busybox.
Command: ```bash kubectl debug e-commerce-pod --copy-to=my-debugger --set-image=*=busybox ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used by default if no reso...
Add a label to the pod 'media-stream'
Command: ```bash kubectl label pods media-stream env=staging ``` What it does: Update the labels on a resource. Syntax: `kubectl label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]` Helpful flags: "flag": "--all-namespaces", "short": "-A", "default": "false", "usage...
Set the cluster field in a given context to a specified cluster
Command: ```bash kubectl config set contexts.prod-context.cluster on-prem-cluster ``` What it does: Set an individual value in a kubeconfig file. PROPERTY_NAME is a dot delimited name where each token represents either an attribute name or a map key. Map keys may not contain dots. PROPERTY_VALUE is the new value you ...
display the resource usage metrics for the kube-master-9 node
Command: ```bash kubectl top node kube-master-9 ``` What it does: Display resource (CPU/memory) usage of nodes. The top-node command allows you to see the resource consumption of nodes. Syntax: `kubectl top node [NAME | -l label]` Helpful flags: "flag": "--selector", "short": "-l", "default": "", "usage": "Selector ...
Retrieve the snapshot logs from the container "e-commerce-pod-1" of the deployment "frontend-deployment-1".
Command: ```bash kubectl logs deployment/frontend-deployment -c e-commerce-pod-1 ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag":...
Update the pod named 'api' with the annotation 'criticality' and the value 'high', replacing any existing value
Command: ```bash kubectl annotate --overwrite pods api criticality='high' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels and include arb...
Start a pod named hazelcast with the ethereum/client-go image and expose port 3000 from the container
Command: ```bash kubectl run hazelcast --image=ethereum/client-go --port=3000 ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args...]` Helpful flags: ...
Forward port 3000 on all addresses to port 5000 in the pod named "chat-app-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/chat-app-pod 3000:5000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will...
Import specific keys from a config map into a deployment
Command: ```bash kubectl set env --keys=DATABASE_URL --from=configmap/app-settings deployment/backend-microservice-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable...
Create a new config map named 'app-config', using the specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap app-config --from-file=settings=/path/to/options/file1.txt --from-file=key2=/path/to/data/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a config...
Configure autoscaling for the replication controller "cdn" with a target CPU utilization of 90%, allowing the number of pods to scale between 1 and 2.
Command: ```bash kubectl autoscale rc cdn --max=2 --cpu-percent=90 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that uses the...
Taint nodes with project=project-alpha label with a workload=web-node-8:PreferNoSchedule taint
Command: ```bash kubectl taint node -l project=project-alpha workload=web-node-8:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "us...
Add a taint with the key 'datacenter' on nodes having the label cluster=my-cluster and the value datacenter=storage-node-13 with the effect 'PreferNoSchedule'
Command: ```bash kubectl taint node -l cluster=my-cluster datacenter=storage-node-13:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "",...
Remove the environment variable "var-to-remove" from the exec auth plugin configuration for the "developer" entry.
Command: ```bash kubectl config set-credentials developer --exec-env=var-to-remove- ``` What it does: Set a user entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values. Client-certificate flags: --client-certificate=certfile --client-key=keyfile Bearer token flags:...
Set the CPU limits of the nginx container in the amazonlinux deployment to 3 and the memory limits to 512Mi.
Command: ```bash kubectl set resources deployment amazonlinux -c=nginx --limits=cpu=3,memory=512Mi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requested, but may burst up...
Set the CPU and memory limits for a container in a deployment to specific values.
Command: ```bash kubectl set resources deployment ruby -c=nginx --limits=cpu=1,memory=128Mi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requested, but may burst up to its...
Update the deployment 'mydeployment' by adding a new environment variable called DB_PASSWORD with the value 'secretpassword'.
Command: ```bash kubectl set env deployment/mydeployment DB_PASSWORD=secretpassword ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more pod templates ...
Create a service for the replicated ruby containers
Command: ```bash kubectl expose rc ruby --port=80 --target-port=300100 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port. A d...
List the replication controller 'web', service 'api-service-rc', and pod 'gateway-pod'
Command: ```bash kubectl get rc/web service/api-service-rc pods/gateway-pod ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced...
Forward traffic from port 8080 locally to port 8088 in the monitoring-stack-deployment pod.
Command: ```bash kubectl port-forward deployment/monitoring-stack-deployment 8080 8088 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod ...
Retrieve a list of deployments in the JSON output format for the "v3.0.0" version of the "api-v2" API group.
Command: ```bash kubectl get deployments.v3.0.0.api-v2 -o json ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you will onl...
Add a taint with key 'hardware' on nodes having label feature=feature-xyz
Command: ```bash kubectl taint node -l feature=feature-xyz hardware=node-1:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": ...
Add a taint to node 'gpu-node-12' with key 'disktype' and no value
Command: ```bash kubectl taint nodes gpu-node-12 disktype:NoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: ...
Import specific keys from a config map into an environment variable of a deployment.
Command: ```bash kubectl set env --keys=config_file_path --from=configmap/log-config deployment/payment-processor-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable ...
Get output from running the 'geth' command in cyber-sleuth from the frontend-pod
Command: ```bash kubectl exec frontend-pod -c cyber-sleuth -- geth ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the...
Import the specific keys `api_key` from the `db-config` config map into the `api-server-deployment` deployment.
Command: ```bash kubectl set env --keys=api_key --from=configmap/db-config deployment/api-server-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in on...
Update the pod named 'vpn' with the label 'env' and the value 'development'
Command: ```bash kubectl label pods vpn env=development ``` What it does: Update the labels on a resource. Syntax: `kubectl label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]` Helpful flags: "flag": "--all-namespaces", "short": "-A", "default": "false", "usage": "I...
Create a new config map named kube-system-config with the specified keys 'conf' and 'data'
Command: ```bash kubectl create configmap kube-system-config --from-file=conf=/path/to/profiles/file1.txt --from-file=data=/path/to/preferences/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creat...
Set the CPU limit to "2" and memory limit to "1Gi" for the node container in the nginx deployment.
Command: ```bash kubectl set resources deployment node -c=nginx --limits=cpu=2,memory=1Gi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requested, but may burst up to its s...
Import the 'smtp_server' key from the 'app-config-prod' ConfigMap and set it as an environment variable in the 'web-app-deployment' deployment.
Command: ```bash kubectl set env --keys=smtp_server --from=configmap/app-config-prod deployment/web-app-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definition...
Copy the file ~/.config/kube from the remote pod "message-broker-pod-15" in the "kube-system" namespace to the local directory /tmp/bar.
Command: ```bash kubectl cp kube-system/message-broker-pod-15:~/.config/kube /tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, us...
Create a job named "backup" using the specified Docker image "docker.elastic.co/elasticsearch/elasticsearch" and run the command "elasticsearch" within the job.
Command: ```bash kubectl create job backup --image=docker.elastic.co/elasticsearch/elasticsearch -- elasticsearch ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "def...
Set the cluster field in the specified context to the desired cluster
Command: ```bash kubectl config set contexts.cluster-2-context.cluster kube-cluster-1 ``` What it does: Set an individual value in a kubeconfig file. PROPERTY_NAME is a dot delimited name where each token represents either an attribute name or a map key. Map keys may not contain dots. PROPERTY_VALUE is the new value ...
Create a new LoadBalancer service with the name "auth-service-lb" and map port 8089 on the host to port 8888 on the service.
Command: ```bash kubectl create service loadbalancer auth-service-lb --tcp=8089:8888 ``` What it does: Create a LoadBalancer service with the specified name. Syntax: `kubectl create service loadbalancer NAME [--tcp=port:targetPort] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "de...
Forward traffic from port 9090 on all addresses to port 8080 in the 'security-service-pod' pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/security-service-pod 9090:8080 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a ...
List the supported API resources for the specified API group
Command: ```bash kubectl api-resources --api-group=scheduling.k8s.io ``` What it does: Print the supported API resources on the server. Syntax: `kubectl api-resources` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: wide|name. "
Retrieve snapshot logs from the container scheduler-app-deployment-1 of a deployment named proxy-service-pod
Command: ```bash kubectl logs deployment/scheduler-app-deployment -c proxy-service-pod-1 ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags:...
Update the cpu and memory limits for the 'alpine' deployment's 'nginx' container
Command: ```bash kubectl set resources deployment alpine -c=nginx --limits=cpu=500m,memory=4Gi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requested, but may burst up to ...
Set the custom TLS server name to 'my-k8s-cluster' for the 'kube-cluster-2' cluster entry
Command: ```bash kubectl config set-cluster kube-cluster-2 --tls-server-name=my-k8s-cluster ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certifi...
retrieve the list of deployments in YAML output format from the "alpha-2.0" version of the "external-apps" API group
Command: ```bash kubectl get deployments.alpha-2.0.external-apps -o yaml ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced yo...
Get output from stardust-shuttle from the pod named "monitoring-pod"
Command: ```bash kubectl attach monitoring-pod -c stardust-shuttle ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitt...
Forward traffic from port 5432 on all addresses to port 9090 in the analytics-pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/analytics-pod 5432:9090 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod wil...
Run the command 'mysqld' in the 'time-machine' container of the 'web-app-pod' pod and get the output
Command: ```bash kubectl exec web-app-pod -c time-machine -- mysqld ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use th...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=external_api_url --from=configmap/app-secrets deployment/load-balancer-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable def...
Import the 'EXTERNAL_API_URL' key from the 'app-config-prod' config map and set it as an environment variable for the 'authentication-service-deployment' deployment.
Command: ```bash kubectl set env --keys=EXTERNAL_API_URL --from=configmap/app-config-prod deployment/authentication-service-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment...
Create a cron job named 'email-notifications' using the 'redis' image, with a schedule of running the 'redis-server' command every minute.
Command: ```bash kubectl create cronjob email-notifications --image=redis --schedule="*/1 * * * *" -- redis-server ``` What it does: Create a cron job with the specified name. Syntax: `kubectl create cronjob NAME --image=image --schedule='0/5 * * * ?' -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short...
Run the command 'npm --version' inside the first container of the pod named 'security-service-pod' and print the output.
Command: ```bash kubectl exec security-service-pod -- npm --version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use th...
Import the DEBUG_MODE key from the config map 'db-config' into the environment of the 'frontend-deployment' deployment.
Command: ```bash kubectl set env --keys=DEBUG_MODE --from=configmap/db-config deployment/frontend-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in o...
Create a new config map named 'app-config-prod' from the environment file located at 'path/to/configs.env'
Command: ```bash kubectl create configmap app-config-prod --from-env-file=path/to/configs.env ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a config map based on a file, the key will default to th...
Execute the 'docker run -d ubuntu sleep 3600' command within the 'code-explorer' container of the 'payment-gateway-pod' pod and retrieve the output.
Command: ```bash kubectl exec payment-gateway-pod -c code-explorer -- docker run -d ubuntu sleep 3600 ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "...
Create a new secret named cert-manager-secret using an env file
Command: ```bash kubectl create secret generic cert-manager-secret --from-env-file=path/to/preferences.env ``` What it does: Create a secret based on a file, directory, or specified literal value. A single secret may package one or more key/value pairs. When creating a secret based on a file, the key will default to t...
Expose a replication controller as a service with specified ports
Command: ```bash kubectl expose rc php --port=5000 --target-port=330600 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port. A ...
Apply a taint to the node 'edge-node-10' with the key 'workload' and no value.
Command: ```bash kubectl taint nodes edge-node-10 workload:NoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of:...
Import the 'database_url' key from the 'app-config-dev' config map and set it as an environment variable in the 'mydeployment' deployment.
Command: ```bash kubectl set env --keys=database_url --from=configmap/app-config-dev deployment/mydeployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in o...
Create a debug copy of the cdn-service-pod, adding a debug container and changing the container images
Command: ```bash kubectl debug cdn-service-pod -it --copy-to=my-debugger --image=debian --set-image=proxy=nginx:1.21,logger=logging-app:debug ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resour...
Remove the label 'release-' from the pod named 'security', if it exists
Command: ```bash kubectl label pods security release- ``` What it does: Update the labels on a resource. Syntax: `kubectl label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]` Helpful flags: "flag": "--all-namespaces", "short": "-A", "default": "false", "usage": "If ...
Remove the taint from node 'backup-node-14' if it exists
Command: ```bash kubectl taint nodes backup-node-14 environment:NoSchedule- ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. O...
Start port forwarding for the 'proxy-server-pod' pod, listening on all addresses and forwarding traffic from port 5432 to port 6379 within the pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/proxy-server-pod 5432:6379 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod ...
Create a service for the replicated python application, which will serve on port 80 and connect to the containers on port 8000.
Command: ```bash kubectl expose rc python --port=7000 --target-port=844300 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port....
Update the annotation 'contact-email' for the pod 'analytics' with the value 'support@example.com'
Command: ```bash kubectl annotate pods analytics contact-email=support@example.com ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels and in...
Edit the last-applied-configuration annotations of a resource using a JSON file.
Command: ```bash kubectl apply edit-last-applied -f config.yaml -o json ``` What it does: Edit the latest last-applied-configuration annotations of resources from the default editor. The edit-last-applied command allows you to directly edit any API resource you can retrieve via the command-line tools. It will open the...
Port-forward local port 5000 to port 5432 in the 'mypod' pod
Command: ```bash kubectl port-forward pod/mypod 5000 5432 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automaticall...
Add a taint with the key 'disktype' on nodes that have the label 'namespace=mynamespace'
Command: ```bash kubectl taint node -l namespace=mynamespace disktype=web-node-8:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "us...
Display only the most recent 20 lines of logs for the web-app-pod pod
Command: ```bash kubectl logs --tail=20 web-app-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", "short": "-c"...
Create a deployment named "mattermost" with the image "postgres" using the command-line interface.
Command: ```bash kubectl create deployment mattermost --image=postgres -- postgres ``` What it does: Create a deployment with the specified name. Syntax: `kubectl create deployment NAME --image=image -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One...
Attach to the 'stardust-shuttle' container in the 'backend-pod' pod to retrieve its output.
Command: ```bash kubectl attach backend-pod -c stardust-shuttle ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted,...
Remove the label 'app' from the 'gateway' pod
Command: ```bash kubectl label pods gateway app- ``` What it does: Update the labels on a resource. Syntax: `kubectl label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]` Helpful flags: "flag": "--all-namespaces", "short": "-A", "default": "false", "usage": "If true,...
Create a pod disruption budget named replica-set-pdb that will select all pods with the tier=frontend label and require at least 9 of them being available at any point in time
Command: ```bash kubectl create poddisruptionbudget replica-set-pdb --selector=tier=frontend --min-available=9 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-available=N ...
Create a service for a replicated alpine pod, serving on port 8089 and connecting to the containers on port 300000
Command: ```bash kubectl expose rc alpine --port=8089 --target-port=300000 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port....
Update the label of pod 'foo' with the key 'role' and the value 'frontend'
Command: ```bash kubectl label pods foo role=frontend ``` What it does: Update the labels on a resource. Syntax: `kubectl label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]` Helpful flags: "flag": "--all-namespaces", "short": "-A", "default": "false", "usage": "If ...
get resources by their type and names
Command: ```bash kubectl get rc/web service/email-service-rc pods/media-stream-pod ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is nam...
Execute the 'elasticsearch' command in the 'e-commerce-pod' pod and retrieve the output.
Command: ```bash kubectl exec e-commerce-pod -- elasticsearch ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kube...
Create a pod named 'hazelcast' using the 'alpine' image and have the container expose port 3306.
Command: ```bash kubectl run hazelcast --image=alpine --port=3306 ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args...]` Helpful flags: "flag": "--f...
Create a copy of the proxy-server-pod with a debug container and change the images of the existing containers
Command: ```bash kubectl debug proxy-server-pod -it --copy-to=my-custom-dbg --image=debian --set-image=cache=redis:alpine,app=app:debug ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and...
Update the node 'gpu-node-12' by partially merging in the JSON patch '{"spec":{"replicas":3}'
Command: ```bash kubectl patch node gpu-node-12 -p '{"spec":{"replicas":3}' ``` What it does: Update fields of a resource using strategic merge patch, a JSON merge patch, or a JSON patch. JSON and YAML formats are accepted. Syntax: `kubectl patch (-f FILENAME | TYPE NAME) [-p PATCH|--patch-file FILE]` Helpful flags:...
Get the output from running the 'mysql' command in the first pod of the 'search-service' service.
Command: ```bash kubectl exec svc/search-service -- mysql ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubectl....
Create a debug image of the cdn-service-pod with all container images changed to php
Command: ```bash kubectl debug cdn-service-pod --copy-to=debug-image-app --set-image=*=php ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used by default if no res...
Create a debug copy of vpn-service-pod
Command: ```bash kubectl debug vpn-service-pod -it --copy-to=debug-image-app --image=debian --set-image=logger=logging-app:debug,proxy=nginx:1.21 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by re...
Create a deployment named "api" that runs the "mongo" image with 4 replicas.
Command: ```bash kubectl create deployment api --image=mongo --replicas=4 ``` What it does: Create a deployment with the specified name. Syntax: `kubectl create deployment NAME --image=image -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: json...
Import the private key secret into the environment of the order-processing-deployment deployment
Command: ```bash kubectl set env --from=secret/private-key-secret deployment/order-processing-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one o...
create a job called 'indexing' using the 'centos' image and execute the 'bash' command within the job
Command: ```bash kubectl create job indexing --image=centos -- bash ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: js...
Create a cron job that runs a specific command
Command: ```bash kubectl create cronjob report-generation --image=mysql --schedule="*/1 * * * *" -- mysql --version ``` What it does: Create a cron job with the specified name. Syntax: `kubectl create cronjob NAME --image=image --schedule='0/5 * * * ?' -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "shor...
Import the CONFIG_FILE_PATH key from the kube-system-config config map and set it as an environment variable in the analytics-platform-deployment deployment.
Command: ```bash kubectl set env --keys=CONFIG_FILE_PATH --from=configmap/kube-system-config deployment/analytics-platform-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment ...
Create a new secret named api-secret-key using the files in the path/to/properties folder
Command: ```bash kubectl create secret generic api-secret-key --from-file=path/to/properties ``` What it does: Create a secret based on a file, directory, or specified literal value. A single secret may package one or more key/value pairs. When creating a secret based on a file, the key will default to the basename of...
Import the "redis_host" key from the "app-config-dev" config map to the environment variables of the "web-app-deployment" deployment.
Command: ```bash kubectl set env --keys=redis_host --from=configmap/app-config-dev deployment/web-app-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions ...
Forward traffic from port 9090 on all addresses to port 6379 in the pod named "proxy-server-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/proxy-server-pod 9090:6379 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod ...
Execute the command `apk add curl` inside the container `lunar-launcher` in the pod `email-service-pod`.
Command: ```bash kubectl exec email-service-pod -c lunar-launcher -- apk add curl ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If o...
Set the resource request and limits for all containers in the 'runtime' deployment
Command: ```bash kubectl set resources deployment runtime --limits=cpu=200m,memory=512Mi --requests=cpu=10,memory=4Gi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requeste...
Import specific keys from a config map into a deployment's environment variables.
Command: ```bash kubectl set env --keys=LOG_LEVEL --from=configmap/log-config deployment/backend-microservice-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defi...
List the replication controller named "web", the service named "log-aggregator-rc", and the pod named "proxy-server-pod".
Command: ```bash kubectl get rc/web service/log-aggregator-rc pods/proxy-server-pod ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is na...
Set the service account of the deployment "web-app-deployment" to "cert-manager"
Command: ```bash kubectl set serviceaccount deployment web-app-deployment cert-manager ``` What it does: Update the service account of pod template resources. Possible resources (case insensitive) can be: replicationcontroller (rc), deployment (deploy), daemonset (ds), job, replicaset (rs), statefulset Syntax: `kubec...
Apply a taint on nodes with a specific label
Command: ```bash kubectl taint node -l customer=acme-corp datacenter=app-node-6:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usa...
Create a copy of the 'analytics-pod' pod with a debug container and change the container images
Command: ```bash kubectl debug analytics-pod -it --copy-to=debug-image-1 --image=debian --set-image=database=mysql:5.7,logger=logging-app:debug ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by reso...
Rename the context 'on-prem-context' to 'user-b-context' in your kubeconfig file
Command: ```bash kubectl config rename-context on-prem-context user-b-context ``` What it does: Renames a context from the kubeconfig file. CONTEXT_NAME is the context name that you want to change. NEW_NAME is the new name you want to set. Note: If the context being renamed is the 'current-context', this field will al...
Display the replication controller named "web", the service named "vpn-service-rc", and the pod named "auth-service-pod"
Command: ```bash kubectl get rc/web service/vpn-service-rc pods/auth-service-pod ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is names...