prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Create a job with a specific command. The command to be executed inside the job is "wp"
Command: ```bash kubectl create job log-processing-job --image=wordpress -- wp ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format....
Create a pod disruption budget named monitoring-pdb that will select all pods with the release=1.0.0 label and require a minimum of four of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget monitoring-pdb --selector=release=1.0.0 --min-available=4 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-available=N [...
Copy the ~/.config/kube file from the backend-pod-13 pod in the argocd namespace to the local /tmp/bar directory.
Command: ```bash kubectl cp argocd/backend-pod-13:~/.config/kube :/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 kubec...
Update the 'gateway-deployment' deployment by setting the environment variable LOG_LEVEL to 'info'
Command: ```bash kubectl set env deployment/gateway-deployment LOG_LEVEL=info ``` 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 (withi...
import the "MAX_CONNECTIONS" key from the "ui-config" config map and set it as an environment variable for the "frontend-deployment" deployment.
Command: ```bash kubectl set env --keys=MAX_CONNECTIONS --from=configmap/ui-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 definitions...
Copy the "~/.config/kube" file from the "task-processor-pod-17" pod in the "metallb-system" namespace to the local "/tmp/bar" directory.
Command: ```bash kubectl cp metallb-system/task-processor-pod-17:~/.config/kube /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,...
Update the image of a container in a pod using a JSON patch with positional arrays
Command: ```bash kubectl patch pod web-app-pod --type='json' -p='[{"op": "replace", "path": "/spec/containers/0/image", "value":"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 ...
Create a service for a replicated python application, which serves on port 5000 and connects to the containers on port 330600
Command: ```bash kubectl expose rc python --port=5000 --target-port=330600 ``` 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....
Remove a taint from a specific node
Command: ```bash kubectl taint nodes node-2 app:PreferNoSchedule- ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: jso...
Return the snapshot logs from the container 'gateway-deployment-1' of the deployment named 'backend-pod'
Command: ```bash kubectl logs deployment/gateway-deployment -c backend-pod-1 ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--...
Retrieve the output from executing the command 'composer --version' inside the first container of the media-stream-pod pod.
Command: ```bash kubectl exec media-stream-pod -- composer --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 t...
Create a catch all ingress rule for "/path" that points to the service "svc:port" and uses the Ingress Class "otheringress"
Command: ```bash kubectl create ingress catch-all --class=otheringress --rule="/path=svc:port" ``` 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": "Out...
Add a taint to the node 'k8s-node-1' with the key 'datacenter' and no value
Command: ```bash kubectl taint nodes k8s-node-1 datacenter: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:...
Create a cluster role named "bar" with the specified NonResourceURL
Command: ```bash kubectl create clusterrole "bar" --verb=watch --non-resource-url=/port-forward ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "sh...
Begin streaming the logs of the `cyber-sleuth` container in the `frontend-pod` pod.
Command: ```bash kubectl logs -f -c cyber-sleuth frontend-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", "sh...
Create a pod named nginx with the ruby image
Command: ```bash kubectl run nginx --image=ruby ``` 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": "--filename", "short":...
Import specific keys from a config map into the environment variables of a deployment.
Command: ```bash kubectl set env --keys=my-example-key --from=configmap/namespace-config 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 ...
Copy the local file /tmp/foo to the remote pod cache-pod-5 in the kube-server namespace at the location /tmp/bar
Command: ```bash kubectl cp :/tmp/foo kube-server/cache-pod-5::/tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubectl....
Forward traffic from port 8088 on localhost and IP 10.19.21.23 to port 8000 in the backend-pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/backend-pod 8088: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 criteri...
Create a job called "database-seeding-job" using the "mysql" image. The command to be executed inside the job is "mysqld".
Command: ```bash kubectl create job database-seeding-job --image=mysql -- mysqld ``` 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 forma...
Create an ingress with TLS enabled using the default ingress certificate and different path types
Command: ```bash kubectl create ingress ingtls --class=default \ --rule="testing.com/=svc:https,tls" \ --rule="website.com/path/subpath*=othersvc:8084" ``` 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"...
Import the LOG_LEVEL key from the app-config config map and set it as an environment variable in the web-app-deployment deployment.
Command: ```bash kubectl set env --keys=LOG_LEVEL --from=configmap/app-config deployment/web-app-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in on...
Forward traffic from local port 5432 to port 8080 in the e-commerce-pod pod.
Command: ```bash kubectl port-forward pod/e-commerce-pod 5432: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 aut...
Start a new mongo pod named nginx, but overload the spec with a partial set of values parsed from JSON
Command: ```bash kubectl run nginx --image=mongo --overrides='{ "apiVersion": "dev-2.2.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] -- [COMM...
Set up port forwarding to listen on port 8081 locally and forward data to/from port 8888 in the 'search-engine-deployment' deployment.
Command: ```bash kubectl port-forward deployment/search-engine-deployment 8081 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...
Create a copy of the backend-pod and change all container images to confluentinc/cp-kafka
Command: ```bash kubectl debug backend-pod --copy-to=my-debugger --set-image=*=confluentinc/cp-kafka ``` 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...
Add or update the annotation "deployment-script" with the value "https://example.com/deploy.sh" for the pod named "auth", overwriting any existing value.
Command: ```bash kubectl annotate --overwrite pods auth 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 la...
Forward port 8088 on all addresses to port 5432 in the 'api-service-pod' pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/api-service-pod 8088: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 w...
Create a job named log-processing-job with the image tagged as php and the command php --version
Command: ```bash kubectl create job log-processing-job --image=php -- php --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 fo...
Set the cluster field of the 'cluster-1-context' context to 'cloud-cluster'
Command: ```bash kubectl config set contexts.cluster-1-context.cluster cloud-cluster ``` 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 y...
Create a service for the replicated node using replica set named "node", which will serve on port 6379 and connect to the containers on port 30010.
Command: ```bash kubectl expose rs node --port=6379 --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. A...
Create a debug container in email-service-pod with a copy named my-debugger, and change the container images for worker to my-custom-worker:1.2.3 and api to api:v2.
Command: ```bash kubectl debug email-service-pod -it --copy-to=my-debugger --image=debian --set-image=worker=my-custom-worker:1.2.3,api=api:v2 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resou...
Return the snapshot logs from the 'media-stream-pod' container of the 'payment-processor-deployment' deployment
Command: ```bash kubectl logs deployment/payment-processor-deployment -c media-stream-pod-1 ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful fla...
Set the environment variables for the "cluster-admin" entry to key1=val1 and key2=val2.
Command: ```bash kubectl config set-credentials cluster-admin --exec-env=key1=val1 --exec-env=key2=val2 ``` 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...
Set the CPU limit of the nginx container in the go deployment to "3" and the memory limit to "256Mi"
Command: ```bash kubectl set resources deployment go -c=nginx --limits=cpu=3,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, but may burst up to its s...
Create an ingress resource named "website-ingress" that routes requests from site.com/input to svc1:5432 using a TLS secret called "my-cert"
Command: ```bash kubectl create ingress website-ingress --rule="site.com/input=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...
Create a pod disruption budget with the name "elastic-search-pdb" that selects all pods with the label "project=my-project" and ensures that at least one of these pods is always available.
Command: ```bash kubectl create poddisruptionbudget elastic-search-pdb --selector=project=my-project --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-avai...
Set the `client-key-data` field in the `security-user` user by providing the certificate data using the `--set-raw-bytes=true` option
Command: ```bash kubectl config set users.security-user.client-key-data cert_data_here --set-raw-bytes=true ``` 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_V...
Create a new ExternalName service named 'external-messaging-service' with an external name of 'demo-service.dev'
Command: ```bash kubectl create service externalname external-messaging-service --external-name demo-service.dev ``` 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 s...
Create a role named "foo" with API Group specified for managing deployments
Command: ```bash kubectl create role foo --verb=create,list,delete --resource=deployments.apps ``` What it does: Create a role with single rule. Syntax: `kubectl create role NAME --verb=verb --resource=resource.group/subresource [--resource-name=resourcename] [--dry-run=server|client|none]` Helpful flags: "flag": "-...
Scale the deployment named app-v2-replicaset's current size to 3 replicas for the mysql resource
Command: ```bash kubectl scale --current-replicas=3 --replicas=3 deployment/app-v2-replicaset ``` What it does: Set a new size for a deployment, replica set, replication controller, or stateful set. Scale also allows users to specify one or more preconditions for the scale action. If --current-replicas or --resource-v...
Create a new config map named 'kube-system-config' from the environment file located at 'path/to/configs.env'
Command: ```bash kubectl create configmap kube-system-config --from-env-file=path/to/configs.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...
Compare the resources defined in the setup.json file with the current cluster state
Command: ```bash kubectl diff -f setup.json ``` What it does: Diff configurations specified by file name or stdin between the current online configuration, and the configuration as it would be if applied. The output is always YAML. KUBECTL_EXTERNAL_DIFF environment variable can be used to select your own diff command....
Forward local port 3000 to port 5432 in the pod "log-aggregator-pod"
Command: ```bash kubectl port-forward pod/log-aggregator-pod 3000: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...
Attach and get output from the nebula-navigator container inside the frontend-pod pod.
Command: ```bash kubectl attach frontend-pod -c nebula-navigator ``` 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...
Forward local port 5000 to port 3000 in the specified pod
Command: ```bash kubectl port-forward pod/api-service-pod 5000: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 local port 5000 to port 6379 in the 'log-aggregator-pod' pod
Command: ```bash kubectl port-forward pod/log-aggregator-pod 5000: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...
Scale the 'db-migration-replicaset' replica set to 3 replicas.
Command: ```bash kubectl scale --replicas=3 rs/db-migration-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-version is specified, it...
Create a cron job named 'data-processing' that runs the 'dotnet' command every minute using the 'mcr.microsoft.com/dotnet/core/runtime' image
Command: ```bash kubectl create cronjob data-processing --image=mcr.microsoft.com/dotnet/core/runtime --schedule="*/1 * * * *" -- dotnet ``` 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: "fla...
Set the custom TLS server name for the kube-cluster-1 cluster entry as "staging-cluster"
Command: ```bash kubectl config set-cluster kube-cluster-1 --tls-server-name=staging-cluster ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certif...
Create a new pod named "hazelcast" with the Ruby image, and configure the container to expose port 7000.
Command: ```bash kubectl run hazelcast --image=ruby --port=7000 ``` 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": "--fil...
List deployments in JSON output format of the "rc-1.1.0" version of the "third-party-apps" API group.
Command: ```bash kubectl get deployments.rc-1.1.0.third-party-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 ...
Copy the local file /tmp/foo to the /etc/kubernetes directory in the remote pod named kube-proxy/auth-service-pod-11, in the namespace "kube-proxy/auth-service-pod-11".
Command: ```bash kubectl cp :/tmp/foo kube-proxy/auth-service-pod-11:/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...
Import specific keys from a config map to a deployment's environment variables.
Command: ```bash kubectl set env --keys=smtp_server --from=configmap/db-config deployment/notification-handler-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable def...
Get the output from the 'stardust-shuttle' container in the 'api-service-pod' pod
Command: ```bash kubectl attach api-service-pod -c stardust-shuttle ``` 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 omit...
Forward local port 8081 to port 8088 in the pod "analytics-pod"
Command: ```bash kubectl port-forward pod/analytics-pod 8081:8088 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected auto...
Create an ingress resource named "service-ingress" with a rule that directs requests from "website.com/input" to the service "svc1" on port 8089, and configure it to use the TLS secret "my-cert".
Command: ```bash kubectl create ingress service-ingress --rule="website.com/input=svc1:8089,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "us...
Create an ingress resource named 'private-service-ingress' with a rule that directs requests for foo.com/example to the service named svc1 running on port 8000
Command: ```bash kubectl create ingress private-service-ingress --rule="foo.com/example=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": "...
Forward traffic from port 8888 on localhost and IP 10.19.21.23 to port 5000 in the pod named "cdn-service-pod"
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/cdn-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...
Create a copy of the security-service-pod pod and start an interactive session in the debug-image-api pod, with the warp-drive container, using the 'sh' command.
Command: ```bash kubectl debug security-service-pod -it --copy-to=debug-image-api --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 ...
Create a deployment named 'prometheus' using the 'redis' image
Command: ```bash kubectl create deployment prometheus --image=redis ``` 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|yaml|...
Run the command "kubectl exec" with the specified parameters to execute the "apk add curl" command in the first pod of the "analytics-platform-deployment" deployment.
Command: ```bash kubectl exec deploy/analytics-platform-deployment -- apk add curl ``` 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 ...
Create a service for a replicated centos using replica set that serves on port 7000 and connects to the containers on port 818100.
Command: ```bash kubectl expose rs centos --port=7000 --target-port=818100 ``` 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....
List the resources of specific types and names.
Command: ```bash kubectl get rc/web service/media-stream-rc pods/monitoring-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 namesp...
Configure the cluster field in the "user-a-context" context to "my-k8s-cluster"
Command: ```bash kubectl config set contexts.user-a-context.cluster my-k8s-cluster ``` 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...
Copy the directory "/tmp/foo_dir" from the remote pod "web-app-pod-1" in the "istio-system" namespace to the local directory "/etc/kubernetes".
Command: ```bash kubectl cp istio-system/web-app-pod-1:/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, use ...
Create a new ClusterIP service named log-service-clusterip that maps port 9000 on the cluster to port 6379 on the service
Command: ```bash kubectl create service clusterip log-service-clusterip --tcp=9000:6379 ``` 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...
Update the 'proxy' pod with the annotation 'backup-strategy' and set the value to 'daily backups'.
Command: ```bash kubectl annotate pods proxy 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 ...
Begin streaming the logs of the 'astro-container' container in pod 'web-app-pod'
Command: ```bash kubectl logs -f -c astro-container web-app-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", "...
Create a new config map named api-config with the specified keys
Command: ```bash kubectl create configmap api-config --from-file=settings=/path/to/configurations/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 creatin...
Create a pod disruption budget named messaging-pdb that will select all pods with the owner=team-1 label and require at least 9 of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget messaging-pdb --selector=owner=team-1 --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 [--...
Import specific keys from a config map into the environment variables of a deployment
Command: ```bash kubectl set env --keys=REDIS_HOST --from=configmap/api-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 definitions in ...
Create a new NodePort service named web-app-nodeport that listens on port 8181 and forwards traffic to port 8181.
Command: ```bash kubectl create service nodeport web-app-nodeport --tcp=8181:8181 ``` What it does: Create a NodePort service with the specified name. Syntax: `kubectl create service nodeport NAME [--tcp=port:targetPort] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "default": "",...
Embed the certificate authority data for the "dev-cluster" cluster entry
Command: ```bash kubectl config set-cluster dev-cluster --embed-certs --certificate-authority=~/.kube/kube-cluster-2/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...
Create an ingress called 'public-service-ingress' that routes requests from site.com/input to svc1:8181 and uses the TLS secret "my-cert" for encryption.
Command: ```bash kubectl create ingress public-service-ingress --rule="site.com/input=svc1:8181,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": "",...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=external_api_url --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 de...
Start a confluentinc/cp-kafka pod, but customize the pod specification using a JSON override
Command: ```bash kubectl run nginx --image=confluentinc/cp-kafka --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] [--comm...
Create a pod disruption budget named logging-pdb that will select all pods with the app=rails label and require at least four of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget logging-pdb --selector=app=rails --min-available=4 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-available=N [--dry-r...
Retrieve the previous terminated logs of the lunar-launcher container in the analytics-pod pod.
Command: ```bash kubectl logs -p -c lunar-launcher analytics-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", ...
Copy a file from a remote pod to a local directory
Command: ```bash kubectl cp velero/message-broker-pod-15::/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 ...
Create an ingress named 'api-v1-ingress' that routes requests from foo.com/bar to svc1 on port 3306, using the "my-cert" TLS secret.
Command: ```bash kubectl create ingress api-v1-ingress --rule="foo.com/bar=svc1:3306,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": "...
Forward the local port 8081 to port 8088 in the cdn-service-pod pod
Command: ```bash kubectl port-forward pod/cdn-service-pod 8081:8088 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected au...
Update the pod named 'payment' with the label 'component' and the value 'api'
Command: ```bash kubectl label pods payment component=api ``` 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": ...
Embed the certificate authority data for the testing-cluster cluster entry by running the command: kubectl config set-cluster testing-cluster --embed-certs --certificate-authority=~/.kube/data-cluster/kubernetes.ca.crt
Command: ```bash kubectl config set-cluster testing-cluster --embed-certs --certificate-authority=~/.kube/data-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 ...
Update pod 'backend' with status=unhealthy only if it is unchanged from version 1
Command: ```bash kubectl label pods backend status=unhealthy --resource-version=1 ``` 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", "defa...
Get output from code-explorer in the pod named gateway-pod
Command: ```bash kubectl attach gateway-pod -c code-explorer ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, us...
Copy the contents of the local directory "/var/run/secrets/kubernetes.io/serviceaccount/_dir" to the remote pod "backend-pod-13" in the default namespace, and place them in the directory "/tmp/bar_dir".
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/_dir backend-pod-13::/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": "Containe...
Get output from the 'cyber-sleuth' container in the 'cdn-service-pod' pod
Command: ```bash kubectl attach cdn-service-pod -c cyber-sleuth ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted,...
Import the 'debug_mode' key from the 'app-secrets' config map into the 'backend-microservice-deployment' deployment
Command: ```bash kubectl set env --keys=debug_mode --from=configmap/app-secrets 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 de...
Execute the command 'kafka-server-start /etc/kafka/server.properties' in the lunar-launcher container of the analytics-pod and display the output.
Command: ```bash kubectl exec analytics-pod -c lunar-launcher -- kafka-server-start /etc/kafka/server.properties ``` 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": "",...
Update the criticality annotation of a pod in the docker-registry.yaml file
Command: ```bash kubectl annotate -f docker-registry.yaml 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 ar...
Create a service for the replication controller specified in "ruby-controller.yaml" file
Command: ```bash kubectl expose -f ruby-controller.yaml --port=5001 --target-port=800000 ``` 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 s...
Start a pod named hazelcast using the ubuntu image, with a container that exposes port 8010.
Command: ```bash kubectl run hazelcast --image=ubuntu --port=8010 ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args...]` Helpful flags: "flag": "--f...
Create a new config map named app-config-prod with specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap app-config-prod --from-file=settings=/path/to/configs/file1.txt --from-file=key2=/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 creati...
create a ClusterIP service named cache-service-clusterip in headless mode
Command: ```bash kubectl create service clusterip cache-service-clusterip --clusterip="None" ``` 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...
Copy ~/.config/kube local file to /tmp/bar in a remote pod
Command: ```bash kubectl cp ~/.config/kube kube-node-lease/image-resizer-pod-20:/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,...
Get the modified deployment in YAML format without making any changes to the actual object on the server
Command: ```bash kubectl set env deployment/mydeployment CACHE_SIZE=64MB -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 templates (wi...
Create a job named 'data-migration-job' with the nginx image and the command 'nginx'
Command: ```bash kubectl create job data-migration-job --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. ...
Execute a command inside the payment-gateway-pod container to install the aws-cli package.
Command: ```bash kubectl exec payment-gateway-pod -- yum install -y aws-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...
Start a redis pod, but customize the pod configuration using JSON overrides
Command: ```bash kubectl run nginx --image=redis --overrides='{ "apiVersion": "feature-branch-2.3.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] [--comman...