prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Forward local port 8080 to port 3000 in the pod selected by the database-deployment deployment
Command: ```bash kubectl port-forward deployment/database-deployment 8080 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 ...
Create a pod disruption budget called auth-service-pdb that will select all pods with the app=nginx label and require at least 70% of the selected pods to be available at any given time.
Command: ```bash kubectl create pdb auth-service-pdb --selector=app=nginx --min-available=70% ``` 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-run=server...
Remove all the taints with key 'dedicated' from node 'backup-node-14'
Command: ```bash kubectl taint nodes backup-node-14 dedicated- ``` 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|y...
Delete the pods and services with the names "cdn" and "web"
Command: ```bash kubectl delete pod,service cdn web ``` 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. Some re...
Forward local port 6379 and selected IP to port 8081 in the pod named "proxy-server-pod"
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/proxy-server-pod 6379: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 cr...
Update the 'key' value of the 'worker-node-3' node using a strategic merge patch. The new value should be 'new-value'.
Command: ```bash kubectl patch node worker-node-3 -p $'data:\n 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 fla...
Add a taint with key 'cpu-type' to nodes that have the label customer=acme-corp
Command: ```bash kubectl taint node -l customer=acme-corp cpu-type=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"...
get the pod in YAML format
Command: ```bash kubectl get -o yaml pod 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 you will only see resu...
Remove the taint with key 'zone' and effect 'PreferNoSchedule' from the node 'edge-node-10'.
Command: ```bash kubectl taint nodes edge-node-10 zone: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": "Output format. One ...
Execute the 'sleep 3600' command in the lunar-launcher container of the proxy-server-pod and get the output.
Command: ```bash kubectl exec proxy-server-pod -c lunar-launcher -- 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": "Container name. If omit...
Forward local port 8081 to port 8088 in the pod named "chat-app-pod"
Command: ```bash kubectl port-forward pod/chat-app-pod 8081 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 autom...
Forward local port to pod's port on Kubernetes cluster
Command: ```bash kubectl port-forward pod/log-aggregator-pod 8081: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 will be selected...
Import the 'SMTP_SERVER' key from the 'app-settings' ConfigMap into the 'database-deployment' Deployment.
Command: ```bash kubectl set env --keys=SMTP_SERVER --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 definitions ...
Create a new NodePort service named api-service-nodeport with TCP port mapping from 8083 to 8010.
Command: ```bash kubectl create service nodeport api-service-nodeport --tcp=8083:8010 ``` 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":...
Import the 'external_api_url' key from the 'api-config' ConfigMap into the 'mydeployment' Deployment
Command: ```bash kubectl set env --keys=external_api_url --from=configmap/api-config 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...
Forward local port 6379 to port 5000 in the pod
Command: ```bash kubectl port-forward pod/mypod 6379: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 be selected automaticall...
Create a pod disruption budget named frontend-pdb that selects all pods with the role=worker label and requires at least 9 of them being available at any point in time
Command: ```bash kubectl create poddisruptionbudget frontend-pdb --selector=role=worker --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...
Attach to the code-explorer container in the analytics-pod to get its output
Command: ```bash kubectl attach analytics-pod -c code-explorer ``` 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 a debug copy of the monitoring-pod with all container images changed to amazonlinux.
Command: ```bash kubectl debug monitoring-pod --copy-to=debug-image-web --set-image=*=amazonlinux ``` 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...
Create a deployment named gateway using the alpine image and expose port 5001
Command: ```bash kubectl create deployment gateway --image=alpine --port=5001 ``` 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: ...
Create a job named "indexing" using the nginx image, and execute the command "nginx -t" inside the job.
Command: ```bash kubectl create job indexing --image=nginx -- nginx -t ``` 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:...
Create a secret named "my-secret" by using files from the specified path.
Command: ```bash kubectl create secret generic my-secret --from-file=path/to/profiles ``` 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 the fi...
Create a new ClusterIP service named shipping-service-clusterip that maps port 8083 on the service to port 7000 on the backend pods
Command: ```bash kubectl create service clusterip shipping-service-clusterip --tcp=8083:7000 ``` 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...
Setup autoscaling for the "cdn" deployment with a minimum of 4 pods and a maximum of 14 pods
Command: ```bash kubectl autoscale deployment cdn --min=4 --max=14 ``` 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...
Update the resource request and limits for all containers in the WordPress deployment
Command: ```bash kubectl set resources deployment wordpress --limits=cpu=200m,memory=512Mi --requests=cpu=3,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 request...
Create a pod disruption budget named messaging-pdb that will select all pods with the app=rails label and require a minimum of 9 of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget messaging-pdb --selector=app=rails --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...
Retrieve the snapshot logs from the container "email-service-pod-1" of the deployment named "frontend-deployment".
Command: ```bash kubectl logs deployment/frontend-deployment -c email-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: "fla...
Copy the contents of the "/var/run/secrets/kubernetes.io/serviceaccount/" file on your local machine to the "/tmp/bar" file in the remote pod named "kube-dns/message-broker-pod-15" in the specified namespace.
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ kube-dns/message-broker-pod-15::/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": "...
Create a new config map named 'namespace-config' with the specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap namespace-config --from-file=properties=/path/to/settings/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. When cr...
Add a taint with key 'cpu-type' on nodes having label stack=tech-stack
Command: ```bash kubectl taint node -l stack=tech-stack cpu-type=kube-master-9: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...
Create a new NodePort service named e-commerce-nodeport that exposes port 8010 on the cluster nodes and forwards traffic to port 5432 on the service cluster IP.
Command: ```bash kubectl create service nodeport e-commerce-nodeport --tcp=5432:8010 ``` 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": ...
Forward all traffic on port 5432 to port 8081 inside the 'proxy-server-pod' pod, listening on all addresses.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/proxy-server-pod 5432: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 ...
Embed the certificate authority data for the 'web-cluster' cluster entry by running the command: 'kubectl config set-cluster web-cluster --embed-certs --certificate-authority=~/.kube/cluster-gamma/kubernetes.ca.crt'
Command: ```bash kubectl config set-cluster web-cluster --embed-certs --certificate-authority=~/.kube/cluster-gamma/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...
View the revision history of the daemonset named "prod" and specifically inspect revision 5.
Command: ```bash kubectl rollout history daemonset/prod --revision=5 ``` What it does: View previous rollout revisions and configurations. Syntax: `kubectl rollout history (TYPE NAME | TYPE/NAME) [flags]` Helpful flags: "flag": "--filename", "short": "-f", "default": "[]", "usage": "Filename, directory, or URL to fi...
Remove the 'workload' taint with the effect 'NoSchedule' from the node 'worker-node-3' if it exists
Command: ```bash kubectl taint nodes worker-node-3 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 o...
Import the 'max_connections' key from the 'api-config' config map into the environment variables of the 'backend-microservice-deployment' deployment.
Command: ```bash kubectl set env --keys=max_connections --from=configmap/api-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 "database-pod" pod
Command: ```bash kubectl logs -f -c warp-drive database-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...
Check if you have permission to list the job named "image-processing-job" in the "production" namespace
Command: ```bash kubectl auth can-i list jobs.batch/image-processing-job -n production ``` 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 partia...
Create a new ClusterIP service named ldap-service-clusterip
Command: ```bash kubectl create service clusterip ldap-service-clusterip --tcp=8084: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", "...
Create a new config map named api-config with the settings key mapping to the contents of /path/to/data/file1.txt and the key2 key mapping to the contents of /path/to/configs/file2.txt.
Command: ```bash kubectl create configmap api-config --from-file=settings=/path/to/data/file1.txt --from-file=key2=/path/to/configs/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...
Switch to the e2e context for the current `kubectl` session.
Command: ```bash kubectl config use-context e2e ``` What it does: Set the current-context in a kubeconfig file. Syntax: `kubectl config use-context CONTEXT_NAME`
Get the output from the 'cyber-sleuth' container in the 'database-pod' pod
Command: ```bash kubectl attach database-pod -c cyber-sleuth ``` 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, us...
Revert a daemonset to a previous revision.
Command: ```bash kubectl rollout undo daemonset/staging --to-revision=1 ``` 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...
Create a new config map named app-secrets in the current namespace, using the specified files for the values
Command: ```bash kubectl create configmap app-secrets --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. When c...
Update the 'order-processing-deployment' deployment by setting the 'API_KEY' environment variable to 'your-api-key'
Command: ```bash kubectl set env deployment/order-processing-deployment API_KEY=your-api-key ``` 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 t...
Create a new config map named app-name-config using the contents of the 'data' folder.
Command: ```bash kubectl create configmap app-name-config --from-file=path/to/data ``` 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 the basename ...
Create a new ClusterIP service named api-service-clusterip with the TCP port mapping from 9000 to 9090.
Command: ```bash kubectl create service clusterip api-service-clusterip --tcp=9000:9090 ``` 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...
Create a new service account named 'vault'
Command: ```bash kubectl create serviceaccount vault ``` What it does: Create a service account with the specified name. Syntax: `kubectl create serviceaccount NAME [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: json|yaml|name|go-temp...
Create a deployment named prometheus with 3 replicas running the mongo image.
Command: ```bash kubectl create deployment prometheus --image=mongo --replicas=3 ``` 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 o...
Create an ingress resource called 'private-ingress' with a rule that directs requests to testing.com/input to the service 'svc1' on port 8080
Command: ```bash kubectl create ingress private-ingress --rule="testing.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": "", "us...
Create a new config map named env-vars using the specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap env-vars --from-file=conf=/path/to/profiles/file1.txt --from-file=data=/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. When creating a confi...
Listen on port 5432 locally, forwarding data to/from port 5432 in the frontend-pod pod
Command: ```bash kubectl port-forward pod/frontend-pod 5432 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 autom...
Add a taint to a Kubernetes node specifying the key, value, and effect
Command: ```bash kubectl taint nodes dev-node-4 zone=us-west-1a: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": "Output form...
Execute the 'sleep 3600' command in the monitoring-pod container and display the output.
Command: ```bash kubectl exec monitoring-pod -- 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": "Container name. If omitted, use the kubectl...
Add a taint with key 'dedicated' on nodes having label team=devops
Command: ```bash kubectl taint node -l team=devops dedicated=worker-node-3: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 job named "security-scan-job" using the image "mcr.microsoft.com/dotnet/core/runtime" and the command "dotnet".
Command: ```bash kubectl create job security-scan-job --image=mcr.microsoft.com/dotnet/core/runtime -- dotnet ``` 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...
Get the output from running a command in a specific pod and container
Command: ```bash kubectl exec proxy-server-pod -c time-machine -- kafka-console-producer --broker-list localhost:9092 --topic test ``` 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": "-...
Import the 'secret_key' from the 'app-name-config' config map into the 'monitoring-stack-deployment' deployment.
Command: ```bash kubectl set env --keys=secret_key --from=configmap/app-name-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 de...
Create a new ClusterIP service named messaging-service-clusterip, which maps port 5432 on the service to port 7000 on the pods
Command: ```bash kubectl create service clusterip messaging-service-clusterip --tcp=5432:7000 ``` 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": "-...
Set the annotation 'scaling-policy' with the value 'auto-horizontal-scaling' for the pod 'chat-app'
Command: ```bash kubectl annotate pods chat-app 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 an...
Create a new ExternalName service with the name external-caching-service and point it to the external address bar.com.
Command: ```bash kubectl create service externalname external-caching-service --external-name bar.com ``` 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 services tha...
Retrieve the previous logs of the "lunar-launcher" container from the "vpn-service-pod" pod
Command: ```bash kubectl logs -p -c lunar-launcher vpn-service-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"...
Create a cron job called cron-task running a golang image every minute
Command: ```bash kubectl create cronjob cron-task --image=golang --schedule="*/1 * * * *" -- go ``` 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", "default":...
create a job named "indexing" with the image "ethereum/client-go" and the command "geth attach"
Command: ```bash kubectl create job indexing --image=ethereum/client-go -- geth attach ``` 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...
Forward data between ports 9090 and 6000 locally and ports 9090 and 6000 in the 'mydeployment' pod of the deployment.
Command: ```bash kubectl port-forward deployment/mydeployment 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 will be selecte...
Create a copy of the email-service-pod and change all container images to postgres
Command: ```bash kubectl debug email-service-pod --copy-to=debug-image-api --set-image=*=postgres ``` 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...
Copy the file "foo" from the remote pod "security-scanner-pod-18" to the local directory "/tmp/bar_dir"
Command: ```bash kubectl cp openfaas/security-scanner-pod-18::/tmp/foo /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 ...
Get the snapshot logs from container database-deployment-1 of the deployment named auth-service-pod
Command: ```bash kubectl logs deployment/database-deployment -c auth-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: "flag...
Create a new config map named 'app-name-config' based on the 'configs' folder
Command: ```bash kubectl create configmap app-name-config --from-file=path/to/configs ``` 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 the basena...
Run the 'dotnet' command in the cosmic-container of the pod named security-service-pod, and get the output.
Command: ```bash kubectl exec security-service-pod -c cosmic-container -- dotnet ``` 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...
Display only the most recent 53 lines of output of the pod 'e-commerce-pod'
Command: ```bash kubectl logs --tail=53 e-commerce-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": "...
Get the output from running the 'mysql' command in the first container of the 'payment-processor-deployment' deployment.
Command: ```bash kubectl exec deploy/payment-processor-deployment -- 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,...
Copy the file /tmp/foo from the pod web-app-pod-1 to the local directory /tmp/bar.
Command: ```bash kubectl cp velero/web-app-pod-1:/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 kubectl.kuber...
Return the previous terminated logs from the 'nebula-navigator' container in the 'backend-pod' pod.
Command: ```bash kubectl logs -p -c nebula-navigator backend-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", ...
Create an ingress called 'web-ingress' that directs requests to website.com/bar to svc1:8010 with the tls secret "my-cert"
Command: ```bash kubectl create ingress web-ingress --rule="website.com/bar=svc1:8010,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": ...
import the 'api_key' key from the 'env-vars' ConfigMap and set it as an environment variable in the 'api-server-deployment' deployment
Command: ```bash kubectl set env --keys=api_key --from=configmap/env-vars 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 one...
Forward traffic from port 8888 on all addresses to port 6379 in the 'security-service-pod' pod, allowing external access.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/security-service-pod 8888: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 ...
Get output from running the 'redis-server' command in stardust-shuttle from pod mypod
Command: ```bash kubectl exec mypod -c stardust-shuttle -- 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 omitted, us...
Forward local port 8081 to port 8000 in the pod named "api-service-pod"
Command: ```bash kubectl port-forward pod/api-service-pod 8081: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 au...
Create a new ClusterIP service named my-cs with a TCP port mapping from local port 3001 to target port 8010
Command: ```bash kubectl create service clusterip my-cs --tcp=3001: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": "-o", "default": "", "us...
Execute the 'node' command inside the 'frontend-pod' pod and retrieve the output
Command: ```bash kubectl exec frontend-pod -- node ``` 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.kuberne...
Forward local port 8080 to port 5432 in the pod
Command: ```bash kubectl port-forward pod/security-service-pod 8080: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 select...
Create a new pod named "hazelcast" using the "mongo" image and expose port 9090
Command: ```bash kubectl run hazelcast --image=mongo --port=9090 ``` 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...
Forward the local ports 5432 and 6000 to the corresponding ports in the 'mypod' pod.
Command: ```bash kubectl port-forward pod/mypod 5432 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...
Create a pod disruption budget named 'messaging-pdb' that will select all pods with the 'env=production' label and require at least 9 of them being available at any point in time
Command: ```bash kubectl create poddisruptionbudget messaging-pdb --selector=env=production --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 [...
Display all logs written in the last hour from the 'database-pod' pod.
Command: ```bash kubectl logs --since=1h database-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": "-...
Forward traffic from local port 5432 to port 8888 in the pod with name 'api-service-pod'
Command: ```bash kubectl port-forward pod/api-service-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 criteria, a pod will be selected au...
Expose the replication controller specified in "alpine-controller.yaml" as a service on port 8010, connecting to the containers on port 8888
Command: ```bash kubectl expose -f alpine-controller.yaml --port=8010 --target-port=888800 ``` 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...
Forward traffic from local port 9090 to port 8888 in the pod named "log-aggregator-pod"
Command: ```bash kubectl port-forward pod/log-aggregator-pod 9090: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...
import the 'api_key' key from the 'db-config' config map and set it as an environment variable in the 'notification-handler-deployment' deployment
Command: ```bash kubectl set env --keys=api_key --from=configmap/db-config 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 variable definit...
Annotate pod with 'monitoring-tool=Prometheus'
Command: ```bash kubectl annotate pods foo monitoring-tool=Prometheus ``` 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...
Create a new ClusterIP service named order-service-clusterip
Command: ```bash kubectl create service clusterip order-service-clusterip --tcp=5000:8082 ``` 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", ...
Create a new cluster role named "foo" with the ResourceName specified.
Command: ```bash kubectl create clusterrole foo --verb=use --resource=configmaps --resource-name=cdn-proxy --resource-name=search-elasticsearch ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|clien...
Create an ingress called 'app1-ingress' that directs requests to site.com/bar to svc1:8082 with a tls secret named "my-cert"
Command: ```bash kubectl create ingress app1-ingress --rule="site.com/bar=svc1:8082,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": "O...
forward the local port 9090 to the port 8000 inside the 'web-app-pod' pod
Command: ```bash kubectl port-forward pod/web-app-pod 9090: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 automa...
Set the resource request and limits for all containers in the wordpress deployment:
Command: ```bash kubectl set resources deployment wordpress --limits=cpu=200m,memory=512Mi --requests=cpu=100m,memory=64Mi ``` 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 req...
Start streaming the logs of the "warp-drive" container in the "analytics-pod" pod.
Command: ```bash kubectl logs -f -c warp-drive analytics-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", "sho...
Copy a file from a remote pod to a local directory.
Command: ```bash kubectl cp logging/ingress-controller-pod-8:/tmp/foo /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 t...
Create a deployment named 'my-dep' using the 'centos' image and expose port 27017.
Command: ```bash kubectl create deployment my-dep --image=centos --port=27017 ``` 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: ...
Create a new ExternalName service named external-payment-gateway-service that points to the external domain example-domain.com
Command: ```bash kubectl create service externalname external-payment-gateway-service --external-name example-domain.com ``` 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 ref...