prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Create a new job from an existing cron job named "email-notifications"
Command: ```bash kubectl create job test-job --from=cronjob/email-notifications ``` 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...
Create a new ClusterIP service named notification-service-clusterip with a TCP port mapping from port 8443 to port 8083.
Command: ```bash kubectl create service clusterip notification-service-clusterip --tcp=8443:8083 ``` 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":...
View the details of a specific context in your kubeconfig file
Command: ```bash kubectl config get-contexts testing-context ``` What it does: Display one or many contexts from the kubeconfig file. Syntax: `kubectl config get-contexts [(-o|--output=)name)]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: name "
Forward traffic from port 5432 on all addresses to port 5000 in the pod named "analytics-pod".
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/analytics-pod 5432: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 wil...
Import the 'redis_host' key from the 'app-name-config' config map and set it as an environment variable in the 'web-app-deployment' deployment.
Command: ```bash kubectl set env --keys=redis_host --from=configmap/app-name-config deployment/web-app-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions...
Retrieve the previous terminated logs of the "warp-drive" container from the "gateway-pod" pod.
Command: ```bash kubectl logs -p -c warp-drive 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", "short...
Return the snapshot logs from the pod "security-service-pod" with only one container
Command: ```bash kubectl logs security-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", "short": "-c",...
Forward traffic from port 8081 on all addresses to port 9090 in the e-commerce-pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/e-commerce-pod 8081: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 wi...
Create a single ingress called 'internal-ingress' that directs requests to site.com/example to the 'svc1' service on port '8088' with a TLS secret named "my-cert".
Command: ```bash kubectl create ingress internal-ingress --rule="site.com/example=svc1:8088,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...
Provide a detailed description of pods with the label 'owner' equal to 'john-doe'
Command: ```bash kubectl describe po -l owner=john-doe ``` What it does: Show details of a specific resource or group of resources. Print a detailed description of the selected resources, including related resources such as events or controllers. You may select a single object by name, all objects of that type, provid...
Partially update the db-node-7 node by setting the `unschedulable` property to `true`, using a strategic merge patch specified in YAML format.
Command: ```bash kubectl patch node db-node-7 -p $'spec:\n 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]` Helpful fl...
Create an ingress named 'web-ingress' that directs requests from website.com/module to svc1:5001 and uses the tls secret "my-cert"
Command: ```bash kubectl create ingress web-ingress --rule="website.com/module=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...
Import the SMTP_SERVER key from the 'app-config-dev' config map into the 'order-processing-deployment' deployment
Command: ```bash kubectl set env --keys=SMTP_SERVER --from=configmap/app-config-dev 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 de...
Create an ingress called 'default-ingress' that directs requests to foo.com/example to svc1:27017 with a TLS secret "my-cert".
Command: ```bash kubectl create ingress default-ingress --rule="foo.com/example=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": "", "usa...
Update the pod 'security' by adding the annotation 'custom-label' with the value 'my-custom-value'
Command: ```bash kubectl annotate pods security custom-label=my-custom-value ``` 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 ...
Taint nodes with the label release=beta by adding a taint with the key 'workload' and the value 'app-node-6:PreferNoSchedule'
Command: ```bash kubectl taint node -l release=beta workload=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 cron job named "daily-report" using the nginx image
Command: ```bash kubectl create cronjob daily-report --image=nginx --schedule="*/1 * * * *" -- nginx -g "daemon off;" ``` 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", "sh...
Copy the file named "foo" from the local machine to the directory "/tmp/bar_dir" on a specific container in a remote pod
Command: ```bash kubectl cp :/tmp/foo ingress-controller-pod-8:/tmp/bar_dir -c logging-agent ``` 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 omit...
Create a new config map named app-config using the files file1.txt and file2.txt, and key1 as the content of file2.txt.
Command: ```bash kubectl create configmap app-config --from-file=properties=/path/to/options/file1.txt --from-file=key1=/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 c...
Copy the local file "/tmp/foo" to the remote pod named "logging-agent-pod-7" in the "cert-manager" namespace and save it as "/tmp/bar"
Command: ```bash kubectl cp :/tmp/foo cert-manager/logging-agent-pod-7::/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...
Set environment variables for a deployment using values from a secret.
Command: ```bash kubectl set env --from=secret/private-key-secret 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 definitions in o...
create a new config map named 'ui-config' with the settings key set to the contents of the '/path/to/profiles/file1.txt' file and the key2 key set to the contents of the '/path/to/profiles/file2.txt' file.
Command: ```bash kubectl create configmap ui-config --from-file=settings=/path/to/profiles/file1.txt --from-file=key2=/path/to/profiles/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...
Copy the directory `/tmp/foo_dir` from the remote pod `ingress-nginx/security-scanner-pod-18` to the local directory `/tmp/bar_dir`.
Command: ```bash kubectl cp ingress-nginx/security-scanner-pod-18:/tmp/foo_dir /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 omitt...
Forward local port 8081 to port 8088 in the pod named "frontend-pod"
Command: ```bash kubectl port-forward pod/frontend-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...
Check if you have permission to list the "data-synchronization-job" job in the "production" namespace.
Command: ```bash kubectl auth can-i list jobs.batch/data-synchronization-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 pa...
Scale the deployment named app-v2-replicaset to 1 replica, if its current size is 3.
Command: ```bash kubectl scale --current-replicas=3 --replicas=1 deployment/app-v2-replicaset ``` 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-v...
Set the service account of the deployment "gateway-deployment" to "kube-controller-manager"
Command: ```bash kubectl set serviceaccount deployment gateway-deployment kube-controller-manager ``` What it does: Update the service account of pod template resources. Possible resources (case insensitive) can be: replicationcontroller (rc), deployment (deploy), daemonset (ds), job, replicaset (rs), statefulset Syn...
Add a taint with key 'environment' on nodes having label app=web-app, with the value 'dev-node-4:PreferNoSchedule'
Command: ```bash kubectl taint node -l app=web-app environment=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": "", "usage": "...
Import the secret_key from the app-config config map and set it as an environment variable in the web-app-deployment deployment.
Command: ```bash kubectl set env --keys=secret_key --from=configmap/app-config deployment/web-app-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in o...
Forward traffic from local port 8888 to port 5432 in the pod named api-service-pod.
Command: ```bash kubectl port-forward pod/api-service-pod 8888 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 au...
Create an ingress called 'app-gateway-ingress' with a rule that directs requests from testing.com/input to svc1:9000
Command: ```bash kubectl create ingress app-gateway-ingress --rule="testing.com/input=svc1:9000,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": "",...
Connect to a pod and interact with its container's bash shell
Command: ```bash kubectl attach analytics-pod -c mycontainer -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 omitt...
Forward local port 3000 to port 8081 on the pod "proxy-server-pod" and listen for incoming connections.
Command: ```bash kubectl port-forward pod/proxy-server-pod 3000: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 a...
Delete the pods and services with the names "vpn" and "payment"
Command: ```bash kubectl delete pod,service vpn payment ``` 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. Som...
Add a taint with key 'special' on nodes having label version=v1.0.0
Command: ```bash kubectl taint node -l version=v1.0.0 special=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...
Update the annotation 'git-repo' of pod 'database' with the value 'https://github.com/example/my-app'
Command: ```bash kubectl annotate pods database git-repo='https://github.com/example/my-app' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than lab...
Set custom TLS server name for kube-cluster-2 cluster entry
Command: ```bash kubectl config set-cluster kube-cluster-2 --tls-server-name=on-prem-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] [--certif...
Forward local port 8080 to port 8081 in the analytics-pod pod.
Command: ```bash kubectl port-forward pod/analytics-pod 8080: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 auto...
Add a taint with the key 'cpu-type' and value 'kube-master-9:PreferNoSchedule' on nodes that have the label 'project=project-alpha'
Command: ```bash kubectl taint node -l project=project-alpha 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": "", ...
Execute the command '/bin/bash -c "echo 'Hello, Amazon Linux'"' in the pod named security-service-pod, specifically in the container named nano-bot and retrieve the output.
Command: ```bash kubectl exec security-service-pod -c nano-bot -- /bin/bash -c "echo 'Hello, Amazon Linux'" ``` 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": "", "usa...
update the 'scheduler-app-deployment' deployment by setting the DB_HOST environment variable to 'localhost'
Command: ```bash kubectl set env deployment/scheduler-app-deployment DB_HOST=localhost ``` 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 templat...
Scale the replication controller "vpn" to automatically adjust the number of pods based on CPU utilization
Command: ```bash kubectl autoscale rc vpn --max=8 --cpu-percent=50 ``` 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...
Forward port 8080 on all addresses to the pod's port 8080
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/security-service-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 ...
Verify if the current user has permission to list the "log-analysis-job" job in the "kube-system" namespace.
Command: ```bash kubectl auth can-i list jobs.batch/log-analysis-job -n kube-system ``` 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 U...
Update the 'auth' pod by adding the label 'env' with the value 'production'
Command: ```bash kubectl label pods auth env=production ``` What it does: Update the labels on a resource. Syntax: `kubectl label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]` Helpful flags: "flag": "--all-namespaces", "short": "-A", "default": "false", "usage": "I...
Forward local port 6379 to port 8080 in the pod 'cdn-service-pod'
Command: ```bash kubectl port-forward pod/cdn-service-pod 6379 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 au...
Forward local port 5432 to port 6379 in the pod "proxy-server-pod"
Command: ```bash kubectl port-forward pod/proxy-server-pod 5432:6379 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected a...
Create a new ExternalName service named 'external-cloud-storage-service' and set the external name to 'governmental-demo.gov'
Command: ```bash kubectl create service externalname external-cloud-storage-service --external-name governmental-demo.gov ``` 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 re...
Forward data between local ports 8080 and 6000 and ports 9090 and 6000 of the 'analytics-pod' pod
Command: ```bash kubectl port-forward pod/analytics-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 auto...
Start a pod named "hazelcast" using the "mongo" image, and expose port 8010
Command: ```bash kubectl run hazelcast --image=mongo --port=8010 ``` 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...
Copy the ~/.config/kube directory from the 'ingress-nginx/payment-gateway-pod-19' pod to the local '/tmp/bar_dir' directory.
Command: ```bash kubectl cp ingress-nginx/payment-gateway-pod-19:~/.config/kube /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 omit...
Create a new config map named 'app-settings' with the specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap app-settings --from-file=properties=/path/to/profiles/file1.txt --from-file=key1=/path/to/preferences/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creat...
Retrieve the logs of container "web-app-pod-1" from the deployment "mydeployment"
Command: ```bash kubectl logs deployment/mydeployment -c web-app-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": "--contai...
List the deployments in JSON format for the "v2.1.0" version of the "internal-apps" API group.
Command: ```bash kubectl get deployments.v2.1.0.internal-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 namespaced you w...
View and output the modified deployment in YAML format without making any changes to the object on the server
Command: ```bash kubectl set env deployment/proxy-service-deployment API_KEY=your-api-key -o yaml ``` 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 a new ClusterIP service named 'monitoring-service-clusterip' that forwards traffic from port 3000 to port 8888.
Command: ```bash kubectl create service clusterip monitoring-service-clusterip --tcp=3000:8888 ``` 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": "...
Create a new ClusterIP service named payment-service-clusterip, mapping traffic from port 3306 to port 8081.
Command: ```bash kubectl create service clusterip payment-service-clusterip --tcp=3306:8081 ``` 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"...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=redis_host --from=configmap/db-config deployment/email-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 ...
Create a new NodePort service named e-commerce-nodeport with the port mapping of 8443 to 8181
Command: ```bash kubectl create service nodeport e-commerce-nodeport --tcp=8443:8181 ``` 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": ...
View the snapshot logs from container `media-stream-pod-1` of a deployment named `api-server-deployment`
Command: ```bash kubectl logs deployment/api-server-deployment -c media-stream-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: "fl...
Update the pod 'foo' by adding the annotation 'release-notes' with the value 'https://example.com/release-notes/v2.5.1'
Command: ```bash kubectl annotate pods foo release-notes='https://example.com/release-notes/v2.5.1' ``` 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 t...
Create a Pod Disruption Budget (PDB) named frontend-pdb that selects all pods with the app=rails label and ensures that at least four of them are available at any given time.
Command: ```bash kubectl create poddisruptionbudget frontend-pdb --selector=app=rails --min-available=4 ``` 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-...
Create a deployment named 'registry' using the 'ubuntu' image and expose port 8000
Command: ```bash kubectl create deployment registry --image=ubuntu --port=8000 ``` 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:...
Update the pod named 'auth' with the annotation 'expiration-date' and set the value to '2024-12-31', replacing any existing value.
Command: ```bash kubectl annotate --overwrite pods auth expiration-date='2024-12-31' ``` 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 ...
Listen on port 8888 on your local machine, and forward traffic to port 8888 in the analytics-pod pod.
Command: ```bash kubectl port-forward pod/analytics-pod 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 pod will be selected auto...
Create a copy of the log-aggregator-pod with a debug container and updated container images
Command: ```bash kubectl debug log-aggregator-pod -it --copy-to=debug-image-web --image=debian --set-image=api=api:v2,cache=redis:alpine ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource an...
Return the snapshot logs from the container named auth-service-pod-1 in the deployment named scheduler-app-deployment.
Command: ```bash kubectl logs deployment/scheduler-app-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: ...
Create a pod disruption budget named web-app-pdb that selects all pods with the component=web label and requires at least four of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget web-app-pdb --selector=component=web --min-available=4 ``` 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 [--d...
List the replication controller with name 'web', the service with name 'analytics-rc', and the pod with name 'cdn-service-pod'.
Command: ```bash kubectl get rc/web service/analytics-rc pods/cdn-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 namespac...
Forward local ports 5432 and 6000 to ports 8088 and 6000 in a selected pod of the deployment
Command: ```bash kubectl port-forward deployment/mydeployment 5432 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 selecte...
Create a cluster role named "view" with NonResourceURL specified.
Command: ```bash kubectl create clusterrole "view" --verb=update --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...
Set the custom TLS server name to 'cluster-gamma' for the 'kube-cluster-1' cluster entry.
Command: ```bash kubectl config set-cluster kube-cluster-1 --tls-server-name=cluster-gamma ``` 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] [--certific...
Set the custom TLS server name to use for validation for the 'e2e' cluster entry as 'dev-cluster'
Command: ```bash kubectl config set-cluster e2e --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] [--certificate-authority...
Forward traffic from port 5432 on localhost and IP 10.19.21.23 to port 8081 in the frontend-pod pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/frontend-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 criter...
Rename the context 'prod-context' to 'client-2-context' in your kubeconfig file
Command: ```bash kubectl config rename-context prod-context client-2-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 als...
Reconcile RBAC resources from a file
Command: ```bash kubectl auth reconcile -f rules.yaml ``` What it does: Reconciles rules for RBAC role, role binding, cluster role, and cluster role binding objects. Missing objects are created, and the containing namespace is created for namespaced objects, if required. Existing roles are updated to include the permi...
Create an ingress resource called 'private-ingress' with a rule that directs requests from foo.com/example to the service svc1:8010
Command: ```bash kubectl create ingress private-ingress --rule="foo.com/example=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": "", "usag...
Copy the local directory "/tmp/foo_dir" to the remote pod with the name "front-end-pod-12" in the default namespace, and place it in the directory "/tmp/bar_dir" on the pod.
Command: ```bash kubectl cp :/tmp/foo_dir front-end-pod-12::/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 kubectl...
Create a cluster role named "foo" with specific permissions for specified sub-resources.
Command: ```bash kubectl create clusterrole foo --verb=list,create,connect --resource=namespaces,namespaces/status ``` 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: "fla...
Execute the 'python' command in the 'warp-drive' container of the 'mypod' pod and retrieve the output.
Command: ```bash kubectl exec mypod -c warp-drive -- 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 omitted, use the kubect...
Create a service for the pod "api-service-pod", serving on port 444 with the name "frontend"
Command: ```bash kubectl expose pod api-service-pod --port=8000 --name=frontend ``` 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 ...
Force replace a resource by deleting and then re-creating it
Command: ```bash kubectl replace --force -f ./conf.json ``` What it does: Replace a resource by file name or stdin. JSON and YAML formats are accepted. If replacing an existing resource, the complete resource spec must be provided. This can be obtained by $ kubectl get TYPE NAME -o yaml Syntax: `kubectl replace -f FI...
replace the pod with the data provided in the parameters.yaml file
Command: ```bash kubectl replace -f ./parameters.yaml ``` What it does: Replace a resource by file name or stdin. JSON and YAML formats are accepted. If replacing an existing resource, the complete resource spec must be provided. This can be obtained by $ kubectl get TYPE NAME -o yaml Syntax: `kubectl replace -f FILE...
Execute the 'python' command inside the 'stardust-shuttle' container from the 'auth-service-pod' pod
Command: ```bash kubectl exec auth-service-pod -c stardust-shuttle -- 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 omitte...
Embed the certificate authority data for the 'cloud-cluster' cluster entry by running the command:
Command: ```bash kubectl config set-cluster cloud-cluster --embed-certs --certificate-authority=~/.kube/cluster-alpha/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 s...
attach to the 'email-service-pod' and capture the output from the 'quantum-quark' container.
Command: ```bash kubectl attach email-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 omitt...
Disable certificate checking for the "galaxy-cluster" entry in the Kubernetes configuration.
Command: ```bash kubectl config set-cluster galaxy-cluster --insecure-skip-tls-verify=true ``` 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] [--certific...
Listen on port 8088 locally, forwarding to the targetPort of the "https" service's port named "https" in a pod selected by the database-service service.
Command: ```bash kubectl port-forward service/database-service 8088:https ``` 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 selec...
List the deployments in YAML output format, in the "v2.1.0" version of the "experimental-apps" API group.
Command: ```bash kubectl get deployments.v2.1.0.experimental-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 y...
Get the replication controller with the name "monitoring-rc" in the ps output format
Command: ```bash kubectl get replicationcontroller monitoring-rc ``` 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 o...
Set the CPU limits to "1" and memory limits to "2Gi" for the hazelcast container in the deployment named "hazelcast".
Command: ```bash kubectl set resources deployment hazelcast -c=nginx --limits=cpu=1,memory=2Gi ``` 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 ...
Scale the mysql deployment to 1 replica, taking into consideration that the current size is 7 replicas.
Command: ```bash kubectl scale --current-replicas=7 --replicas=1 deployment/foo ``` 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 spec...
Delete pods and services named "analytics" and "proxy-server"
Command: ```bash kubectl delete pod,service analytics proxy-server ``` 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 se...
Add a 'special' taint on nodes that have a label 'environment=production'
Command: ```bash kubectl taint node -l environment=production special=edge-node-10: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 traffic from port 8081 on localhost and IP address 10.19.21.23 to port 5432 in the pod named "analytics-pod".
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/analytics-pod 8081: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 crite...
Embed the certificate authority data for the 'kube-cluster-2' cluster entry using the command:
Command: ```bash kubectl config set-cluster kube-cluster-2 --embed-certs --certificate-authority=~/.kube/star-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 s...
Create a pod disruption budget named elastic-search-pdb that will select all pods with the release=1.0.0 label and require a minimum of 9 of them being available at any point in time
Command: ```bash kubectl create poddisruptionbudget elastic-search-pdb --selector=release=1.0.0 --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...
Partially update a node by applying a strategic merge patch in YAML format
Command: ```bash kubectl patch node kube-master-9 -p $'spec:\n rules:\n- http:\n paths:\n - path: /\n backend:\n service:\n name: new-service' ``` 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. ...
Import the MAX_CONNECTIONS key from the app-name-config config map and set it as an environment variable in the scheduler-app-deployment deployment.
Command: ```bash kubectl set env --keys=MAX_CONNECTIONS --from=configmap/app-name-config deployment/scheduler-app-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable ...
Update the cluster role binding "admin" to include the service account "namespace:fluentd"
Command: ```bash kubectl set subject clusterrolebinding admin --serviceaccount=namespace:fluentd ``` What it does: Update the user, group, or service account in a role binding or cluster role binding. Syntax: `kubectl set subject (-f FILENAME | TYPE NAME) [--user=username] [--group=groupname] [--serviceaccount=namesp...