prompt
stringlengths
13
282
response
stringlengths
128
3.11k
View the output from the time-machine container in the security-service-pod
Command: ```bash kubectl attach security-service-pod -c time-machine ``` 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 omi...
Add a taint with the key 'disktype' on nodes that have the label 'stack=tech-stack'
Command: ```bash kubectl taint node -l stack=tech-stack disktype=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": "", "us...
Create a new secret named tls-certificate-secret with keys for each file in folder 'path/to/profiles'
Command: ```bash kubectl create secret generic tls-certificate-secret --from-file=path/to/profiles ``` What it does: Create a secret based on a file, directory, or specified literal value. A single secret may package one or more key/value pairs. When creating a secret based on a file, the key will default to the basen...
Add a taint with the key 'workload' and the value 'testing-node-11:PreferNoSchedule' on nodes that have the label 'stack=tech-stack'
Command: ```bash kubectl taint node -l stack=tech-stack workload=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": "", "us...
Create an ingress called 'ingtls' with TLS enabled using the default ingress certificate
Command: ```bash kubectl create ingress ingtls --class=default \ --rule="site.com/=svc:https,tls" \ --rule="website.com/path/subpath*=othersvc:8181" ``` 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": "...
Scale the mysql deployment to 7 replicas to match the current size of the webapp-replicaset deployment.
Command: ```bash kubectl scale --current-replicas=7 --replicas=7 deployment/webapp-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...
Update the expiration-date annotation of a pod in the pod.json file.
Command: ```bash kubectl annotate -f pod.json 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 ar...
Import the environment from the 'aws-credentials-secret' secret to the 'analytics-platform-deployment' deployment.
Command: ```bash kubectl set env --from=secret/aws-credentials-secret deployment/analytics-platform-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...
Expose a service with a different name and port
Command: ```bash kubectl expose service php --port=443 --target-port=3000 --name=nginx-https ``` 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 t...
Create a new config map named app-config using specific keys instead of file basenames on disk
Command: ```bash kubectl create configmap app-config --from-file=conf=/path/to/configurations/file1.txt --from-file=data=/path/to/settings/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a...
Set the resource request and limits for all containers in the 'ruby' deployment
Command: ```bash kubectl set resources deployment ruby --limits=cpu=200m,memory=512Mi --requests=cpu=2,memory=256Mi ``` 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,...
Create a cluster role named "foo" with specific resource names
Command: ```bash kubectl create clusterrole foo --verb=create --resource=services --resource-name=queue-consumer --resource-name=backup-service ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|clien...
Create a job named report-generation-job using the image confluentinc/cp-kafka
Command: ```bash kubectl create job report-generation-job --image=confluentinc/cp-kafka -- kafka-console-producer --broker-list localhost:9092 --topic test ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flag...
Execute the command 'go version' in the code-explorer container of the auth-service-pod and retrieve the output.
Command: ```bash kubectl exec auth-service-pod -c code-explorer -- go version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitt...
Listen for incoming traffic on port 3000 on your local machine and forward it to port 8080 in the 'proxy-server-pod' pod.
Command: ```bash kubectl port-forward pod/proxy-server-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 will be selected a...
import the API_KEY key from the namespace-config config map into the api-server-deployment deployment
Command: ```bash kubectl set env --keys=API_KEY --from=configmap/namespace-config deployment/api-server-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definition...
Open a raw terminal to the "api-service-pod" container named "stardust-shuttle", allowing input and output from the client.
Command: ```bash kubectl attach api-service-pod -c stardust-shuttle -i -t ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. I...
Create a cron job named "report-generation" that runs a command using the "redis" image every minute
Command: ```bash kubectl create cronjob report-generation --image=redis --schedule="*/1 * * * *" -- redis-server --version ``` 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"...
Forward traffic from port 8000 on both localhost and IP address 10.19.21.23 to port 6379 in the 'proxy-server-pod' pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/proxy-server-pod 8000:6379 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the cr...
Create a copy of 'analytics-pod' and add a debug container with the images 'debian' and 'redis:alpine' for the containers 'cache' and 'mailer' respectively, and name it 'my-custom-dbg'.
Command: ```bash kubectl debug analytics-pod -it --copy-to=my-custom-dbg --image=debian --set-image=cache=redis:alpine,mailer=mailer:latest ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource...
Import the MAX_CONNECTIONS key from the config map 'api-config' and set it as an environment variable in the deployment 'api-server-deployment'
Command: ```bash kubectl set env --keys=MAX_CONNECTIONS --from=configmap/api-config deployment/api-server-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definiti...
Set the resource request and limits for all containers in the node deployment
Command: ```bash kubectl set resources deployment node --limits=cpu=200m,memory=512Mi --requests=cpu=10,memory=4Gi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requested, ...
Change the service account of the 'mydeployment' deployment to 'metrics-server'
Command: ```bash kubectl set serviceaccount deployment mydeployment metrics-server ``` 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: `kubectl s...
Forward local port 6379 to port 3000 in the cdn-service-pod pod
Command: ```bash kubectl port-forward pod/cdn-service-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 be selected au...
Forward all incoming traffic on port 8000 to port 8080 in the 'log-aggregator-pod' pod, listening on all addresses.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/log-aggregator-pod 8000: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...
Copy the directory /tmp/foo_dir from the remote pod message-broker-pod-15 in the kube-node-lease namespace to the local directory /tmp/bar_dir.
Command: ```bash kubectl cp kube-node-lease/message-broker-pod-15:/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...
View the logs from container "notification-handler-deployment-1" of the deployment named "monitoring-pod"
Command: ```bash kubectl logs deployment/notification-handler-deployment -c monitoring-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...
Execute 'ash' command in payment-service pod
Command: ```bash kubectl exec svc/payment-service -- 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.k...
Copy the file "/tmp/foo" from the remote pod "security-scanner-pod-18" in the "default" namespace to the local directory "/tmp/bar_dir"
Command: ```bash kubectl cp default/security-scanner-pod-18::/tmp/foo /tmp/bar_dir ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use t...
Set the service account of the deployment named cache-cluster-deployment to "tiller"
Command: ```bash kubectl set serviceaccount deployment cache-cluster-deployment tiller ``` 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: `kubec...
Import specific keys from a config map into a deployment.
Command: ```bash kubectl set env --keys=external_api_url --from=configmap/kube-system-config deployment/frontend-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable d...
Set the label 'unhealthy=true' for the pod named 'web'
Command: ```bash kubectl label pods web unhealthy=true ``` 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": "If...
View the environment variables defined on the 'load-balancer-deployment' deployment.
Command: ```bash kubectl set env deployment/load-balancer-deployment --list ``` 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 (within ...
Listen on all addresses on port 5000 and forward traffic to port 8888 in the 'backend-pod' pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/backend-pod 5000: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 ...
Import the "log_level" key from the "monitoring-config" ConfigMap and set it as an environment variable for the "mydeployment" deployment.
Command: ```bash kubectl set env --keys=log_level --from=configmap/monitoring-config deployment/mydeployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in o...
Check if you have permission to list the job named "cron-job" in the "kube-ingress" namespace
Command: ```bash kubectl auth can-i list jobs.batch/cron-job -n kube-ingress ``` 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 URL that...
Jump into raw terminal mode for the "cosmic-container" in the "media-stream-pod" pod
Command: ```bash kubectl attach media-stream-pod -c cosmic-container -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. ...
Remove the 'NoExecute' taint with key 'datacenter' from node 'backup-node-14'
Command: ```bash kubectl taint nodes backup-node-14 datacenter:NoExecute- ``` 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...
Create a new config map named 'app-secrets' using the provided files as key-value pairs
Command: ```bash kubectl create configmap app-secrets --from-file=properties=/path/to/configs/file1.txt --from-file=key1=/path/to/parameters/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating...
Forward traffic from local port 8088 to port 8080 in the pod named cdn-service-pod
Command: ```bash kubectl port-forward pod/cdn-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 pod will be selected au...
restart the 'test' deployment
Command: ```bash kubectl rollout restart deployment/test ``` What it does: Restart a resource. Resource rollout will be restarted. Syntax: `kubectl rollout restart RESOURCE` Helpful flags: "flag": "--filename", "short": "-f", "default": "[]", "usage": "Filename, directory, or URL to files identifying the resource to...
Copy the directory '/var/run/secrets/kubernetes.io/serviceaccount/' from the remote pod 'admin-dashboard-pod-16' to the local directory '/tmp/bar'
Command: ```bash kubectl cp openfaas/admin-dashboard-pod-16:/var/run/secrets/kubernetes.io/serviceaccount/ /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": "...
Embed the certificate authority data into the 'dev-cluster' cluster entry using the certificate authority file located at '~/.kube/galaxy-cluster/kubernetes.ca.crt'
Command: ```bash kubectl config set-cluster dev-cluster --embed-certs --certificate-authority=~/.kube/galaxy-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...
Scale the deployment named web to 7 replicas, maintaining the current number of replicas as 7.
Command: ```bash kubectl scale --current-replicas=7 --replicas=7 deployment/web ``` 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...
Remove all taints with the key 'hardware' from the node 'storage-node-13'
Command: ```bash kubectl taint nodes storage-node-13 hardware- ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: json|y...
delete all pods and services with the label "myLabel"
Command: ```bash kubectl delete pods,services -l myLabel ``` 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...
Create a deployment named prometheus that runs the ubuntu image and exposes port 5000.
Command: ```bash kubectl create deployment prometheus --image=ubuntu --port=5000 ``` What it does: Create a deployment with the specified name. Syntax: `kubectl create deployment NAME --image=image -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One o...
Execute the `elasticsearch --version` command in the code-explorer container of the backend-pod and get the output.
Command: ```bash kubectl exec backend-pod -c code-explorer -- elasticsearch --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. ...
Set custom TLS server name for cluster entry "app-cluster" to "cluster-gamma"
Command: ```bash kubectl config set-cluster app-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] [--certificate...
Update the pod 'chat-app' with the annotation 'owner' and set the value 'alice smith'
Command: ```bash kubectl annotate pods chat-app 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 arbitrary...
Forward local port 3000 to port 3000 in the pod selected by the 'authentication-service-deployment' deployment.
Command: ```bash kubectl port-forward deployment/authentication-service-deployment 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, ...
Get the output from running the 'bash' command inside the pod named 'backend-pod', using the first container in the pod.
Command: ```bash kubectl exec backend-pod -- bash ``` 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.kubernet...
Create a new config map named app-config-dev from the environment file located at path/to/preferences.env
Command: ```bash kubectl create configmap app-config-dev --from-env-file=path/to/preferences.env ``` 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...
Forward local port 8080 to port 5000 in a specific pod
Command: ```bash kubectl port-forward pod/proxy-server-pod 8080: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 a...
Wait for a pod to be deleted
Command: ```bash kubectl delete pod/database-pod kubectl wait --for=delete pod/busybox1 --timeout=60s ``` What it does: Experimental: Wait for a specific condition on one or many resources. The command takes multiple resources and waits until the specified condition is seen in the Status field of every given resource....
Add the annotation 'last-deployment=2023-03-15' to the 'analytics' pod
Command: ```bash kubectl annotate pods analytics last-deployment=2023-03-15 ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels and include a...
Retrieve the output from running the 'ruby --version' command in the 'astro-container' from the 'log-aggregator-pod'.
Command: ```bash kubectl exec log-aggregator-pod -c astro-container -- ruby --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. ...
Forward local and selected IP's port 9090 to pod's port 8888
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/e-commerce-pod 9090:8888 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the crit...
Connect to a running pod and attach to a specific container to interact with it in real-time.
Command: ```bash kubectl attach payment-gateway-pod -c nebula-navigator -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 nam...
Add a taint with key 'dedicated' on nodes having label release=beta
Command: ```bash kubectl taint node -l release=beta dedicated=gpu-node-12: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": "...
Scale the replica set 'payment-service-rs' to 7 replicas
Command: ```bash kubectl scale --replicas=7 rs/payment-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-version is specified, it is v...
import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=EXTERNAL_API_URL --from=configmap/ui-config deployment/monitoring-stack-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable de...
Attach to the 'warp-drive' container and get the output from the 'email-service-pod' pod.
Command: ```bash kubectl attach email-service-pod -c warp-drive ``` 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,...
Get the output from running the 'redis-cli' command in the 'cyber-sleuth' container from the 'api-service-pod' pod.
Command: ```bash kubectl exec api-service-pod -c cyber-sleuth -- redis-cli ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted,...
Set the custom TLS server name to 'star-cluster' for the 'web-cluster' cluster entry
Command: ```bash kubectl config set-cluster web-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 job called 'report-generation-job' using the 'confluentinc/cp-kafka' image, and run the command 'kafka-topics --list' within the job.
Command: ```bash kubectl create job report-generation-job --image=confluentinc/cp-kafka -- kafka-topics --list ``` 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", "defaul...
Create a copy of the e-commerce-pod into a new debugging pod named my-custom-dbg, with the warp-drive container, and launch an interactive shell.
Command: ```bash kubectl debug e-commerce-pod -it --copy-to=my-custom-dbg --container=warp-drive -- sh ``` 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 defau...
Copy the `~/.config/kube` local file to `/tmp/bar_dir` inside the `argocd/cache-pod-5` pod in the current namespace.
Command: ```bash kubectl cp ~/.config/kube argocd/cache-pod-5:/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 kubec...
Start a redis pod named nginx, but override the spec with a partial set of values parsed from JSON
Command: ```bash kubectl run nginx --image=redis --overrides='{ "apiVersion": "beta-1.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] -- [COMMA...
Update the annotation of pod 'api' with the value 'daily backups' for the annotation 'backup-strategy'
Command: ```bash kubectl annotate pods api 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 include ar...
Forward local port 8888 to port 8081 in the pod "api-service-pod"
Command: ```bash kubectl port-forward pod/api-service-pod 8888: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 au...
Update the image of all containers in the daemonset "namespace-2" to "mongo:5.0.2".
Command: ```bash kubectl set image daemonset namespace-2 *=mongo:5.0.2 ``` 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: `...
Forward local port 5000 to port 8080 in the pod "web-app-pod"
Command: ```bash kubectl port-forward pod/web-app-pod 5000: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 automa...
Create a job called "cleanup" using the nginx image and run the command "nginx" inside the job.
Command: ```bash kubectl create job cleanup --image=nginx -- nginx ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: jso...
Create a deployment for monitoring using the postgres image
Command: ```bash kubectl create deployment monitoring --image=postgres -- postgres ``` 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 annotation of pod 'email' with the value 'Web server for marketing site', overwriting any existing value
Command: ```bash kubectl annotate --overwrite pods email description='Web server for marketing site' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger ...
Import environment variables from the 'ui-config' config map with the 'MYSQL_' prefix and apply them to the 'database-deployment' deployment.
Command: ```bash kubectl set env --from=configmap/ui-config --prefix=MYSQL_ deployment/database-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one...
Check if the current user has permission to list the "image-processing-job" job in the "development" namespace.
Command: ```bash kubectl auth can-i list jobs.batch/image-processing-job -n development ``` 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 parti...
Copy the local file "/tmp/foo_dir" to the remote pod "auth-service-pod-11" in the container "database-container" to the location "/tmp/bar_dir"
Command: ```bash kubectl cp /tmp/foo_dir auth-service-pod-11:/tmp/bar_dir -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 o...
Enable the Google Compute Platform auth provider for the "cloud-user" entry
Command: ```bash kubectl config set-credentials cloud-user --auth-provider=gcp ``` What it does: Set a user entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values. Client-certificate flags: --client-certificate=certfile --client-key=keyfile Bearer token flags: --...
Embed the certificate authority data for the "moon-cluster" cluster entry by executing the command:
Command: ```bash kubectl config set-cluster moon-cluster --embed-certs --certificate-authority=~/.kube/prod-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 set...
Create a new NodePort service named proxy-server-nodeport, forwarding traffic from local port 8083 to port 5432 on the target
Command: ```bash kubectl create service nodeport proxy-server-nodeport --tcp=8083:5432 ``` 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"...
Set environment variables from a config map
Command: ```bash kubectl set env --keys=redis_host --from=configmap/namespace-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 definition...
Forward local traffic from port 5432 to port 8088 on the pod selected by the api-server-deployment deployment.
Command: ```bash kubectl port-forward deployment/api-server-deployment 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 b...
Set the cluster field in the team-alpha-context context to cluster-gamma.
Command: ```bash kubectl config set contexts.team-alpha-context.cluster cluster-gamma ``` 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 ...
Import the smtp_server key from the config map named app-settings and apply it to the backend-microservice-deployment deployment.
Command: ```bash kubectl set env --keys=smtp_server --from=configmap/app-settings deployment/backend-microservice-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable ...
Apply a taint on nodes with the label 'stack=tech-stack' using the key 'datacenter' and the value 'db-node-7:PreferNoSchedule'
Command: ```bash kubectl taint node -l stack=tech-stack datacenter=db-node-7:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage"...
Import the secret_key from the kube-system-config config map and update the environment variables of the backend-microservice-deployment deployment.
Command: ```bash kubectl set env --keys=secret_key --from=configmap/kube-system-config deployment/backend-microservice-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment vari...
Auto scale the deployment "vpn" with a minimum of 3 pods and a maximum of 9 pods.
Command: ```bash kubectl autoscale deployment vpn --min=3 --max=9 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that uses the ...
List deployments in YAML output format, for the "beta-1.0" version of the "internal-apps" API group.
Command: ```bash kubectl get deployments.beta-1.0.internal-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 you...
Delete the 'star-cluster' cluster from the kubectl configuration.
Command: ```bash kubectl config delete-cluster star-cluster ``` What it does: Delete the specified cluster from the kubeconfig. Syntax: `kubectl config delete-cluster NAME`
Check the status of a daemonset rollout
Command: ```bash kubectl rollout status daemonset/my-deployment ``` What it does: Manage the rollout of a resource. Valid resource types include: Syntax: `kubectl rollout SUBCOMMAND`
replace a pod using yaml configuration from file
Command: ```bash kubectl replace -f ./docker-registry.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...
Create a cluster role named "view" with the following resource permissions:
Command: ```bash kubectl create clusterrole view --verb=connect --resource=configmaps --resource-name=audit-logger --resource-name=load-balancer ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|clie...
Update the annotation of pod 'cdn' with the value 'Prometheus'
Command: ```bash kubectl annotate --overwrite pods cdn monitoring-tool='Prometheus' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels and i...
Copy the file /tmp/foo from the pod named 'worker-pod-4' in the 'prometheus' namespace to the local directory /etc/kubernetes.
Command: ```bash kubectl cp prometheus/worker-pod-4:/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 kub...
Listen on port 8088 on all addresses and forward the traffic to port 8888 in the analytics-pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/analytics-pod 8088:8888 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod wil...
Begin streaming the logs of the "nano-bot" container in the "payment-gateway-pod" pod
Command: ```bash kubectl logs -f -c nano-bot payment-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", ...
Update the annotation 'criticality' of pod 'database' with the value 'high'
Command: ```bash kubectl annotate pods database criticality=high ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels and include arbitrary st...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=secret_key --from=configmap/global-config deployment/backend-microservice-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable ...