prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Set the cluster field in the prod-context context to my-k8s-cluster
Command: ```bash kubectl config set contexts.prod-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 w...
Update the image of all containers in the daemonset 'nginx' to 'node:14.17.3'.
Command: ```bash kubectl set image daemonset nginx *=node:14.17.3 ``` 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: `kubec...
Create a copy of the 'email-service-pod' pod as 'dgb-img', changing all container images to 'mongo'.
Command: ```bash kubectl debug email-service-pod --copy-to=dgb-img --set-image=*=mongo ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used by default if no resourc...
Stream the logs of the time-machine container in the backend-pod pod
Command: ```bash kubectl logs -f -c time-machine backend-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", "sho...
Set resource request and limits for all containers in the deployment named "golang" in the Kubernetes cluster.
Command: ```bash kubectl set resources deployment golang --limits=cpu=200m,memory=512Mi --requests=cpu=2,memory=128Mi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requeste...
Create a new pod named "nginx" using the image "mcr.microsoft.com/dotnet/core/runtime", but customize the pod specification by providing a JSON object with partial set of values.
Command: ```bash kubectl run nginx --image=mcr.microsoft.com/dotnet/core/runtime --overrides='{ "apiVersion": "alpha-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=i...
Auto scale the replication controller "cdn" with a target CPU utilization of 81% and a maximum of 3 pods
Command: ```bash kubectl autoscale rc cdn --max=3 --cpu-percent=81 ``` 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...
Import the DATABASE_URL key from the app-config-dev config map to the load-balancer-deployment deployment.
Command: ```bash kubectl set env --keys=DATABASE_URL --from=configmap/app-config-dev 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 defi...
Copy the file located at /var/run/secrets/kubernetes.io/serviceaccount/ to /tmp/bar in the remote pod named file-server-pod-14 in the rook-ceph namespace.
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ rook-ceph/file-server-pod-14:/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": "Con...
Create a deployment named 'jenkins-x' using the 'php' image and expose port 27017.
Command: ```bash kubectl create deployment jenkins-x --image=php --port=27017 ``` 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: ...
Forward traffic from a local port to a specific port in a pod
Command: ```bash kubectl port-forward pod/frontend-pod :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 automatic...
Set the auth provider to Google Compute Platform for the "security-user" entry
Command: ```bash kubectl config set-credentials security-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: ...
Switch to raw terminal mode and attach to the frontend-pod container named quantum-quark
Command: ```bash kubectl attach frontend-pod -c quantum-quark -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 omit...
Remove a specific taint from a node
Command: ```bash kubectl taint nodes monitoring-node-15 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. ...
Create a pod named "hazelcast" using the Golang image and expose port 8443
Command: ```bash kubectl run hazelcast --image=golang --port=8443 ``` 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...
Remove the taint on a specific node
Command: ```bash kubectl taint nodes app-node-6 zone: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...
Run the 'jenkins --version' command in quantum-quark from pod cdn-service-pod
Command: ```bash kubectl exec cdn-service-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...
Add a taint with key 'disktype' on nodes having label app-type=microservice, setting the taint value to 'backup-node-14' and the effect to 'PreferNoSchedule'
Command: ```bash kubectl taint node -l app-type=microservice disktype=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": "",...
Add a taint with key 'hardware' on nodes having label region=eu-west-2, specifically on node-1 with the effect 'PreferNoSchedule'
Command: ```bash kubectl taint node -l region=eu-west-2 hardware=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": "Ou...
Create a service for a replication controller with specified ports
Command: ```bash kubectl expose -f alpine-controller.yaml --port=7000 --target-port=909000 ``` 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...
Create a new ExternalName service named external-git-service with the external name of demo-service.dev
Command: ```bash kubectl create service externalname external-git-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 service...
Create a cron job named "weekly-summary" with an image "docker.elastic.co/elasticsearch/elasticsearch", a schedule of running every minute, and a command "elasticsearch --version"
Command: ```bash kubectl create cronjob weekly-summary --image=docker.elastic.co/elasticsearch/elasticsearch --schedule="*/1 * * * *" -- elasticsearch --version ``` What it does: Create a cron job with the specified name. Syntax: `kubectl create cronjob NAME --image=image --schedule='0/5 * * * ?' -- [COMMAND] [args.....
Import specific keys from a config map for a deployment
Command: ```bash kubectl set env --keys=api_key --from=configmap/monitoring-config deployment/payment-processor-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...
Enable the Google Compute Platform auth provider for the "web-app" entry
Command: ```bash kubectl config set-credentials web-app --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: --tok...
Get output from running the 'mongo' command in the 'stardust-shuttle' container of the 'cdn-service-pod' pod.
Command: ```bash kubectl exec cdn-service-pod -c stardust-shuttle -- 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,...
Forward traffic from port 8081 on all addresses to port 8888 in the security-service-pod pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/security-service-pod 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 ...
Forward local port to a pod's port for direct access.
Command: ```bash kubectl port-forward pod/security-service-pod :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...
Forward traffic from port 8888 on localhost and IP 10.19.21.23 to port 3000 in the pod named api-service-pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/api-service-pod 8888: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 cri...
Embed the certificate authority data for the dev-cluster cluster entry by running the command "kubectl config set-cluster dev-cluster --embed-certs --certificate-authority=~/.kube/testing-cluster/kubernetes.ca.crt"
Command: ```bash kubectl config set-cluster dev-cluster --embed-certs --certificate-authority=~/.kube/testing-cluster/kubernetes.ca.crt ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config s...
Set the cpu limits to "1" and memory limits to "4Gi" for the nginx container in the amazonlinux deployment.
Command: ```bash kubectl set resources deployment amazonlinux -c=nginx --limits=cpu=1,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, but may burst up t...
Set the environment variable MAX_CONNECTIONS in the deployment/search-engine-deployment using the values from the configmap/monitoring-config
Command: ```bash kubectl set env --keys=MAX_CONNECTIONS --from=configmap/monitoring-config deployment/search-engine-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 variabl...
Add a taint with key 'app' on nodes having label owner=john-doe
Command: ```bash kubectl taint node -l owner=john-doe app=prod-node-5: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": "Outp...
Import environment variables from the 'db-config' config map with the prefix 'MYSQL_' into the 'authentication-service-deployment' deployment.
Command: ```bash kubectl set env --from=configmap/db-config --prefix=MYSQL_ deployment/authentication-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 defi...
Import the 'DATABASE_URL' key from the 'api-config' ConfigMap and set it as an environment variable in the 'web-app-deployment' deployment
Command: ```bash kubectl set env --keys=DATABASE_URL --from=configmap/api-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...
Create a copy of the monitoring-pod named debug-image-web by adding a debug container and attach to it
Command: ```bash kubectl debug monitoring-pod -it --image=busybox --copy-to=debug-image-web ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used by default if no re...
Create a job named image-build-job with the wordpress image and run the wp command
Command: ```bash kubectl create job image-build-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. On...
Set the resource requests and limits for all containers in the php deployment to cpu=10 and memory=4Gi respectively
Command: ```bash kubectl set resources deployment php --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, b...
Copy the contents of /var/run/secrets/kubernetes.io/serviceaccount/ from the monitoring-agent-pod-6 pod in the velero namespace to the local directory /tmp/bar.
Command: ```bash kubectl cp velero/monitoring-agent-pod-6:/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": "C...
Listen on port 9090 on localhost and IP 10.19.21.23, and forward the traffic to port 8088 in the frontend-pod pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/frontend-pod 9090: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 criter...
Forward local port 8081 to port 8088 in the security-service-pod pod
Command: ```bash kubectl port-forward pod/security-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 select...
Create a copy of the e-commerce-pod container called debug-image-api, changing the command to 'sh' in the stardust-shuttle container for debugging purposes.
Command: ```bash kubectl debug e-commerce-pod -it --copy-to=debug-image-api --container=stardust-shuttle -- 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 ...
Add the label 'env=development' to the pod 'log-aggregator'
Command: ```bash kubectl label pods log-aggregator env=development ``` 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", ...
Update the cluster field to "testing-cluster" in the "my-context" context.
Command: ```bash kubectl config set contexts.edge-context.cluster testing-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 ...
Create an ingress called 'app-ingress' that directs requests to a specific path of a website to a service with TLS encryption
Command: ```bash kubectl create ingress app-ingress --rule="site.com/input=svc1:8443,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": "...
Set up autoscaling for the deployment "email" with a minimum of 1 pod and a maximum of 9 pods.
Command: ```bash kubectl autoscale deployment email --min=1 --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 th...
Forward data from local port 3000 to port 8081 in a pod selected by the deployment "database-deployment".
Command: ```bash kubectl port-forward deployment/database-deployment 3000 8081 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be ...
Forward local port 5000 to port 6379 in the pod named "web-app-pod"
Command: ```bash kubectl port-forward pod/web-app-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 automa...
Get the output from running the 'composer --version' command in the cosmic-container from the pod backend-pod
Command: ```bash kubectl exec backend-pod -c cosmic-container -- 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...
Set the environment variable 'LOG_LEVEL' to 'info' in the 'web-app-deployment' deployment.
Command: ```bash kubectl set env deployment/web-app-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...
Forward local traffic on port 8088 to port 8000 in the 'chat-app-pod' pod.
Command: ```bash kubectl port-forward pod/chat-app-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 criteria, a pod will be selected autom...
Add a taint with the key 'hardware' on nodes that have a label 'myLabel'
Command: ```bash kubectl taint node -l myLabel hardware=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": "Output ...
Add a taint named 'special' with value 'prod-node-5:PreferNoSchedule' on nodes that have the label 'myLabel'
Command: ```bash kubectl taint node -l myLabel special=prod-node-5: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 ...
Copy the file "/tmp/foo" from your local machine to the "/etc/kubernetes" directory of the remote pod named "monitoring-agent-pod-6" under the namespace "kube-proxy".
Command: ```bash kubectl cp :/tmp/foo kube-proxy/monitoring-agent-pod-6:/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, ...
Create a job for data migration with the specified command
Command: ```bash kubectl create job data-migration-job --image=ubuntu -- docker run -it ubuntu ``` 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":...
Create a config map named app-config-dev with specified keys from files.
Command: ```bash kubectl create configmap app-config-dev --from-file=conf=/path/to/profiles/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 c...
Create a job called "monitoring-job" using the "centos" image, and run the command "sleep 3600" inside the job.
Command: ```bash kubectl create job monitoring-job --image=centos -- sleep 3600 ``` 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...
Set the custom TLS server name to use for validation for the cluster-gamma cluster entry
Command: ```bash kubectl config set-cluster cluster-gamma --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] [--certificat...
create an ExternalName service named external-database-service to connect to an external database with the address "blog-test.blog"
Command: ```bash kubectl create service externalname external-database-service --external-name blog-test.blog ``` 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 serv...
Create a new deployment named gateway with the ethereum/client-go image and expose port 8010
Command: ```bash kubectl create deployment gateway --image=ethereum/client-go --port=8010 ``` 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 form...
Forward traffic from port 8088 on localhost and IP address 10.19.21.23 to port 8088 in the 'chat-app-pod' pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/chat-app-pod 8088: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 criter...
Add a taint with key 'disktype' on nodes having label 'customer=acme-corp' and the value 'monitoring-node-15' with the scheduler preference 'PreferNoSchedule'
Command: ```bash kubectl taint node -l customer=acme-corp disktype=monitoring-node-15: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": ""...
Expose a replica set as a service, listening on port 9091 and forwarding traffic to containers on port 808900.
Command: ```bash kubectl expose rs node --port=9091 --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 specified port. A...
Forward local port 8081 to port 5432 in the pod named "proxy-server-pod"
Command: ```bash kubectl port-forward pod/proxy-server-pod 8081:5432 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected a...
Expose a python deployment as a service on port 80, connecting to containers on port 8000.
Command: ```bash kubectl expose deployment python --port=8000 --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...
Add a taint to the app-node-6 node with the key 'environment', value 'production', and effect 'NoSchedule'
Command: ```bash kubectl taint nodes app-node-6 environment=production: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 for...
Import the 'api_key' key from the 'global-config' config map into the 'api-server-deployment' deployment
Command: ```bash kubectl set env --keys=api_key --from=configmap/global-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 definitions i...
Listen on local port 8080 and forward traffic to port 8088 in the pod named "security-service-pod"
Command: ```bash kubectl port-forward pod/security-service-pod 8080:8088 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be select...
Attach to the 'lunar-launcher' container in the 'proxy-server-pod' and switch to raw terminal mode
Command: ```bash kubectl attach proxy-server-pod -c lunar-launcher -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...
Create a copy of the cdn-service-pod resource, adding a debug container and changing the container images
Command: ```bash kubectl debug cdn-service-pod -it --copy-to=dgb-img --image=debian --set-image=proxy=nginx:1.21,scheduler=my-scheduler:1.0 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource...
Retrieve the previous terminated logs of the 'nebula-navigator' container from the 'analytics-pod' pod
Command: ```bash kubectl logs -p -c nebula-navigator 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"...
Update the annotation 'app-version' of pod 'log-aggregator' to '2.5.1', replacing any existing value
Command: ```bash kubectl annotate --overwrite pods log-aggregator app-version='2.5.1' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels and...
List deployments in YAML output format for the "dev-2.2.0" version of the "experimental-apps" API group.
Command: ```bash kubectl get deployments.dev-2.2.0.experimental-apps -o yaml ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespace...
Create a pod disruption budget named web-app-pdb that selects pods with the component=web label and ensures that at least 9 of them are available at all times.
Command: ```bash kubectl create poddisruptionbudget web-app-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 [--d...
Create a single ingress called 'app-loadbalancer-ingress' that directs requests to testing.com/input to svc # svc1:3306 with a tls secret "my-cert"
Command: ```bash kubectl create ingress app-loadbalancer-ingress --rule="testing.com/input=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"...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=api_key --from=configmap/kube-system-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 variabl...
Change the service account of the 'scheduler-app-deployment' deployment to 'cert-manager'
Command: ```bash kubectl set serviceaccount deployment scheduler-app-deployment cert-manager ``` What it does: Update the service account of pod template resources. Possible resources (case insensitive) can be: replicationcontroller (rc), deployment (deploy), daemonset (ds), job, replicaset (rs), statefulset Syntax: ...
Update the label of a pod with the specified key-value pair
Command: ```bash kubectl label pods security tier=frontend ``` 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":...
Create a pod disruption budget named web-app-pdb that will select all pods with the owner=team-1 label and require a minimum of 9 of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget web-app-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 [--dr...
Create a deployment with a specific image and optional command
Command: ```bash kubectl create deployment monitoring --image=jenkins -- java -jar /usr/share/jenkins/jenkins.war ``` 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": "...
Import the value of the key "my-example-key" from the "env-vars" config map and set it as an environment variable in the "order-processing-deployment" deployment
Command: ```bash kubectl set env --keys=my-example-key --from=configmap/env-vars 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 defin...
Get the output from running the 'pg_dump --version' command in the 'nebula-navigator' container of the 'proxy-service-pod'.
Command: ```bash kubectl exec proxy-service-pod -c nebula-navigator -- pg_dump --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 nam...
Create a job called 'data-migration-job' using the 'confluentinc/cp-kafka' image
Command: ```bash kubectl create job data-migration-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 flags: ...
Apply a taint with the key 'app' on the nodes that have the label 'myLabel'
Command: ```bash kubectl taint node -l myLabel app=worker-node-3: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 fo...
Run the 'jenkins-plugin-cli' command in the 'cyber-sleuth' container in the 'media-stream-pod' pod and get the output
Command: ```bash kubectl exec media-stream-pod -c cyber-sleuth -- jenkins-plugin-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. I...
List all deployments in the "dev-2.2.0" version of the "apps" API group in YAML output format.
Command: ```bash kubectl get deployments.dev-2.2.0.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 will on...
Create a new ExternalName service named external-metrics-service with the external address set to travel-sample.travel.
Command: ```bash kubectl create service externalname external-metrics-service --external-name travel-sample.travel ``` 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...
Update environment variables of a deployment with specific keys from a config map
Command: ```bash kubectl set env --keys=API_KEY --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 one...
Create an ingress named 'api-gateway-ingress' with a rule that directs requests from foo.com/example to svc1:8082 and uses the tls secret named "my-cert".
Command: ```bash kubectl create ingress api-gateway-ingress --rule="foo.com/example=svc1:8082,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "...
Update the annotation 'last-deployment' of the pod 'database' to '2023-03-15' in the Kubernetes cluster, overwriting any existing value
Command: ```bash kubectl annotate --overwrite pods database 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 ...
Create a copy of the monitoring-pod and add a debug container by changing its container images
Command: ```bash kubectl debug monitoring-pod -it --copy-to=debug-image-web --image=debian --set-image=app=app:debug,worker=my-custom-worker:1.2.3 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by r...
Add a taint with key 'cpu-type' on nodes having label project=project-alpha and node name db-node-7 with a preference of no scheduling
Command: ```bash kubectl taint node -l project=project-alpha cpu-type=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": "", "usa...
Modify the environment variable of a deployment and output the modified YAML without making changes on the server.
Command: ```bash kubectl set env deployment/scheduler-app-deployment LOG_LEVEL=info -o yaml ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more pod te...
create a deployment named auth using the golang image and exposing port 9091
Command: ```bash kubectl create deployment auth --image=golang --port=9091 ``` What it does: Create a deployment with the specified name. Syntax: `kubectl create deployment NAME --image=image -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: jso...
Start a pod with a custom set of values specified in a JSON format
Command: ```bash kubectl run nginx --image=docker.elastic.co/elasticsearch/elasticsearch --overrides='{ "apiVersion": "custom-version", "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] [...
Forward traffic from localhost and IP 10.19.21.23 on port 8888 to port 6379 in the pod named "analytics-pod"
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/analytics-pod 8888: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 crite...
Retrieve the logs from the first container of a job named "load-testing-job".
Command: ```bash kubectl logs job/load-testing-job ``` 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",...
Copy the file /tmp/foo from the web-app-pod-1 pod in the kube-node-lease namespace to the local directory /tmp/bar_dir.
Command: ```bash kubectl cp kube-node-lease/web-app-pod-1:/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 a deployment using the specified image
Command: ```bash kubectl create deployment drupal --image=golang -- go ``` 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|ya...
Start a Jenkins pod with custom specifications parsed from JSON
Command: ```bash kubectl run nginx --image=jenkins --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] [--comm...
Create a service for a ruby deployment, serving on port 9091, and connecting to the containers on port 808300
Command: ```bash kubectl expose deployment ruby --port=9091 --target-port=808300 ``` 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...