prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Create a debug container based on the e-commerce-pod and set the image of all containers in the debug container to hazelcast/hazelcast
Command: ```bash kubectl debug e-commerce-pod --copy-to=dgb-img --set-image=*=hazelcast/hazelcast ``` 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...
Forward port 3000 on all addresses to port 8080 in the pod named "analytics-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/analytics-pod 3000:8080 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod wil...
Copy the local file "foo" located in "/tmp" to the remote pod "logging-agent-pod-7" in the container "metrics-exporter" in the "/etc/kubernetes" directory.
Command: ```bash kubectl cp :/tmp/foo logging-agent-pod-7:/etc/kubernetes -c metrics-exporter ``` 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 omi...
Set a custom TLS server name to use for validation for the "sun-cluster" cluster entry.
Command: ```bash kubectl config set-cluster sun-cluster --tls-server-name=star-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-...
Create a deployment named 'cache' that runs the 'mysql' image with 4 replicas.
Command: ```bash kubectl create deployment cache --image=mysql --replicas=4 ``` 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: js...
Create a new config map named app-config using specified keys instead of file basenames on disk.
Command: ```bash kubectl create configmap app-config --from-file=conf=/path/to/settings/file1.txt --from-file=data=/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 confi...
Forward local port 6379 to pod port 8081 in the monitoring-stack-deployment deployment
Command: ```bash kubectl port-forward deployment/monitoring-stack-deployment 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 criteria, a pod ...
Update the image of a container in a pod named "database-pod"
Command: ```bash kubectl patch pod database-pod -p '{"spec":{"containers":[{"name":"kubernetes-serve-hostname","image":"new image"}]}}' ``` 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 FILENAM...
Create an ingress rule named 'private-api-ingress' that directs requests from foo.com/module to svc1:8000 with a tls secret named "my-cert"
Command: ```bash kubectl create ingress private-api-ingress --rule="foo.com/module=svc1:8000,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "u...
Import specific keys from a config map to environment variables for a deployment
Command: ```bash kubectl set env --keys=DATABASE_URL --from=configmap/log-config deployment/gateway-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...
Configure the OpenID Connect auth provider for the "operator" entry by setting the following arguments: client-id=foo and client-secret=bar
Command: ```bash kubectl config set-credentials operator --auth-provider=oidc --auth-provider-arg=client-id=foo --auth-provider-arg=client-secret=bar ``` 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: --cl...
Update the annotation 'owner' of the pod named 'media-stream' with the value 'alice-smith', and overwrite any existing value.
Command: ```bash kubectl annotate --overwrite pods media-stream owner='alice-smith' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels and i...
Scale the deployment named api-service-rs to 5 replicas if its current size is 7.
Command: ```bash kubectl scale --current-replicas=7 --replicas=5 deployment/api-service-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-vers...
Start a pod named 'nginx' using the 'mcr.microsoft.com/dotnet/core/runtime' image
Command: ```bash kubectl run nginx --image=mcr.microsoft.com/dotnet/core/runtime --overrides='{ "apiVersion": "v2.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=inli...
Describe pods with label app=web-app
Command: ```bash kubectl describe po -l app=web-app ``` 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, provide a...
Set the custom TLS server name to "cluster-gamma" for validation of the "on-prem-cluster" cluster entry.
Command: ```bash kubectl config set-cluster on-prem-cluster --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] [--certifi...
Create a cluster role named "default_role" that allows a user to perform "list", "create", and "connect" actions on pods
Command: ```bash kubectl create clusterrole default_role --verb=list,create,connect --resource=pods ``` 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",...
Return the snapshot logs from the container "payment-processor-deployment-1" of the deployment named "proxy-service-pod"
Command: ```bash kubectl logs deployment/payment-processor-deployment -c proxy-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 fl...
List deployments in YAML output format, using the "v1.1.1" version of the "experimental-apps" API group.
Command: ```bash kubectl get deployments.v1.1.1.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...
Create a new ExternalName service named external-geolocation-service that points to the external domain test-site.org
Command: ```bash kubectl create service externalname external-geolocation-service --external-name test-site.org ``` What it does: Create an ExternalName service with the specified name. ExternalName service references to an external DNS address instead of only pods, which will allow application authors to reference se...
Execute 'dotnet' command in the first pod of the deployment 'gateway-deployment' and get the output.
Command: ```bash kubectl exec deploy/gateway-deployment -- 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 omitted, use the ...
Forward port 8888 on localhost and the IP 10.19.21.23 to port 5000 in the pod named "api-service-pod"
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/api-service-pod 8888:5000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the cri...
Forward traffic from port 6379 on all addresses to port 3000 in the backend-pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/backend-pod 6379: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 ...
Copy the file `/tmp/foo` from the remote pod `velero/cache-pod-5` to the local directory `/tmp/bar_dir`
Command: ```bash kubectl cp velero/cache-pod-5::/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 the kubectl.ku...
Import specific keys from a config map to the environment variables of a deployment.
Command: ```bash kubectl set env --keys=max_connections --from=configmap/app-config-prod deployment/proxy-service-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable ...
Create a LoadBalancer service named media-stream-lb that maps incoming traffic on port 9000 to port 8888.
Command: ```bash kubectl create service loadbalancer media-stream-lb --tcp=9000:8888 ``` What it does: Create a LoadBalancer service with the specified name. Syntax: `kubectl create service loadbalancer NAME [--tcp=port:targetPort] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "de...
Copy the local file "/tmp/foo" to the remote pod "ingress-controller-pod-8" in the namespace "logging"
Command: ```bash kubectl cp :/tmp/foo logging/ingress-controller-pod-8:/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, u...
Add a taint to the node 'edge-node-10' with the key 'cpu-type', value 'x86', and effect 'NoSchedule'
Command: ```bash kubectl taint nodes edge-node-10 cpu-type=x86: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...
Autoscale the replication controller "payment" with a minimum of 1 pod, a maximum of 7 pods, and a target CPU utilization of 20%.
Command: ```bash kubectl autoscale rc payment --max=7 --cpu-percent=20 ``` 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...
Import the SMTP_SERVER key from the app-config config map and set it as an environment variable in the user-management-deployment deployment.
Command: ```bash kubectl set env --keys=SMTP_SERVER --from=configmap/app-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 variable definit...
Create a cron job named 'metrics-collection' using the 'python' image, with a schedule of running every minute, and executing the 'python' command.
Command: ```bash kubectl create cronjob metrics-collection --image=python --schedule="*/1 * * * *" -- python ``` 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...
Execute the command 'jenkins --version' in the container 'quantum-quark' inside the 'database-pod' pod
Command: ```bash kubectl exec database-pod -c quantum-quark -- jenkins --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 om...
Create a cluster role named "bar" with permissions to perform proxy, update, and patch actions on the endpoints and endpoints/status subresources
Command: ```bash kubectl create clusterrole bar --verb=proxy,update,patch --resource=endpoints,endpoints/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: "flag":...
Update the annotation of a pod with a new value, overwriting any existing value.
Command: ```bash kubectl annotate --overwrite pods email owner='alice-smith' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels and include ...
Import specific keys from a config map into an environment variable for a deployment.
Command: ```bash kubectl set env --keys=redis_host --from=configmap/global-config 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 defi...
Forward local port 8000 to pod port 3000
Command: ```bash kubectl port-forward deployment/email-server-deployment 8000 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...
Update the 'gateway' pod with the annotation 'backup-strategy' and set the value to 'daily backups'
Command: ```bash kubectl annotate pods gateway backup-strategy='daily backups' ``` 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 includ...
Create a debug pod named 'debug-image-web' as a copy of 'security-service-pod', with all container images set to 'ruby'
Command: ```bash kubectl debug security-service-pod --copy-to=debug-image-web --set-image=*=ruby ``` 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 an horizontal autoscaler for the replication controller "database", with a minimum of 1 pod, a maximum of 3 pods, and a target CPU utilization of 40%.
Command: ```bash kubectl autoscale rc database --max=3 --cpu-percent=40 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that use...
Create a copy of the 'email-service-pod' pod and add a debug container to it
Command: ```bash kubectl debug email-service-pod -it --copy-to=debug-image-api --image=debian --set-image=scheduler=my-scheduler:1.0,proxy=nginx:1.21 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified b...
Set custom TLS server name for cluster kube-cluster-2
Command: ```bash kubectl config set-cluster kube-cluster-2 --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...
Annotate the pod 'api' with the annotation 'deployment-script' and the value 'https'
Command: ```bash kubectl annotate --overwrite pods api 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 lar...
Output modified deployment in YAML without making any changes on the server
Command: ```bash kubectl set env deployment/cache-cluster-deployment GOOGLE_API_KEY=your-google-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 i...
Create an ingress called 'external-ingress' with a rule that directs requests from website.com/example to svc1:7000
Command: ```bash kubectl create ingress external-ingress --rule="website.com/example=svc1:7000,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", ...
Display the most recent 20 lines of logs for a pod named "database-pod".
Command: ```bash kubectl logs --tail=20 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": "-c...
Create an ingress resource named 'public-api-ingress' with a rule that directs requests to testing.com/module to the service named svc1 on port 9091
Command: ```bash kubectl create ingress public-api-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": "",...
Create a new config map named app-config-dev using specific file paths and keys instead of file basenames on disk.
Command: ```bash kubectl create configmap app-config-dev --from-file=settings=/path/to/preferences/file1.txt --from-file=key2=/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 cr...
Forward port 3000 from the pod "log-aggregator-pod" to port 3000 on localhost and IP address 10.19.21.23
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/log-aggregator-pod 3000:3000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the ...
Create a service for the 'ubuntu' deployment, which serves on port 3001 and connects to the containers on port 844300.
Command: ```bash kubectl expose deployment ubuntu --port=3001 --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 specifi...
List the specified resources by their type and names
Command: ```bash kubectl get rc/web service/e-commerce-rc pods/web-app-pod ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced ...
Describe all configmaps managed by the 'frontend' replication controller.
Command: ```bash kubectl describe configmaps frontend ``` 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, provide...
Add a taint with a key 'environment' and value 'app-node-6:PreferNoSchedule' on nodes having label 'release=beta'.
Command: ```bash kubectl taint node -l release=beta environment=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": ...
Add a taint to the node 'backup-node-14' with the key 'disktype' and no value
Command: ```bash kubectl taint nodes backup-node-14 disktype: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...
Create a new config map named "db-config" with specified keys and corresponding file paths
Command: ```bash kubectl create configmap db-config --from-file=properties=/path/to/properties/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 creatin...
Create a new config map named "app-config-dev" with specified keys instead of file basenames on disk.
Command: ```bash kubectl create configmap app-config-dev --from-file=settings=/path/to/profiles/file1.txt --from-file=key2=/path/to/options/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 ...
Forward data between your local machine's port 8080 and a selected pod's port 8080 in the 'analytics-platform-deployment' deployment.
Command: ```bash kubectl port-forward deployment/analytics-platform-deployment 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 po...
Set the custom TLS server name "moon-cluster" to use for validation for the e2e cluster entry.
Command: ```bash kubectl config set-cluster e2e --tls-server-name=moon-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-authorit...
Listen on port 3000 on all addresses and forward to port 9090 in the log-aggregator-pod pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/log-aggregator-pod 3000: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 po...
Create a pod disruption budget named batch-processing-pdb that will select all pods with the component=web label and require at least one of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget batch-processing-pdb --selector=component=web --min-available=1 ``` 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-availab...
Forward traffic between local ports 3000 and 6000 and ports 3000 and 6000 in the pod
Command: ```bash kubectl port-forward pod/mypod 3000 3000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automaticall...
Set custom TLS server name for cluster e2e to "cluster-beta"
Command: ```bash kubectl config set-cluster e2e --tls-server-name=cluster-beta ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certificate-authorit...
Add a taint with the key 'workload' and the value 'k8s-node-1:PreferNoSchedule' on nodes with the label 'customer=acme-corp'
Command: ```bash kubectl taint node -l customer=acme-corp workload=k8s-node-1:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage...
Update the deployment 'proxy-service-deployment' with a new environment variable 'S3_BUCKET' set to 'my-s3-bucket'.
Command: ```bash kubectl set env deployment/proxy-service-deployment S3_BUCKET=my-s3-bucket ``` 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...
Create a service for a replication controller specified in "php-controller.yaml", serving on port 80 and connecting to containers on port 8000.
Command: ```bash kubectl expose -f php-controller.yaml --port=8083 --target-port=808900 ``` 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...
Update the 'web' pod with the annotation 'custom-label' and the value 'my-custom-value', replacing any existing value
Command: ```bash kubectl annotate --overwrite pods web 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...
Forward local port 8088 to port 8080 in the pod with the name log-aggregator-pod
Command: ```bash kubectl port-forward pod/log-aggregator-pod 8088: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...
Create a secret named aws-credentials-secret using files from the folder "path/to/parameters"
Command: ```bash kubectl create secret generic aws-credentials-secret --from-file=path/to/parameters ``` 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 bas...
Start a new pod named "hazelcast" using the mysql image and expose port 9090
Command: ```bash kubectl run hazelcast --image=mysql --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...
Create a debug container in the gateway-pod, named debug-image-app, with the image set to "debian"
Command: ```bash kubectl debug gateway-pod -it --copy-to=debug-image-app --image=debian --set-image=proxy=nginx:1.21,proxy=nginx:1.21 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and n...
Create a new config map named monitoring-config with the specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap monitoring-config --from-file=properties=/path/to/profiles/file1.txt --from-file=key1=/path/to/options/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 crea...
Add a taint to node 'monitoring-node-15' with key 'disktype', value 'ssd', and effect 'NoSchedule'
Command: ```bash kubectl taint nodes monitoring-node-15 disktype=ssd: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 forma...
Copy the file "foo" from the remote pod "auth-service-pod-11" in the "logging" namespace to the local directory "/etc/kubernetes".
Command: ```bash kubectl cp logging/auth-service-pod-11:/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...
Switch to raw terminal mode and connect to the frontend-pod container named time-machine in order to interact with 'bash'.
Command: ```bash kubectl attach frontend-pod -c time-machine -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...
Execute the 'mongo' command inside the 'time-machine' container of the 'auth-service-pod' pod and get the output.
Command: ```bash kubectl exec auth-service-pod -c time-machine -- mongo ``` 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...
Create a single ingress called 'private-service-ingress' that directs requests to foo.com/bar to svc1:27017 with a tls secret "my-cert"
Command: ```bash kubectl create ingress private-service-ingress --rule="foo.com/bar=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": "", ...
Add a taint with key 'datacenter' on nodes having label team=devops and value backup-node-14 with the effect of PreferNoSchedule.
Command: ```bash kubectl taint node -l team=devops datacenter=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"...
Forward traffic from a local random port to port 5432 in the pod named log-aggregator-pod
Command: ```bash kubectl port-forward pod/log-aggregator-pod :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 aut...
Add a taint to nodes with specific label
Command: ```bash kubectl taint node -l app-type=microservice special=node-1:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage":...
Add a taint with key 'special' on nodes having label 'namespace=mynamespace'
Command: ```bash kubectl taint node -l namespace=mynamespace special=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": "", "...
Auto scale the "vpn" deployment with the number of pods between 7 and 10, using the default autoscaling policy
Command: ```bash kubectl autoscale deployment vpn --min=7 --max=10 ``` 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...
Create a new configmap named namespace-config with specified keys from file paths
Command: ```bash kubectl create configmap namespace-config --from-file=conf=/path/to/configurations/file1.txt --from-file=data=/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 creat...
Auto scale the "auth" deployment with a minimum of 5 pods and a maximum of 10 pods using the default autoscaling policy
Command: ```bash kubectl autoscale deployment auth --min=5 --max=10 ``` 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 th...
Copy the local file /tmp/foo to the remote pod file-server-pod-14 in the /tmp/bar directory, using the image-resizer container.
Command: ```bash kubectl cp :/tmp/foo file-server-pod-14:/tmp/bar -c image-resizer ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use t...
Remove all the taints with the key 'app' from the 'k8s-node-1' node
Command: ```bash kubectl taint nodes k8s-node-1 app- ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: json|yaml|name|g...
create a service for the replication controller specified in "wordpress-controller.yaml" file, which will serve on port 80 and connect to the containers on port 8000
Command: ```bash kubectl expose -f wordpress-controller.yaml --port=8089 --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 ...
Create a service for a replicated WordPress application, serving on port 8081 and connecting to the containers on port 700000.
Command: ```bash kubectl expose rc wordpress --port=8081 --target-port=700000 ``` 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 po...
Forward traffic from port 8088 on all addresses to port 8080 in the pod named "security-service-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/security-service-pod 8088: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 ...
Embed the certificate authority data for the cluster entry named 'my-k8s-cluster' by running the command 'kubectl config set-cluster my-k8s-cluster --embed-certs --certificate-authority=~/.kube/cluster-gamma/kubernetes.ca.crt'
Command: ```bash kubectl config set-cluster my-k8s-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 ...
Update the label of the pod named 'cdn' with the key 'status' and the value 'unhealthy', replacing any existing value
Command: ```bash kubectl label --overwrite pods cdn status=unhealthy ``` 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"...
Create a priority class named 'marketing-priority' with a value of 300, a description of "Priority for marketing-related tasks", and a preemption policy of "Never"
Command: ```bash kubectl create priorityclass marketing-priority --value=300 --description="Priority for marketing-related tasks" --preemption-policy="Never" ``` What it does: Create a priority class with the specified name, value, globalDefault and description. Syntax: `kubectl create priorityclass NAME --value=VALU...
Copy the local file /tmp/foo to the /etc/kubernetes directory in the front-end-pod-12 pod's database-container container.
Command: ```bash kubectl cp /tmp/foo front-end-pod-12:/etc/kubernetes -c database-container ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitt...
Forward local port 6379 to port 6379 in the frontend-pod
Command: ```bash kubectl port-forward pod/frontend-pod 6379 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 autom...
Update the pod 'backend' with a description of 'my frontend running nginx' only if the resource is unchanged from version 1.
Command: ```bash kubectl annotate pods backend description='my frontend running nginx' --resource-version=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 ...
Create a service with the name 'hazelcast' using the replica set, which will serve on port 3001 and connect to the containers on port 500100.
Command: ```bash kubectl expose rs hazelcast --port=3001 --target-port=500100 ``` 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 po...
Create a pod disruption budget named database-pdb that selects all pods with the component=web label, and requires a minimum of 9 of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget database-pdb --selector=component=web --min-available=9 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-available=N [--...
Create a new config map named app-settings with the specified keys and their respective file paths --from-file=settings=/path/to/preferences/file1.txt and --from-file=key2=/path/to/configurations/file2.txt
Command: ```bash kubectl create configmap app-settings --from-file=settings=/path/to/preferences/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...
Create a deployment named "jenkins" with 2 replicas running the "mysql" image.
Command: ```bash kubectl create deployment jenkins --image=mysql --replicas=2 ``` 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: ...
Add a taint with the key 'zone' on nodes that have the label 'component=proxy'
Command: ```bash kubectl taint node -l component=proxy zone=node-2: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 ...
Create a new config map named 'app-secrets' using the files 'file1.txt' and 'file2.txt'
Command: ```bash kubectl create configmap app-secrets --from-file=conf=/path/to/data/file1.txt --from-file=data=/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 creating a confi...
Create a new ClusterIP service named git-service-clusterip that forwards traffic from port 8089 to port 9000.
Command: ```bash kubectl create service clusterip git-service-clusterip --tcp=8089:9000 ``` What it does: Create a ClusterIP service with the specified name. Syntax: `kubectl create service clusterip NAME [--tcp=<port>:<targetPort>] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "d...