prompt
stringlengths
13
282
response
stringlengths
128
3.11k
import the 'log_level' key from the 'app-config-dev' config map and set it as environment variable in the 'frontend-deployment' deployment
Command: ```bash kubectl set env --keys=log_level --from=configmap/app-config-dev 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 ...
Partially update a node by applying a strategic merge patch, using a JSON patch.
Command: ```bash kubectl patch node app-node-6 -p '{"spec":{"containers":[{"name":"container-name", "resources":{"limits":{"cpu":"200m"}}}]}' ``` 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 F...
Forward ports 3000 and 6000 locally to ports 3000 and 6000 in the pod named "chat-app-pod"
Command: ```bash kubectl port-forward pod/chat-app-pod 3000 3000 ``` 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 autom...
Add a taint with key 'hardware' on nodes having label cluster=my-cluster
Command: ```bash kubectl taint node -l cluster=my-cluster hardware=prod-node-5: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": "", "usag...
Execute the 'redis-cli' command inside the 'gateway-pod' pod and get the output
Command: ```bash kubectl exec gateway-pod -- redis-cli ``` 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.kub...
Listen on port 8081 on all addresses, forwarding to port 8080 in the security-service-pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/security-service-pod 8081: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 ...
Forward traffic from localhost port 3000 to the analytics-pod pod's port 3000, listening on all addresses (0.0.0.0)
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/analytics-pod 3000:3000 ``` 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 "php --version" in the container "rocket-ranger" from the pod "web-app-pod" and get the output.
Command: ```bash kubectl exec web-app-pod -c rocket-ranger -- php --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...
Create a new config map named namespace-config with specified keys and their corresponding values from specified files
Command: ```bash kubectl create configmap namespace-config --from-file=conf=/path/to/profiles/file1.txt --from-file=data=/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 con...
Return a snapshot of the previous terminated logs from the "warp-drive" container in the "frontend-pod" pod.
Command: ```bash kubectl logs -p -c warp-drive frontend-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", "shor...
Set the environment variables DATABASE_URL from the log-config config map for the monitoring-stack-deployment deployment.
Command: ```bash kubectl set env --keys=DATABASE_URL --from=configmap/log-config deployment/monitoring-stack-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 defin...
Create a new secret named payment-gateway-secret with keys for each file in folder bar
Command: ```bash kubectl create secret generic payment-gateway-secret --from-file=path/to/preferences ``` 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 ba...
Listen on port 8000 locally, and forward data to/from port 9090 in the mypod pod
Command: ```bash kubectl port-forward pod/mypod 8000 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 will be selected automaticall...
List the deployments in YAML output format, specifically in the "legacy-1.0.0" version of the "alpha-apps" API group
Command: ```bash kubectl get deployments.legacy-1.0.0.alpha-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...
Return the snapshot logs from the container "mypod-1" of the deployment named "mydeployment"
Command: ```bash kubectl logs deployment/mydeployment -c mypod-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": "--container", ...
Set a taint with the key 'zone' on nodes that have the label 'instance=app-instance-1', and the taint value 'zone=monitoring-node-15:PreferNoSchedule'
Command: ```bash kubectl taint node -l instance=app-instance-1 zone=monitoring-node-15: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": "...
Create a cluster role named "foo" with the following permissions and resource names:
Command: ```bash kubectl create clusterrole foo --verb=list --resource=services --resource-name=error-logger --resource-name=monitoring-prometheus ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|cl...
Create a new ClusterIP service named my-cs with a TCP port mapping of 8089 to 9000.
Command: ```bash kubectl create service clusterip my-cs --tcp=8089:9000 ``` What it does: Create a ClusterIP service with the specified name. Syntax: `kubectl create service clusterip NAME [--tcp=<port>:<targetPort>] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "us...
Update the container images for a deployment
Command: ```bash kubectl set image deployment/centos busybox=busybox centos=centos:8.4.2105 ``` What it does: Update existing container image(s) of resources. Possible resources include (case insensitive): pod (po), replicationcontroller (rc), deployment (deploy), daemonset (ds), statefulset (sts), cronjob (cj), repli...
Create an ingress named 'ingress1' in the default class, with two rules
Command: ```bash kubectl create ingress ingress1 --class=default \ --rule="foo.com/path*=svc:7000" \ --rule="example.com/admin*=svc2:http" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output",...
Check if the current user has permission to list the job named "data-migration-job" in the "monitoring" namespace
Command: ```bash kubectl auth can-i list jobs.batch/data-migration-job -n monitoring ``` What it does: Check whether an action is allowed. VERB is a logical Kubernetes API verb like 'get', 'list', 'watch', 'delete', etc. TYPE is a Kubernetes resource. Shortcuts and groups will be resolved. NONRESOURCEURL is a partial ...
Copy the local directory '/tmp/foo_dir' to the remote pod 'task-processor-pod-17' in the default namespace, with the destination directory '/tmp/bar_dir'
Command: ```bash kubectl cp :/tmp/foo_dir task-processor-pod-17:/tmp/bar_dir ``` 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, use the kub...
Create a new config map named app-name-config, providing values for specified keys
Command: ```bash kubectl create configmap app-name-config --from-file=properties=/path/to/configs/file1.txt --from-file=key1=/path/to/settings/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 creati...
Set the service account of the deployment "frontend-deployment" to "jenkins"
Command: ```bash kubectl set serviceaccount deployment frontend-deployment jenkins ``` 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: `kubectl s...
Forward traffic from port 8088 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 8088: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 ...
Forward port 8081 on all addresses to port 6379 in the web-app-pod pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/web-app-pod 8081: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 will ...
Delete the "my-k8s-cluster" cluster from the kubectl configuration
Command: ```bash kubectl config delete-cluster my-k8s-cluster ``` What it does: Delete the specified cluster from the kubeconfig. Syntax: `kubectl config delete-cluster NAME`
Start a hazelcast pod using the ethereum/client-go image and expose port 8084
Command: ```bash kubectl run hazelcast --image=ethereum/client-go --port=8084 ``` 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: ...
Execute the 'php --version' command inside the first container of the 'payment-service' service, and retrieve the output.
Command: ```bash kubectl exec svc/payment-service -- php --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 the...
Import specific keys from a config map to an environment variable in a deployment.
Command: ```bash kubectl set env --keys=REDIS_HOST --from=configmap/app-secrets 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 one or...
Set a custom TLS server name for the my-k8s-cluster cluster entry
Command: ```bash kubectl config set-cluster my-k8s-cluster --tls-server-name=dev-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] [--certificat...
undo the last deployment of the specified deployment
Command: ```bash kubectl rollout undo deployment/test ``` What it does: Roll back to a previous rollout. Syntax: `kubectl rollout undo (TYPE NAME | TYPE/NAME) [flags]` Helpful flags: "flag": "--filename", "short": "-f", "default": "[]", "usage": "Filename, directory, or URL to files identifying the resource to get f...
View the resource usage metrics for a specific node
Command: ```bash kubectl top node monitoring-node-15 ``` 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": "Sele...
Create a single ingress called 'public-api-ingress' that directs requests to testing.com/input to svc1 on port 8081, with a tls secret named "my-cert"
Command: ```bash kubectl create ingress public-api-ingress --rule="testing.com/input=svc1:8081,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", ...
Execute the 'python' command in the 'cosmic-container' from the 'security-service-pod' pod and get the output.
Command: ```bash kubectl exec security-service-pod -c cosmic-container -- python ``` 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 om...
Add a taint on nodes with the label "team=devops" using the key "hardware" and the value "gpu-node-12" with the effect "PreferNoSchedule".
Command: ```bash kubectl taint node -l team=devops hardware=gpu-node-12: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": "Ou...
Copy the directory '/tmp/foo_dir' from the remote pod 'kube-public/payment-gateway-pod-19' to the local directory '/tmp/bar'
Command: ```bash kubectl cp kube-public/payment-gateway-pod-19:/tmp/foo_dir /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, use...
Retrieve the output of the 'composer --version' command from the cosmic-container running in the auth-service-pod.
Command: ```bash kubectl exec auth-service-pod -c cosmic-container -- composer --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 nam...
Create an ingress named 'app-ingress' that routes requests from testing.com/input to svc1:5001 with a TLS secret named "my-cert"
Command: ```bash kubectl create ingress app-ingress --rule="testing.com/input=svc1:5001,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage"...
Listen on port 5432 locally and forward it to port 8080 in the 'web-app-pod' pod
Command: ```bash kubectl port-forward pod/web-app-pod 5432: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 pod will be selected automa...
List deployments in YAML output format, using the specific version of the "my-apps" API group
Command: ```bash kubectl get deployments.v3.0.0.my-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 you will on...
Create a cluster role named "custom_role" with the permission to get the "configmaps" resource, specifically the "billing-service" and "auth-service" resources.
Command: ```bash kubectl create clusterrole custom_role --verb=get --resource=configmaps --resource-name=billing-service --resource-name=auth-service ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server...
List the replication controller "web", service "proxy-service-rc", and pod "vpn-service-pod"
Command: ```bash kubectl get rc/web service/proxy-service-rc pods/vpn-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 name...
Forward local port 8080 to pod port 8088
Command: ```bash kubectl port-forward pod/security-service-pod 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 will be select...
Set a custom TLS server name for the "data-cluster" cluster entry
Command: ```bash kubectl config set-cluster data-cluster --tls-server-name=galaxy-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] [--certifica...
Get the output of the 'pip --version' command from the 'log-aggregator-pod' pod in the 'time-machine' container.
Command: ```bash kubectl exec log-aggregator-pod -c time-machine -- pip --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 o...
Create a cron job named 'cron-task' using the image 'redis', with a schedule of running every minute, and execute the command 'redis-server'
Command: ```bash kubectl create cronjob cron-task --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": "-o", "...
Forward port 6379 on all addresses to port 8888 in the chat-app-pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/chat-app-pod 6379:8888 ``` 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 the environment variables from the 'email-credentials-secret' secret and set them for the 'order-processing-deployment' deployment.
Command: ```bash kubectl set env --from=secret/email-credentials-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...
Forward local port to pod's port.
Command: ```bash kubectl port-forward pod/security-service-pod 5432: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 criteria, a pod will be select...
Add a taint with the key 'zone' and value 'app-node-6:PreferNoSchedule' on nodes that have the label 'stack=tech-stack'
Command: ```bash kubectl taint node -l stack=tech-stack zone=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": "", "usage": "Ou...
Create a new config map named app-config-prod and populate it with the contents of the files "file1.txt" and "file2.txt"
Command: ```bash kubectl create configmap app-config-prod --from-file=properties=/path/to/configurations/file1.txt --from-file=key1=/path/to/properties/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. Wh...
create a job named 'security-scan-job' using the image 'mcr.microsoft.com/dotnet/core/runtime', and execute the command 'dotnet --list-sdks'
Command: ```bash kubectl create job security-scan-job --image=mcr.microsoft.com/dotnet/core/runtime -- dotnet --list-sdks ``` 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": "-...
Set the criticality annotation to "high" for the pod specified in the "parameters.json" file.
Command: ```bash kubectl annotate -f parameters.json 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 arbitra...
List all deployments in the "custom-version" version of the "sandbox-apps" API group in JSON format.
Command: ```bash kubectl get deployments.custom-version.sandbox-apps -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 namespace...
Create a debug copy of proxy-service-pod with all container images changed to "ethereum/client-go"
Command: ```bash kubectl debug proxy-service-pod --copy-to=debug-image-1 --set-image=*=ethereum/client-go ``` 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 de...
Import the 'MAX_CONNECTIONS' key from the 'app-settings' config map and set it as an environment variable for the 'database-deployment' deployment.
Command: ```bash kubectl set env --keys=MAX_CONNECTIONS --from=configmap/app-settings deployment/database-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 definiti...
Delete the pods and services named "monitoring" and "foo"
Command: ```bash kubectl delete pod,service monitoring foo ``` What it does: Delete resources by file names, stdin, resources and names, or by resources and label selector. JSON and YAML formats are accepted. Only one type of argument may be specified: file names, resources and names, or resources and label selector. ...
Create a new ExternalName service named 'external-ldap-service' with the external name 'travel-sample.travel'
Command: ```bash kubectl create service externalname external-ldap-service --external-name travel-sample.travel ``` What it does: Create an ExternalName service with the specified name. ExternalName service references to an external DNS address instead of only pods, which will allow application authors to reference se...
Forward local port 8080 to port 8080 in the web-app-pod
Command: ```bash kubectl port-forward pod/web-app-pod 8080: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 pod will be selected automa...
Partially update the node using a strategic merge patch
Command: ```bash kubectl patch -f node-config.toml -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 fla...
Get the output from running the 'redis-server' command in the 'cyber-sleuth' container of the 'vpn-service-pod' pod.
Command: ```bash kubectl exec vpn-service-pod -c cyber-sleuth -- redis-server ``` 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 omitt...
Retrieve the snapshot logs from the container "cdn-service-pod-1" of the deployment "payment-processor-deployment".
Command: ```bash kubectl logs deployment/payment-processor-deployment -c cdn-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 flag...
Create a pod named "hazelcast" using the "ruby" image and configure the container to expose port 9092.
Command: ```bash kubectl run hazelcast --image=ruby --port=9092 ``` 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": "--fil...
Execute the command `kubectl exec vpn-service-pod -c cyber-sleuth -- docker run ubuntu echo "Hello, World"` to run the `docker run ubuntu echo "Hello, World"` command inside the `cyber-sleuth` container of the `vpn-service-pod` pod
Command: ```bash kubectl exec vpn-service-pod -c cyber-sleuth -- docker run ubuntu echo "Hello, World" ``` 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": ...
Forward local traffic from port 3000 to port 6379 in the pod named "api-service-pod"
Command: ```bash kubectl port-forward pod/api-service-pod 3000 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 will be selected au...
Execute the 'wp' command inside the 'nebula-navigator' container of the 'monitoring-pod' pod.
Command: ```bash kubectl exec monitoring-pod -c nebula-navigator -- wp ``` 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...
Set the service account of the deployment "web-app-deployment" to "gitlab-runner"
Command: ```bash kubectl set serviceaccount deployment web-app-deployment gitlab-runner ``` 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: `kube...
create a pod using the provided configuration file
Command: ```bash kubectl create -f ./config.json ``` What it does: Create a resource from a file or from stdin. JSON and YAML formats are accepted. Syntax: `kubectl create -f FILENAME` Helpful flags: "flag": "--filename", "short": "-f", "default": "[]", "usage": "Filename, directory, or URL to files to use to create...
Create a new config map named 'db-config' using the specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap db-config --from-file=properties=/path/to/data/file1.txt --from-file=key1=/path/to/parameters/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 co...
Update the 'password' field for the node 'node-1' using a strategic merge patch with the new value as 'new-password'
Command: ```bash kubectl patch node node-1 -p '{"stringData":{"password":"new-password"}' ``` 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]` ...
Expose the replica set named centos as a service on port 3001, with the containers being accessed on port 637900.
Command: ```bash kubectl expose rs centos --port=3001 --target-port=637900 ``` 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....
Copy /tmp/foo_dir from a remote pod to /tmp/bar locally
Command: ```bash kubectl cp logging/ingress-controller-pod-8:/tmp/foo_dir /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, use t...
Remove all the taints with the key 'workload' from the node 'node-2'
Command: ```bash kubectl taint nodes node-2 workload- ``` 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: json|yaml|name|...
Rename the context 'dev-context' to 'team-alpha-context' in your kubeconfig file
Command: ```bash kubectl config rename-context dev-context team-alpha-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...
Import environment variables from a secret to a deployment
Command: ```bash kubectl set env --from=secret/azure-storage-secret deployment/proxy-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 variable definitions in one or...
Create a new config map named monitoring-config with specified keys from file paths
Command: ```bash kubectl create configmap monitoring-config --from-file=conf=/path/to/preferences/file1.txt --from-file=data=/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...
Create a service for the replicated nginx, which serves on port 80 and connects to the containers on port 8000.
Command: ```bash kubectl expose rc nginx --port=3001 --target-port=500000 ``` 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. ...
Create a deployment named 'grafana' using the 'alpine' image and expose port 9090
Command: ```bash kubectl create deployment grafana --image=alpine --port=9090 ``` 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: ...
Embed certificate authority data for the web-cluster cluster entry
Command: ```bash kubectl config set-cluster web-cluster --embed-certs --certificate-authority=~/.kube/dev-cluster/kubernetes.ca.crt ``` 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-c...
Delete the pods and services with the names "security" and "security"
Command: ```bash kubectl delete pod,service security security ``` What it does: Delete resources by file names, stdin, resources and names, or by resources and label selector. JSON and YAML formats are accepted. Only one type of argument may be specified: file names, resources and names, or resources and label selecto...
Create a NodePort service named "e-commerce-nodeport"
Command: ```bash kubectl create service nodeport e-commerce-nodeport --tcp=8082:8089 ``` What it does: Create a NodePort service with the specified name. Syntax: `kubectl create service nodeport NAME [--tcp=port:targetPort] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "default": ...
Retrieve the replication controller 'web', the service 'payment-gateway-rc', and the pod 'backend-pod'
Command: ```bash kubectl get rc/web service/payment-gateway-rc pods/backend-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 namesp...
Use a different editor to edit the configuration of a service
Command: ```bash KUBE_EDITOR="nvim" kubectl edit svc/analytics-service ``` What it does: Edit a resource from the default editor. The edit command allows you to directly edit any API resource you can retrieve via the command-line tools. It will open the editor defined by your KUBE_EDITOR, or EDITOR environment variabl...
create an ingress named 'app-gateway-ingress' with a rule that directs requests from testing.com/module to svc1:3000, using the tls secret "my-cert"
Command: ```bash kubectl create ingress app-gateway-ingress --rule="testing.com/module=svc1:3000,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": ""...
Add a taint with the key 'workload' and value 'testing-node-11:PreferNoSchedule' on nodes that have the label 'tier=frontend'
Command: ```bash kubectl taint node -l tier=frontend workload=testing-node-11: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...
Create a pod disruption budget named "database-pdb" that selects pods with the label "component=web" and ensures that at least 9 of them are always available.
Command: ```bash kubectl create poddisruptionbudget database-pdb --selector=component=web --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 [--...
Import environment from a secret
Command: ```bash kubectl set env --from=secret/email-credentials-secret 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 variable definitions ...
Create a Pod Disruption Budget named notification-service-pdb that will select all pods with the component=web label and require at least 9 of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget notification-service-pdb --selector=component=web --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-ava...
Create a new ClusterIP service named api-service-clusterip that maps port 3001 on the service to port 6379 on the pods.
Command: ```bash kubectl create service clusterip api-service-clusterip --tcp=3001:6379 ``` What it does: Create a ClusterIP service with the specified name. Syntax: `kubectl create service clusterip NAME [--tcp=<port>:<targetPort>] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "d...
Forward local port 5000 to port 8000 in the 'frontend-pod' pod
Command: ```bash kubectl port-forward pod/frontend-pod 5000: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 criteria, a pod will be selected autom...
Set the environment variables "key1=val1" and "key2=val2" for the "security-user" entry in the exec auth plugin.
Command: ```bash kubectl config set-credentials security-user --exec-env=key1=val1 --exec-env=key2=val2 ``` 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...
Run the 'wp' command inside the backend-pod and display the output
Command: ```bash kubectl exec backend-pod -- wp ``` 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.kubernetes...
Get the output from running the 'postgres' command in the cosmic-container from the frontend-pod.
Command: ```bash kubectl exec frontend-pod -c cosmic-container -- postgres ``` 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,...
Forward local port 8080 to port 9090 in the chat-app-pod pod
Command: ```bash kubectl port-forward pod/chat-app-pod 8080: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 will be selected autom...
Create a cluster role binding called "view" that allows user1, user2, and group1 to view cluster resources.
Command: ```bash kubectl create clusterrolebinding view --clusterrole=view --user=user1 --user=user2 --group=group1 ``` What it does: Create a cluster role binding for a particular cluster role. Syntax: `kubectl create clusterrolebinding NAME --clusterrole=NAME [--user=username] [--group=groupname] [--serviceaccount=...
Create a cluster role named "reader" with the verb "exec" and the non-resource URL "/debug/core" specified.
Command: ```bash kubectl create clusterrole "reader" --verb=exec --non-resource-url=/debug/core ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "sh...
Create an ingress resource named 'app-loadbalancer-ingress' that directs requests from foo.com/input to the service named svc1, running on port 8080
Command: ```bash kubectl create ingress app-loadbalancer-ingress --rule="foo.com/input=svc1:8080,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": ""...
Listen on port 5432 on localhost and IP 10.19.21.23, and forward the traffic to port 8888 in the chat-app-pod pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/chat-app-pod 5432:8888 ``` 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 criter...
Delete pods and services with the names "media-stream" and "cdn"
Command: ```bash kubectl delete pod,service media-stream cdn ``` What it does: Delete resources by file names, stdin, resources and names, or by resources and label selector. JSON and YAML formats are accepted. Only one type of argument may be specified: file names, resources and names, or resources and label selector...