prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Forward traffic from local port 8000 to port 6379 in the email-server-deployment pod selected by the deployment
Command: ```bash kubectl port-forward deployment/email-server-deployment 8000 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...
Copy the contents of '/var/run/secrets/kubernetes.io/serviceaccount/' from the pod 'image-resizer-pod-20' in the 'kube-server' namespace and extract it to the local '/etc/kubernetes' directory.
Command: ```bash kubectl exec -n kube-server image-resizer-pod-20 -- tar cf - /var/run/secrets/kubernetes.io/serviceaccount/ | tar xf - -C /etc/kubernetes ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "...
Create a copy of the api-service-pod with a debug container and change the container images
Command: ```bash kubectl debug api-service-pod -it --copy-to=debug-image-web --image=debian --set-image=proxy=nginx:1.21,web=nginx:latest ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource a...
create a job with a command to perform a deployment rollout
Command: ```bash kubectl create job deployment-rollout-job --image=wordpress -- apache2ctl -D FOREGROUND ``` 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": ""...
Create a debug container and change container images in a pod by using the kubectl debug command
Command: ```bash kubectl debug monitoring-pod -it --copy-to=debug-image-api --image=debian --set-image=mailer=mailer:latest,web=nginx:latest ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resourc...
Forward data between local ports 8888 and 6000, and the ports 8888 and 6000 of a pod selected by the 'notification-handler-deployment' deployment
Command: ```bash kubectl port-forward deployment/notification-handler-deployment 8888 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 ...
List the deployments in the "stable-2.0.0" version of the "api-v1" API group in YAML output format.
Command: ```bash kubectl get deployments.stable-2.0.0.api-v1 -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 wi...
Forward port 5432 from the mypod pod to a random port locally, and listen for incoming connections.
Command: ```bash kubectl port-forward pod/mypod :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 automatically. T...
Create a new ClusterIP service named 'cache-service-clusterip' that forwards requests from port 8000 to port 8088
Command: ```bash kubectl create service clusterip cache-service-clusterip --tcp=8000:8088 ``` 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", ...
Switch to raw terminal mode for the analytics-pod, specifically for the stardust-shuttle container
Command: ```bash kubectl attach analytics-pod -c stardust-shuttle -i -t ``` 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 ...
Create an ingress resource called 'internal-ingress' with a rule that directs requests from testing.com/input to svc1:8089
Command: ```bash kubectl create ingress internal-ingress --rule="testing.com/input=svc1:8089,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": "", "u...
Create a service for the 'centos' deployment, which serves on port 8081 and connects to the containers on port 543200.
Command: ```bash kubectl expose deployment centos --port=8081 --target-port=543200 ``` 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 specifi...
Set exec auth plugin environment variables for "dev-user" entry
Command: ```bash kubectl config set-credentials dev-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 Bear...
List the resource(s) of a specific type and name(s)
Command: ```bash kubectl get rc/web service/monitoring-rc pods/monitoring-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 namespac...
Create a new config map named app-name-config with specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap app-name-config --from-file=conf=/path/to/configs/file1.txt --from-file=data=/path/to/configurations/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...
Forward traffic from local port 8000 to port 5432 in the pod named "mypod"
Command: ```bash kubectl port-forward pod/mypod 8000 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...
Check if you have permission to list the job named "certificates-renewal-job" in the "kube-dns" namespace.
Command: ```bash kubectl auth can-i list jobs.batch/certificates-renewal-job -n kube-dns ``` 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 part...
Add a taint with key 'datacenter' on nodes having label version=v1.0.0
Command: ```bash kubectl taint node -l version=v1.0.0 datacenter=db-node-7: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": ...
Update the annotation of pod 'payment' with the key 'scaling-policy' and the value 'auto-horizontal-scaling'
Command: ```bash kubectl annotate pods payment scaling-policy=auto-horizontal-scaling ``` 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...
Add a taint with the key 'cpu-type' on nodes that have the label 'cluster=my-cluster'
Command: ```bash kubectl taint node -l cluster=my-cluster cpu-type=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": "", "...
Add an annotation to the pod named 'vpn'
Command: ```bash kubectl annotate pods vpn last-deployment=2023-03-15 ``` 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...
Retrieve information about the ReplicationController 'web', the Service 'frontend-rc', and the pod 'web-app-pod'
Command: ```bash kubectl get rc/web service/frontend-rc pods/web-app-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...
Copy the local file /tmp/foo_dir to the /etc/kubernetes directory in the logging-agent-pod-7 pod, specifically to the ingress-controller container.
Command: ```bash kubectl cp /tmp/foo_dir logging-agent-pod-7:/etc/kubernetes -c ingress-controller ``` 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. I...
Create a new config map with specified keys for configuration and parameters files
Command: ```bash kubectl create configmap env-vars --from-file=conf=/path/to/configurations/file1.txt --from-file=data=/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...
Start a new pod named "hazelcast" with the mongo image and expose port 3001
Command: ```bash kubectl run hazelcast --image=mongo --port=3001 ``` 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": "--fi...
Scale the replica set 'prod-app-rs' to 1 replica
Command: ```bash kubectl scale --replicas=1 rs/prod-app-rs ``` What it does: Set a new size for a deployment, replica set, replication controller, or stateful set. Scale also allows users to specify one or more preconditions for the scale action. If --current-replicas or --resource-version is specified, it is validate...
Forward local port 8088 to port 8888 in the pod named "web-app-pod"
Command: ```bash kubectl port-forward pod/web-app-pod 8088: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 be selected automa...
Import the api_key key from the kube-system-config config map into the environment variables of the backend-microservice-deployment deployment.
Command: ```bash kubectl set env --keys=api_key --from=configmap/kube-system-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 variabl...
Begin streaming the logs of the "warp-drive" container in the "mypod" pod.
Command: ```bash kubectl logs -f -c warp-drive mypod ``` 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...
Forward traffic from port 8888 on all addresses to port 8080 in the 'frontend-pod' pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/frontend-pod 8888: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...
Create a pod named "hazelcast" using the image "confluentinc/cp-kafka" and expose port 8081.
Command: ```bash kubectl run hazelcast --image=confluentinc/cp-kafka --port=8081 ``` 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 flag...
Add a taint with key 'app' and value 'k8s-node-1:PreferNoSchedule' on the nodes labeled with zone=us-east-1
Command: ```bash kubectl taint node -l zone=us-east-1 app=k8s-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": "Outpu...
Set the cluster field in a specific context to a specific cluster
Command: ```bash kubectl config set contexts.app-2-context.cluster prod-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 wa...
Forward local port 9090 to port 9090 in the specified deployment.
Command: ```bash kubectl port-forward deployment/search-engine-deployment 9090 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...
Get the output of the 'go version' command in the cyber-sleuth container of the email-service-pod pod
Command: ```bash kubectl exec email-service-pod -c cyber-sleuth -- go 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 omitt...
Create a deployment named "worker" with the "php" image, and expose port 8888.
Command: ```bash kubectl create deployment worker --image=php --port=8888 ``` 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 'log_level' key from the 'app-settings' ConfigMap and set it as an environment variable in the 'backend-microservice-deployment' deployment.
Command: ```bash kubectl set env --keys=log_level --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 de...
Forward traffic from port 8888 on localhost and IP address 10.19.21.23 to port 5000 in the mypod pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/mypod 8888: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 p...
Import specific keys from a config map to an environment variable in a deployment
Command: ```bash kubectl set env --keys=DEBUG_MODE --from=configmap/kube-system-config deployment/log-aggregator-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 d...
Copy the file "/var/run/secrets/kubernetes.io/serviceaccount/" from your local machine to the "/tmp/bar" path within the "security-scanner-pod-18" pod
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ security-scanner-pod-18:/tmp/bar -c backend-container ``` 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": "...
Create a new secret named git-credentials-secret from an environment file
Command: ```bash kubectl create secret generic git-credentials-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 t...
Create a new ClusterIP service named 'messaging-service-clusterip' that maps port 5001 of the service to port 8000 of the pods
Command: ```bash kubectl create service clusterip messaging-service-clusterip --tcp=5001:8000 ``` 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": "-...
List the replication controller named 'web', the service replication controller named 'cdn-service-rc', and the pod named 'analytics-pod'.
Command: ```bash kubectl get rc/web service/cdn-service-rc pods/analytics-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 namespac...
Attach to the first pod in a replica set named "node" and view its output
Command: ```bash kubectl attach rs/node ``` 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, use the kubectl.kuberne...
Set the custom TLS server name to 'cluster-alpha' for the 'dev-cluster' cluster entry
Command: ```bash kubectl config set-cluster dev-cluster --tls-server-name=cluster-alpha ``` 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] [--certificate...
Set the CPU limit of the nginx container in the redis deployment to "50m" and the memory limit to "1Gi"
Command: ```bash kubectl set resources deployment redis -c=nginx --limits=cpu=50m,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 it...
Configure the TLS server name for cluster-alpha in the Kubernetes config file.
Command: ```bash kubectl config set-cluster cluster-alpha --tls-server-name=cluster-beta ``` 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...
Delete the pods and services with the names "chat-app" and "backend"
Command: ```bash kubectl delete pod,service chat-app backend ``` 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...
View only the most recent 5 lines of logs for a pod named chat-app-pod
Command: ```bash kubectl logs --tail=5 chat-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"...
Auto scale the deployment "analytics" with a minimum of 2 pods and a maximum of 9 pods
Command: ```bash kubectl autoscale deployment analytics --min=2 --max=9 ``` 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 use...
Create a single ingress called 'api-v1-ingress' that directs requests to testing.com/input to the svc1 service on port 27017, with the TLS secret "my-cert"
Command: ```bash kubectl create ingress api-v1-ingress --rule="testing.com/input=svc1:27017,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": "", "us...
Start streaming the logs of the "lunar-launcher" container in the "gateway-pod" pod
Command: ```bash kubectl logs -f -c lunar-launcher gateway-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", "s...
Update the 'log-aggregator-deployment' deployment by adding a new environment variable named ENV with the value of prod.
Command: ```bash kubectl set env deployment/log-aggregator-deployment ENV=prod ``` 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 (with...
Create a new LoadBalancer service named monitoring-lb that forwards TCP traffic from port 5000 to port 8000
Command: ```bash kubectl create service loadbalancer monitoring-lb --tcp=5000:8000 ``` 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", "defa...
Import the 'MAX_CONNECTIONS' key from the 'app-secrets' ConfigMap and set it as an environment variable for the 'notification-handler-deployment' deployment.
Command: ```bash kubectl set env --keys=MAX_CONNECTIONS --from=configmap/app-secrets deployment/notification-handler-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 variab...
Create a new ConfigMap named ui-config with specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap ui-config --from-file=conf=/path/to/profiles/file1.txt --from-file=data=/path/to/configurations/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 ...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=api_key --from=configmap/kube-system-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 d...
Forward traffic from local port 8888 to port 8088 on the pod
Command: ```bash kubectl port-forward pod/mypod 8888: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 selected automaticall...
Execute the 'nginx' command in the 'proxy-service-pod' pod and retrieve the output from the first container.
Command: ```bash kubectl exec proxy-service-pod -- nginx ``` 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.k...
Create a copy of the "monitoring-pod" pod and add a debug container, then change the container images.
Command: ```bash kubectl debug monitoring-pod -it --copy-to=dgb-img --image=debian --set-image=app=app:debug,mailer=mailer:latest ``` 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....
Create a copy of a pod named "log-aggregator-pod" by adding a debug container and changing the container images
Command: ```bash kubectl debug log-aggregator-pod -it --copy-to=debug-image-api --image=debian --set-image=app=app:debug,api=api:v2 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and nam...
Create a service for the replicated php deployment that serves on port 3000 and connects to the containers on port 543200.
Command: ```bash kubectl expose rc php --port=3000 --target-port=543200 ``` 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 ...
Add a taint with the key 'hardware' and value 'dev-node-4:PreferNoSchedule' on nodes with the label instance=app-instance-1.
Command: ```bash kubectl taint node -l instance=app-instance-1 hardware=dev-node-4: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": "", "...
Forward port 5000 on all addresses to port 8081 in the pod named "proxy-server-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/proxy-server-pod 5000:8081 ``` 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 ...
Start a pod named hazelcast using the python image, and ensure it exposes port 8082
Command: ```bash kubectl run hazelcast --image=python --port=8082 ``` 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...
Taint the nodes with the key 'zone' that have the label 'customer=acme-corp'
Command: ```bash kubectl taint node -l customer=acme-corp zone=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": "Outp...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=secret_key --from=configmap/app-settings 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...
Forward local port 6379 to port 5432 in the pod named "log-aggregator-pod"
Command: ```bash kubectl port-forward pod/log-aggregator-pod 6379: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...
Partially update the edge-node-10 node by setting the unschedulable field to true using a strategic merge patch in JSON format.
Command: ```bash kubectl patch node edge-node-10 -p '{"spec":{"unschedulable":true}}' ``` 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]` Help...
Copy the file '/tmp/foo' from the remote pod 'argocd/logging-agent-pod-7' to the local directory '/tmp/bar'
Command: ```bash kubectl cp argocd/logging-agent-pod-7:/tmp/foo :/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 the kubect...
Attach to the first pod of a replica set named "go" to get the output
Command: ```bash kubectl attach rs/go ``` 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, use the kubectl.kubernete...
Forward traffic from local ports 9090 to the 'email-server-deployment' pods' port 5000
Command: ```bash kubectl port-forward deployment/email-server-deployment 9090 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...
Set the service account of the deployment "monitoring-stack-deployment" to "gitlab-runner"
Command: ```bash kubectl set serviceaccount deployment monitoring-stack-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 Synt...
Change the default editor to "code" and edit the "notification-service" service.
Command: ```bash KUBE_EDITOR="code" kubectl edit svc/notification-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 vari...
List deployments in YAML output format for the specific version of a custom API group.
Command: ```bash kubectl get deployments.custom-version.testing-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 namespace...
Create a new ClusterIP service named 'inventory-service-clusterip' that maps port 8443 of the service to port 8010 of the backend pods.
Command: ```bash kubectl create service clusterip inventory-service-clusterip --tcp=8443:8010 ``` 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": "-...
Update the pod named 'vpn' with the annotation 'team' and the value 'frontend team'.
Command: ```bash kubectl annotate pods vpn team='frontend team' ``` 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 arbitrary str...
Check if you have permission to list the "queue-processing-job" job in the "kube-dns" namespace
Command: ```bash kubectl auth can-i list jobs.batch/queue-processing-job -n kube-dns ``` 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 ...
import the environment variables from the 'gcp-service-account-secret' secret and apply them to the 'proxy-service-deployment' deployment
Command: ```bash kubectl set env --from=secret/gcp-service-account-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 ...
Create a new pod running Ruby and expose port 8084
Command: ```bash kubectl run hazelcast --image=ruby --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: "flag": "--fil...
Begin streaming the logs of the cosmic-container container in the proxy-server-pod pod.
Command: ```bash kubectl logs -f -c cosmic-container proxy-server-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": "--contain...
Inject the environment variables from the secret "ssl-key-secret" into the "log-aggregator-deployment" deployment.
Command: ```bash kubectl set env --from=secret/ssl-key-secret deployment/log-aggregator-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 more...
Create an ingress called 'api-v2-ingress' that directs requests to 'foo.com/bar' to a service named 'svc1' on port 8080, and use a TLS secret named 'my-cert'.
Command: ```bash kubectl create ingress api-v2-ingress --rule="foo.com/bar=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": "", "usage": "...
Attach to the 'cdn-service-pod' and get the output from the 'quantum-quark' container
Command: ```bash kubectl attach cdn-service-pod -c quantum-quark ``` 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...
Create an ingress named 'web-ingress' that maps requests from the path '/bar' of site.com to the service 'svc1' running on port 7000
Command: ```bash kubectl create ingress web-ingress --rule="site.com/bar=svc1:7000,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": "Ou...
Create a deployment named "auth" using the hazelcast image with 7 replicas
Command: ```bash kubectl create deployment auth --image=hazelcast/hazelcast --replicas=7 ``` 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 forma...
Create a pod disruption budget named 'worker-pdb' that will select all pods with the 'tier=frontend' label and require a minimum of 9 of them to be available at any point in time
Command: ```bash kubectl create poddisruptionbudget worker-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 [--dr...
Import the 'config_file_path' key from the 'ui-config' ConfigMap and set it as an environment variable for the 'authentication-service-deployment' deployment.
Command: ```bash kubectl set env --keys=config_file_path --from=configmap/ui-config 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 varia...
Partially update the web-node-8 node using a strategic merge patch specified in JSON
Command: ```bash kubectl patch node web-node-8 -p '{"data":{"key":"new-value"}' ``` 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 fl...
Forward traffic from local port 3000 to port 8080 of the selected pod in the deployment "search-engine-deployment"
Command: ```bash kubectl port-forward deployment/search-engine-deployment 3000 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 wil...
Update the 'media-stream' pod by adding or modifying the 'owner' annotation to have the value 'alice smith'
Command: ```bash kubectl annotate pods media-stream owner='alice smith' ``` 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 arbit...
Update the annotation "git-repo" of a pod identified by type and name in the "docker-registry.yaml" file.
Command: ```bash kubectl annotate -f docker-registry.yaml 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 large...
Get the output from running the 'redis-cli' command on a specific pod.
Command: ```bash kubectl exec mypod -- 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.kubernete...
Update the pod named 'proxy' with the annotation 'description' and the value 'Web server for marketing site' by running the command kubectl annotate pods proxy description='Web server for marketing site'.
Command: ```bash kubectl annotate pods proxy description='Web server for marketing site' ``` 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 ...
Create a new config map named `api-config` and populate it with specific keys and their corresponding file paths
Command: ```bash kubectl create configmap api-config --from-file=properties=/path/to/profiles/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 creating a...
Create a pod disruption budget named logging-pdb that will select all pods with the version=v2 label and require a minimum of 9 of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget logging-pdb --selector=version=v2 --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 [--dry-...
list the replication controller named "web", the service named "frontend", and the pod named "email-service"
Command: ```bash kubectl get rc/web service/frontend-rc pods/email-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 namespa...
Retrieve the output from running the 'geth attach' command in the first container of the first pod of the 'mydeployment' deployment.
Command: ```bash kubectl exec deploy/mydeployment -- geth attach ``` 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 k...
update the password for the node specified in "node-settings.json" using a strategic merge patch
Command: ```bash kubectl patch -f node-settings.json -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-fil...
Create a copy of the payment-gateway-pod and change all container images to Python for debugging purposes.
Command: ```bash kubectl debug payment-gateway-pod --copy-to=debug-image-api --set-image=*=python ``` 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...