prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Start a pod using the ethereum/client-go image, but customize its specification by providing a partial set of values in JSON format.
Command: ```bash kubectl run nginx --image=ethereum/client-go --overrides='{ "apiVersion": "legacy-1.0.0", "spec": { ... } }' ``` 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] [--c...
Disable certificate checking for the dev cluster entry by setting the '--insecure-skip-tls-verify=true' flag for the 'kube-cluster-2' cluster.
Command: ```bash kubectl config set-cluster kube-cluster-2 --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...
Run the 'docker run -d ubuntu sleep 3600' command in the 'warp-drive' container inside the 'media-stream-pod' pod and get the output
Command: ```bash kubectl exec media-stream-pod -c warp-drive -- docker run -d ubuntu sleep 3600 ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Contai...
Forward local port 5000 to port 8088 in the pod
Command: ```bash kubectl port-forward pod/mypod 5000: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...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=EXTERNAL_API_URL --from=configmap/app-secrets deployment/load-balancer-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable def...
Update the deployment 'email-server-deployment' by adding a new environment variable named DEBUG with a value of true.
Command: ```bash kubectl set env deployment/email-server-deployment DEBUG=true ``` 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 config map named db-config with the specified keys and files
Command: ```bash kubectl create configmap db-config --from-file=settings=/path/to/configurations/file1.txt --from-file=key2=/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 c...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=DEBUG_MODE --from=configmap/api-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 definitio...
Create a job named 'certificate-renewal' using the 'postgres' image, with the command being executed as 'postgres'
Command: ```bash kubectl create job certificate-renewal --image=postgres -- postgres ``` 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 f...
Remove the "client-secret" config value for the OpenID Connect auth provider for the "deploy-bot" entry
Command: ```bash kubectl config set-credentials deploy-bot --auth-provider=oidc --auth-provider-arg=client-secret- ``` 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-...
Forward local port 8000 to port 5432 on a pod selected by the api-server-deployment deployment.
Command: ```bash kubectl port-forward deployment/api-server-deployment 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 b...
Create a deployment named grafana that runs the php image and exposes port 8181
Command: ```bash kubectl create deployment grafana --image=php --port=8181 ``` 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: jso...
Apply a taint to a specific node
Command: ```bash kubectl taint nodes storage-node-13 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...
Retrieve logs from the container "auth-service-pod-1" in the deployment "cache-cluster-deployment"
Command: ```bash kubectl logs deployment/cache-cluster-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 copy of the 'proxy-service-pod' pod, changing all container images to 'alpine'
Command: ```bash kubectl debug proxy-service-pod --copy-to=dgb-img --set-image=*=alpine ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used by default if no resour...
forward local port 8000 to pod port 5000
Command: ```bash kubectl port-forward pod/e-commerce-pod 8000 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 aut...
Forward local ports 5000 and 6000 to ports 5000 and 6000 in a selected pod.
Command: ```bash kubectl port-forward deployment/analytics-platform-deployment 5000 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 po...
Add a taint with the key 'disktype' and the value 'edge-node-10:PreferNoSchedule' on the nodes that have the label 'stack=tech-stack'
Command: ```bash kubectl taint node -l stack=tech-stack disktype=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": "", "usage...
Create a job named "monitoring-job" using the Ruby image. The job should run the command "ruby --version".
Command: ```bash kubectl create job monitoring-job --image=ruby -- ruby --version ``` 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 form...
Create a new config map named app-secrets using specified keys and file paths
Command: ```bash kubectl create configmap app-secrets --from-file=settings=/path/to/options/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 co...
Create a deployment called loadbalancer with the wordpress image
Command: ```bash kubectl create deployment loadbalancer --image=wordpress ``` 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...
Expose the php deployment as a service, serving on port 7000 and connecting to the containers on port 500000.
Command: ```bash kubectl expose deployment php --port=7000 --target-port=500000 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified ...
Create a pod disruption budget named monitoring-pdb that will select all pods with the component=web label and require minimum 9 of them being available at any point in time
Command: ```bash kubectl create poddisruptionbudget monitoring-pdb --selector=component=web --min-available=9 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-available=N [...
Create a deployment named 'drupal' with the 'amazonlinux' image and 5 replicas.
Command: ```bash kubectl create deployment drupal --image=amazonlinux --replicas=5 ``` 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...
Update the 'frontend-deployment' deployment with the SMTP_PASSWORD environment variable set to 'your-password'
Command: ```bash kubectl set env deployment/frontend-deployment SMTP_PASSWORD=your-password ``` 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 te...
Execute the 'geth' command in the astro-container from the pod named 'auth-service-pod'
Command: ```bash kubectl exec auth-service-pod -c astro-container -- geth ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, ...
Create a pod disruption budget named web-app-pdb that will select all pods with the version=v2 label and require at least 9 of them being available at any point in time
Command: ```bash kubectl create poddisruptionbudget web-app-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-...
Create a service for the replicated alpine using replica set, which serves on port 8082 and connects to the containers on port 300100.
Command: ```bash kubectl expose rs alpine --port=8082 --target-port=300100 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port....
Forward local port 8000 to port 8088 in the pod "log-aggregator-pod"
Command: ```bash kubectl port-forward pod/log-aggregator-pod 8000 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...
Add a taint to the node named 'storage-node-13' with the key 'environment' and no value
Command: ```bash kubectl taint nodes storage-node-13 environment:NoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. O...
Execute the 'go' command inside the 'stardust-shuttle' container of the 'api-service-pod' pod, and get the output from it.
Command: ```bash kubectl exec api-service-pod -c stardust-shuttle -- go ``` 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 traffic from local port 9090 to port 6379 in the pod named log-aggregator-pod
Command: ```bash kubectl port-forward pod/log-aggregator-pod 9090:6379 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected...
Output the modified deployment in YAML format without making any changes to the object on the server
Command: ```bash kubectl set env deployment/mydeployment SMTP_HOST=smtp.example.com -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 pod te...
Set the resource request and limits for all containers in the golang deployment.
Command: ```bash kubectl set resources deployment golang --limits=cpu=200m,memory=512Mi --requests=cpu=3,memory=128Mi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requeste...
Create an ingress that routes requests from site.com/bar to svc1:5432 using a TLS certificate named "my-cert"
Command: ```bash kubectl create ingress service-ingress --rule="site.com/bar=svc1:5432,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":...
Embed certificate authority data for the app-cluster cluster entry
Command: ```bash kubectl config set-cluster app-cluster --embed-certs --certificate-authority=~/.kube/my-k8s-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 se...
List the deployments in YAML format using the "stable-2.0.0" version of the "backup-apps" API group
Command: ```bash kubectl get deployments.stable-2.0.0.backup-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...
Forward traffic from port 8888 on localhost and IP address 10.19.21.23 to port 9090 in the security-service-pod pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/security-service-pod 8888: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 th...
Set the cluster field in a specific context to a specified cluster
Command: ```bash kubectl config set contexts.staging-context.cluster cluster-beta ``` 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 ...
Listen on port 9090 of localhost and IP address 10.19.21.23, and forward the traffic to port 9090 of the cdn-service-pod pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/cdn-service-pod 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 cri...
Forward traffic from port 8080 on localhost and IP 10.19.21.23 to port 8088 in the pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/mypod 8080:8088 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a p...
Import the keys 'config_file_path' from the config map named 'monitoring-config' into the environment variables of the deployment named 'user-management-deployment'.
Command: ```bash kubectl set env --keys=config_file_path --from=configmap/monitoring-config deployment/user-management-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 vari...
Change the service account of the deployment "backend-microservice-deployment" to "vault"
Command: ```bash kubectl set serviceaccount deployment backend-microservice-deployment vault ``` What it does: Update the service account of pod template resources. Possible resources (case insensitive) can be: replicationcontroller (rc), deployment (deploy), daemonset (ds), job, replicaset (rs), statefulset Syntax: ...
Copy a directory (/tmp/foo_dir) from a remote pod to a local destination (/etc/kubernetes)
Command: ```bash kubectl cp kube-proxy/image-resizer-pod-20:/tmp/foo_dir /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", "short": "-c", "default": "", "usage": "Container name. If omitted,...
Start port forwarding from all addresses on port 8000, forwarding to port 8888 in the 'mypod' pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/mypod 8000: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 sel...
Retrieve the logs of the previously terminated "cosmic-container" container from the pod "proxy-service-pod"
Command: ```bash kubectl logs -p -c cosmic-container proxy-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": "--contai...
Delete the pods and services with the names "database" and "vpn"
Command: ```bash kubectl delete pod,service database vpn ``` 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. So...
Expose the deployment "ruby" as a service on port 6379, connecting to container ports on port 909100
Command: ```bash kubectl expose deployment ruby --port=6379 --target-port=909100 ``` 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...
Create a service for a replicated Ruby application, serving on port 80 and connecting to the containers on port 8000
Command: ```bash kubectl expose rc ruby --port=80 --target-port=801000 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port. A d...
Create a service for the centos deployment, which serves on port 8010 and connects to the containers on port 8084.
Command: ```bash kubectl expose deployment centos --port=8010 --target-port=808400 ``` 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...
Forward traffic from a local random port to port 3000 in the security-service-pod pod
Command: ```bash kubectl port-forward pod/security-service-pod :3000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected a...
Remove a taint from a specific node if it exists
Command: ```bash kubectl taint nodes testing-node-11 dedicated: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. On...
Copy the file /tmp/foo from the remote pod backend-pod-13 in the kube-system namespace to the local directory /etc/kubernetes.
Command: ```bash kubectl cp kube-system/backend-pod-13::/tmp/foo /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", "short": "-c", "default": "", "usage": "Container name. If omitted, use the...
Expose a replicated alpine resource as a service, serving on port 3000 and connecting to the containers on port 808000.
Command: ```bash kubectl expose rc alpine --port=3000 --target-port=808000 ``` 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....
Delete the pods and services with the names "backend" and "monitoring"
Command: ```bash kubectl delete pod,service backend monitoring ``` 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 select...
Copy a directory from a remote pod to your local machine
Command: ```bash kubectl cp kube-public/database-pod-2:/tmp/foo_dir :/tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the ku...
Add a taint with the key 'special' and the value 'testing-node-11:PreferNoSchedule' to the nodes that have the label 'role=database'.
Command: ```bash kubectl taint node -l role=database 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 image of the 'php' container to 'php:7.4.22' in all deployments and replication controllers.
Command: ```bash kubectl set image deployments,rc php=php:7.4.22 --all ``` What it does: Update existing container image(s) of resources. Possible resources include (case insensitive): pod (po), replicationcontroller (rc), deployment (deploy), daemonset (ds), statefulset (sts), cronjob (cj), replicaset (rs) Syntax: `...
Create a new config map named app-secrets using the key=value pairs from the file located at path/to/data.
Command: ```bash kubectl create configmap app-secrets --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 of t...
Import the 'SMTP_SERVER' key from the 'app-settings' config map to the 'monitoring-stack-deployment' deployment.
Command: ```bash kubectl set env --keys=SMTP_SERVER --from=configmap/app-settings 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 defi...
Forward the local port 8080 to the port 8080 of a pod named "frontend-pod"
Command: ```bash kubectl port-forward pod/frontend-pod 8080:8080 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected autom...
List deployments in JSON format, specifically in the "v2.1.0" version of the "backup-apps" API group.
Command: ```bash kubectl get deployments.v2.1.0.backup-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 wil...
Run the 'ash' command inside the pod named gateway-pod
Command: ```bash kubectl exec gateway-pod -- ash ``` 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...
Begin streaming the logs of the `astro-container` container in the `api-service-pod` pod
Command: ```bash kubectl logs -f -c astro-container api-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...
Forward local port 6379 to the target port of the service named "https" in a selected pod.
Command: ```bash kubectl port-forward service/api-service 6379: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 selected a...
Listen on a random port locally, forwarding to the 8088 port in the 'mypod' pod
Command: ```bash kubectl port-forward pod/mypod :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 automatically. T...
Scale the deployment named dev-environment-rs to 5 replicas if its current size is 7.
Command: ```bash kubectl scale --current-replicas=7 --replicas=5 deployment/dev-environment-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-...
Create a new secret named email-credentials-secret from an environment file located at path/to/profiles.env
Command: ```bash kubectl create secret generic email-credentials-secret --from-env-file=path/to/profiles.env ``` What it does: Create a secret based on a file, directory, or specified literal value. A single secret may package one or more key/value pairs. When creating a secret based on a file, the key will default to...
Delete the pods and services named "backend"
Command: ```bash kubectl delete pod,service backend 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....
Remove the environment variable ENV from the container 'mycontainer' in all deployment configs.
Command: ```bash kubectl set env deployments --all --containers="mycontainer" ENV- ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more pod templates (...
Create an ingress named 'private-service-ingress' with a rule that directs requests from testing.com/example to svc1:8082
Command: ```bash kubectl create ingress private-service-ingress --rule="testing.com/example=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...
Forward local data from ports 8888 and 6000 to the 'frontend-pod' pod's ports 8000 and 6000
Command: ```bash kubectl port-forward pod/frontend-pod 8888 8000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected autom...
Add a taint with key 'workload' on nodes having label version=v1.0.0
Command: ```bash kubectl taint node -l version=v1.0.0 workload=backup-node-14: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...
Retrieve previous terminated logs from the "warp-drive" container in the "api-service-pod" pod.
Command: ```bash kubectl logs -p -c warp-drive api-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", "s...
Show metrics for a specific pod and its containers
Command: ```bash kubectl top pod proxy-server-pod --containers ``` What it does: Display resource (CPU/memory) usage of pods. The 'top pod' command allows you to see the resource consumption of pods. Due to the metrics pipeline delay, they may be unavailable for a few minutes since pod creation. Syntax: `kubectl top ...
Create a service for the replication controller specified in "php-controller.yaml", serving on port 8089 and connecting to the containers on port 844300
Command: ```bash kubectl expose -f php-controller.yaml --port=8089 --target-port=844300 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the sp...
Add an annotation to the 'backend' pod, set the annotation 'expiration-date' to '2024-12-31'.
Command: ```bash kubectl annotate pods backend 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 include a...
Execute the 'mysql --version' command inside the 'api-service-pod' pod and display the output
Command: ```bash kubectl exec api-service-pod -- mysql --version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the k...
Copy the /tmp/foo_dir directory from the metrics-exporter-pod-10 pod in the default namespace, and paste it in the /tmp/bar directory locally.
Command: ```bash kubectl cp default/metrics-exporter-pod-10:/tmp/foo_dir :/tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use t...
Forward traffic from local port 8888 to port 8000 in the backend pod
Command: ```bash kubectl port-forward pod/backend-pod 8888: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...
Create a service for a replicated node, which serves on port 3000 and connects to the containers on port 8080
Command: ```bash kubectl expose rc node --port=3000 --target-port=808800 ``` 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...
Forward traffic between local ports 8888 and pod ports 8888.
Command: ```bash kubectl port-forward pod/mypod 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 automaticall...
Create a copy of the 'payment-gateway-pod' pod and change all container images to 'docker.elastic.co/elasticsearch/elasticsearch'
Command: ```bash kubectl debug payment-gateway-pod --copy-to=debug-image-web --set-image=*=docker.elastic.co/elasticsearch/elasticsearch ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource an...
Update the annotation of the pod 'chat-app' with the key 'deployment-script' and the value 'https://example.com/deploy.sh'.
Command: ```bash kubectl annotate pods chat-app deployment-script='https://example.com/deploy.sh' ``` 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 tha...
Partially update the 'node-2' node by applying a strategic merge patch with the specified JSON
Command: ```bash kubectl patch node node-2 -p '{"spec":{"someField":"newValue"}' ``` 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 f...
Remove the taint with key 'special' and effect 'NoSchedule' from the node 'edge-node-10' if it exists.
Command: ```bash kubectl taint nodes edge-node-10 special:NoSchedule- ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of:...
Attach to the running 'cdn-service-pod' pod and select the container specified by the 'kubectl.kubernetes.io/default-container' annotation.
Command: ```bash kubectl attach cdn-service-pod ``` 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...
Update the image of all containers in the daemonset namespace-2 to 'postgres:13.4'
Command: ```bash kubectl set image daemonset namespace-2 *=postgres:13.4 ``` What it does: Update existing container image(s) of resources. Possible resources include (case insensitive): pod (po), replicationcontroller (rc), deployment (deploy), daemonset (ds), statefulset (sts), cronjob (cj), replicaset (rs) Syntax:...
Change the cluster field in the specified context to the given value
Command: ```bash kubectl config set contexts.cluster-1-context.cluster kube-cluster-1 ``` What it does: Set an individual value in a kubeconfig file. PROPERTY_NAME is a dot delimited name where each token represents either an attribute name or a map key. Map keys may not contain dots. PROPERTY_VALUE is the new value ...
Forward local port 3000 to port 8888 in the pod "mypod"
Command: ```bash kubectl port-forward pod/mypod 3000: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 automaticall...
Add a taint with the key 'hardware' on nodes having the label stack=tech-stack
Command: ```bash kubectl taint node -l stack=tech-stack hardware=web-node-8:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage":...
Create an ingress called 'public-service-ingress' with a rule that directs requests from testing.com/module to svc1:9091
Command: ```bash kubectl create ingress public-service-ingress --rule="testing.com/module=svc1:9091,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default":...
Execute the 'wp' command in the 'mycontainer' container of the 'media-stream-pod' pod and get the output.
Command: ```bash kubectl exec media-stream-pod -c mycontainer -- wp ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use th...
run the command 'docker run ubuntu echo "Hello, World"' inside the first container of the first pod belonging to the 'proxy-service' service
Command: ```bash kubectl exec svc/proxy-service -- docker run ubuntu echo "Hello, World" ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container nam...
List the replication controllers with the name "web", services with the name "auth-service-rc", and pods with the name "auth-service-pod".
Command: ```bash kubectl get rc/web service/auth-service-rc pods/auth-service-pod ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is name...
create a cron job named email-notifications with an image "wordpress", schedule it to run every minute, and execute the command "wp"
Command: ```bash kubectl create cronjob email-notifications --image=wordpress --schedule="*/1 * * * *" -- wp ``` 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...
Add a taint with key 'zone' on nodes having label feature=feature-xyz
Command: ```bash kubectl taint node -l feature=feature-xyz zone=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": "", "usa...
Run the 'mysql' command inside the 'cdn-service-pod' pod
Command: ```bash kubectl exec cdn-service-pod -- mysql ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubectl.kub...
Start a new nginx pod using the amazonlinux image, but override the pod specification with specific values provided in a JSON format.
Command: ```bash kubectl run nginx --image=amazonlinux --overrides='{ "apiVersion": "v3.0.0", "spec": { ... } }' ``` 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] -- [C...
Retrieve the phase value of the security-service-pod pod.
Command: ```bash kubectl get -o template pod/security-service-pod --template={{.status.phase}} ``` 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...