prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Retrieve the previous terminated logs of the "ruby" container from the "chat-app-pod" pod by running the command "kubectl logs -p -c ruby chat-app-pod".
Command: ```bash kubectl logs -p -c ruby chat-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", "short": "-...
Create a config map with specified keys and files
Command: ```bash kubectl create configmap app-config --from-file=settings=/path/to/configurations/file1.txt --from-file=key2=/path/to/properties/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When crea...
Set the cluster field in the staging-context context to moon-cluster
Command: ```bash kubectl config set contexts.staging-context.cluster moon-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 ...
Forward traffic from port 5432 on all addresses to port 8088 in the e-commerce-pod pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/e-commerce-pod 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 wi...
Start a pod with custom overrides
Command: ```bash kubectl run nginx --image=ubuntu --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] [--comma...
Create an ingress called 'default-ingress' with a rule that directs requests from foo.com/example to svc1:3001
Command: ```bash kubectl create ingress default-ingress --rule="foo.com/example=svc1:3001,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": "", "usag...
List deployments in JSON output format for the "v2.1.0" version of the "api-v2" API group.
Command: ```bash kubectl get deployments.v2.1.0.api-v2 -o json ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you will onl...
Add a taint with key 'zone' on nodes having the label 'owner=john-doe'
Command: ```bash kubectl taint node -l owner=john-doe zone=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": "Outpu...
Create a job called 'data-migration-job' using the 'golang' image and run the command 'go run hello.go'
Command: ```bash kubectl create job data-migration-job --image=golang -- go run hello.go ``` 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": "Outp...
Create a pod disruption budget named critical-services-pdb that will select all pods with the env=production label and require at least four of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget critical-services-pdb --selector=env=production --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-avail...
Forward local port 8000 to port 5000 in the pod named "analytics-pod"
Command: ```bash kubectl port-forward pod/analytics-pod 8000:5000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected auto...
Add a taint with the key 'environment' and the value 'edge-node-10:PreferNoSchedule' on nodes having the label 'zone=us-east-1'
Command: ```bash kubectl taint node -l zone=us-east-1 environment=edge-node-10:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usag...
Create a single ingress called 'api-ingress' that directs requests to foo.com/bar to svc1:9090 with a tls secret "my-cert"
Command: ```bash kubectl create ingress api-ingress --rule="foo.com/bar=svc1:9090,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": "Out...
Scale up or down the replication controller "auth" based on the CPU utilization, with a range of 1 to 6 pods, targeting a CPU utilization of 81%
Command: ```bash kubectl autoscale rc auth --max=6 --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 th...
Create a new config map named 'namespace-config' using the files '/path/to/options/file1.txt' and '/path/to/profiles/file2.txt' for the keys 'conf' and 'data' respectively.
Command: ```bash kubectl create configmap namespace-config --from-file=conf=/path/to/options/file1.txt --from-file=data=/path/to/profiles/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a ...
Start a new pod called 'nginx' using the 'amazonlinux' image, but modify the pod specification using the values provided in the JSON file for the 'apiVersion' and 'spec' fields.
Command: ```bash kubectl run nginx --image=amazonlinux --overrides='{ "apiVersion": "v2.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] -- [C...
Set a custom TLS server name for the edge-cluster cluster entry
Command: ```bash kubectl config set-cluster edge-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] [--certificat...
Import specific keys from a config map into a deployment
Command: ```bash kubectl set env --keys=SMTP_SERVER --from=configmap/ui-config deployment/log-aggregator-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitio...
Add a taint to nodes with label 'owner=john-doe' named 'app=db-node-7', and set it to 'PreferNoSchedule'.
Command: ```bash kubectl taint node -l owner=john-doe app=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": "Output...
Update the annotation 'git-repo' for the pod 'proxy-server' with the value 'https://github.com/example/my-app', overwriting any existing value
Command: ```bash kubectl annotate --overwrite pods proxy-server git-repo='https://github.com/example/my-app' ``` 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...
Add a taint with key 'environment' and value 'storage-node-13:PreferNoSchedule' on nodes having the label 'customer=acme-corp'
Command: ```bash kubectl taint node -l customer=acme-corp environment=storage-node-13:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": ""...
List the deployments in YAML output format for the "alpha-2.0" version of the "my-apps" API group.
Command: ```bash kubectl get deployments.alpha-2.0.my-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...
Create a new NodePort service named auth-service-nodeport with a TCP port mapping of 3001 to 8083.
Command: ```bash kubectl create service nodeport auth-service-nodeport --tcp=3001:8083 ``` 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"...
Approve a Certificate Signing Request (CSR) with the name 'csr-worker-3'.
Command: ```bash kubectl certificate approve csr-worker-3 ``` What it does: Approve a certificate signing request. kubectl certificate approve allows a cluster admin to approve a certificate signing request (CSR). This action tells a certificate signing controller to issue a certificate to the requestor with the attri...
Import specific keys from a config map to a deployment's environment variables.
Command: ```bash kubectl set env --keys=secret_key --from=configmap/namespace-config deployment/log-aggregator-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable def...
List deployments in JSON format for the "v1.0.0" version of the "custom-apps" API group
Command: ```bash kubectl get deployments.v1.0.0.custom-apps -o json ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you wil...
Get the output from the stardust-shuttle container in the email-service-pod
Command: ```bash kubectl attach email-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 om...
Set the custom TLS server name "cloud-cluster" for the star-cluster cluster entry.
Command: ```bash kubectl config set-cluster star-cluster --tls-server-name=cloud-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...
Set the annotation "release-notes" to "https://example.com/release-notes/v2.5.1" for the pod "media-stream"
Command: ```bash kubectl annotate pods media-stream release-notes='https://example.com/release-notes/v2.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...
Import the DEBUG_MODE key from the ui-config config map into the database-deployment deployment.
Command: ```bash kubectl set env --keys=DEBUG_MODE --from=configmap/ui-config 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 o...
Retrieve the output from running the command 'psql' inside the first container of the first pod of the 'load-balancer-deployment' deployment
Command: ```bash kubectl exec deploy/load-balancer-deployment -- psql ``` 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 ...
Delete the dev-user user from the kubectl configuration
Command: ```bash kubectl config delete-user dev-user ``` What it does: Delete the specified user from the kubeconfig. Syntax: `kubectl config delete-user NAME`
Import specific keys from a config map into an environment variable of a deployment
Command: ```bash kubectl set env --keys=redis_host --from=configmap/log-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 def...
Add a NoSchedule taint with key 'environment' to the node 'web-node-8'
Command: ```bash kubectl taint nodes web-node-8 environment:NoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of...
Listen on port 9090 on all addresses, and forward to port 8080 in the 'analytics-pod' pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/analytics-pod 9090:8080 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod wil...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=config_file_path --from=configmap/app-config-prod 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...
Create a job named cleanup using the redis image, and run the command "redis-server" inside the job.
Command: ```bash kubectl create job cleanup --image=redis -- redis-server ``` 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 ...
Forward port 3000 on localhost and IP 10.19.21.23 to port 9090 in the web-app-pod pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/web-app-pod 3000:9090 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteri...
Create a job with a given command.
Command: ```bash kubectl create job database-seeding-job --image=node -- node --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": "Outpu...
Forward local port 9090 to pod port 3000 in the chat-app-pod pod
Command: ```bash kubectl port-forward pod/chat-app-pod 9090 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 autom...
Start a pod with the image "docker.elastic.co/elasticsearch/elasticsearch" and expose port 8083 from the container.
Command: ```bash kubectl run hazelcast --image=docker.elastic.co/elasticsearch/elasticsearch --port=8083 ``` 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] ...
Import specific keys from a config map into a deployment's environment variables
Command: ```bash kubectl set env --keys=config_file_path --from=configmap/kube-system-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 va...
Create an ingress with a rule that directs requests from testing.com/example to svc1:3306 with tls secret "my-cert"
Command: ```bash kubectl create ingress web-ingress --rule="testing.com/example=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": "", "usag...
Return snapshot logs from container 'e-commerce-pod-1' of a deployment named 'analytics-platform-deployment'.
Command: ```bash kubectl logs deployment/analytics-platform-deployment -c e-commerce-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 flag...
Create a new config map named db-config with specified keys instead of file basenames on disk.
Command: ```bash kubectl create configmap db-config --from-file=conf=/path/to/preferences/file1.txt --from-file=data=/path/to/configs/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a conf...
Listen on port 8081 locally and forward data to/from port 9090 in the 'proxy-server-pod' pod
Command: ```bash kubectl port-forward pod/proxy-server-pod 8081 9090 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected a...
Create a job that runs a command using a specific image
Command: ```bash kubectl create job monitoring-job --image=jenkins -- java -jar /usr/share/jenkins/jenkins.war ``` 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...
Import the environment variables from the app-config-secret secret into the load-balancer-deployment deployment.
Command: ```bash kubectl set env --from=secret/app-config-secret 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 definitions in one or mo...
Listen on port 3000 locally, forwarding data to and from port 8888 in the security-service-pod.
Command: ```bash kubectl port-forward pod/security-service-pod 3000 8888 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be select...
Forward traffic from local port 8081 to the HTTPS port of the selected pod through the specified service.
Command: ```bash kubectl port-forward service/analytics-service 8081:https ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be sele...
Create an ingress named 'app2-ingress' that maps requests for 'website.com/bar' to the service 'svc1' on port 9090, using the TLS certificate 'my-cert'.
Command: ```bash kubectl create ingress app2-ingress --rule="website.com/bar=svc1:9090,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 single ingress called 'web-ingress' that directs requests to website.com/example to svc1:5000 with a tls secret "my-cert"
Command: ```bash kubectl create ingress web-ingress --rule="website.com/example=svc1:5000,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": "", "usag...
Forward traffic from port 8081 on your localhost and IP 10.19.21.23 to port 5000 in the "web-app-pod" pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/web-app-pod 8081: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 criteri...
Start a Jenkins pod and expose port 8181 for the container
Command: ```bash kubectl run hazelcast --image=jenkins --port=8181 ``` 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": "--...
Import specific keys from a config map to a deployment.
Command: ```bash kubectl set env --keys=API_KEY --from=configmap/kube-system-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 on...
Run a proxy to the Kubernetes API server on port 8082, serving static content from ./local/www/
Command: ```bash kubectl proxy --port=8082 --www=./local/www/ ``` What it does: Creates a proxy server or application-level gateway between localhost and the Kubernetes API server. It also allows serving static content over specified HTTP path. All incoming data enters through one port and gets forwarded to the remote...
Create a copy of the analytics-pod and add a debug container with the image set to debian
Command: ```bash kubectl debug analytics-pod -it --copy-to=my-debugger --image=debian --set-image=scheduler=my-scheduler:1.0,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 re...
Auto scale the "proxy-server" deployment with a minimum of 4 pods and a maximum of 15 pods.
Command: ```bash kubectl autoscale deployment proxy-server --min=4 --max=15 ``` 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...
Create an ingress called 'private-service-ingress' that directs requests from 'testing.com/input' to the 'svc1' service on port '5432' with a TLS secret named 'my-cert'.
Command: ```bash kubectl create ingress private-service-ingress --rule="testing.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":...
create a job named 'monitoring-job' using the 'python' image, and run the command 'python --version'
Command: ```bash kubectl create job monitoring-job --image=python -- python --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 ...
Forward local port 8081 to port 3000 in the pod named "web-app-pod"
Command: ```bash kubectl port-forward pod/web-app-pod 8081: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 automa...
Auto scale the "vpn" deployment with a minimum of 5 pods and a maximum of 14 pods
Command: ```bash kubectl autoscale deployment vpn --min=5 --max=14 ``` 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...
Add a taint with the key 'app' and value 'web-node-8:PreferNoSchedule' on nodes labeled with 'release=beta'
Command: ```bash kubectl taint node -l release=beta app=web-node-8:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output ...
Update the label of the 'media-stream' pod to 'release=v1.0'
Command: ```bash kubectl label pods media-stream release=v1.0 ``` 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", "usag...
Create a secret named my-secret with keys for each file in the given folder
Command: ```bash kubectl create secret generic my-secret --from-file=path/to/properties ``` 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 basename of the ...
Import specific keys from a config map to a deployment's environment variables
Command: ```bash kubectl set env --keys=DATABASE_URL --from=configmap/app-config-dev 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...
Delete both the pod and service with the name "monitoring".
Command: ```bash kubectl delete pod,service monitoring monitoring ``` What it does: Delete resources by file names, stdin, resources and names, or by resources and label selector. JSON and YAML formats are accepted. Only one type of argument may be specified: file names, resources and names, or resources and label sel...
List deployments in JSON output format, specifically the "v1.1.1" version of the "third-party-apps" API group
Command: ```bash kubectl get deployments.v1.1.1.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 yo...
forward data between the local ports 8080 and 6000, and the pod selected by the 'analytics-platform-deployment' deployment ports 8088 and 6000.
Command: ```bash kubectl port-forward deployment/analytics-platform-deployment 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 po...
Forward local random port to pod port 3000
Command: ```bash kubectl port-forward pod/e-commerce-pod :3000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automat...
Create a new LoadBalancer service named media-stream-lb, and forward traffic from port 3306 to port 9092.
Command: ```bash kubectl create service loadbalancer media-stream-lb --tcp=3306:9092 ``` What it does: Create a LoadBalancer service with the specified name. Syntax: `kubectl create service loadbalancer NAME [--tcp=port:targetPort] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "de...
List the deployments in the "rc-1.1.0" version of the "legacy-apps" API group in JSON output format.
Command: ```bash kubectl get deployments.rc-1.1.0.legacy-apps -o json ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you w...
Add a taint with the key 'special' on nodes having the label 'customer=acme-corp', specifically on the node 'db-node-7', and set it to 'PreferNoSchedule'.
Command: ```bash kubectl taint node -l customer=acme-corp special=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":...
Forward traffic from all addresses on port 8000 to port 8000 in the pod named 'cdn-service-pod'.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/cdn-service-pod 8000: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 w...
set the cpu and memory limits for a container in a deployment
Command: ```bash kubectl set resources deployment ubuntu -c=nginx --limits=cpu=1,memory=2Gi ``` 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...
Copy the file /tmp/foo from the pod named cache-pod-5 in the kube-dns namespace to the local file /tmp/bar.
Command: ```bash kubectl cp kube-dns/cache-pod-5:/tmp/foo /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.kuber...
Create a role named "default_role" with API Group specified
Command: ```bash kubectl create role default_role --verb=proxy,get,update --resource=roles.rbac.authorization.k8s.io ``` 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]` Hel...
Forward port 8088 from localhost to port 8088 in the backend-pod, allowing traffic from all IP addresses
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/backend-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 criteria, a pod will ...
Apply the configuration in pod.json file to a pod
Command: ```bash kubectl apply -f ./pod.json ``` What it does: Apply a configuration to a resource by file name or stdin. The resource name must be specified. This resource will be created if it doesn't exist yet. To use 'apply', always create the resource initially with either 'apply' or 'create --save-config'. JSON ...
Start listening on port 8000 on localhost and IP address 10.19.21.23, and forward it to port 8088 in the 'frontend-pod' pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/frontend-pod 8000:8088 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criter...
Create a ClusterIP service named notification-service-clusterip with the TCP port mapping 8084:8888
Command: ```bash kubectl create service clusterip notification-service-clusterip --tcp=8084:8888 ``` 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":...
Update the monitoring-tool annotation of a pod specified in the config.json file to "Prometheus"
Command: ```bash kubectl annotate -f config.json 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 include a...
Import specific keys from a config map to configure environment variables for a deployment
Command: ```bash kubectl set env --keys=max_connections --from=configmap/global-config deployment/log-aggregator-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable d...
Embed certificate authority data for the my-k8s-cluster cluster entry
Command: ```bash kubectl config set-cluster my-k8s-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 s...
Create a debug image of the 'gateway-pod' and change all container images to 'jenkins'
Command: ```bash kubectl debug gateway-pod --copy-to=debug-image-api --set-image=*=jenkins ``` 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 res...
Create an ingress called 'app-gateway-ingress' with a rule that directs requests from foo.com/module to svc1:8084, and use the TLS secret "my-cert"
Command: ```bash kubectl create ingress app-gateway-ingress --rule="foo.com/module=svc1:8084,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "u...
Auto scale the deployment "media-stream" by setting the minimum number of pods to 1 and the maximum number of pods to 11.
Command: ```bash kubectl autoscale deployment media-stream --min=1 --max=11 ``` 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...
List the deployments in the "v1.1.1" version of the "testing-apps" API group in YAML output format
Command: ```bash kubectl get deployments.v1.1.1.testing-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 wi...
Retrieve the output of the 'elasticsearch-plugin --list' command from the cyber-sleuth container in the web-app-pod pod.
Command: ```bash kubectl exec web-app-pod -c cyber-sleuth -- elasticsearch-plugin --list ``` 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 service for a replicated ubuntu, which serves on port 80 and connects to the containers on port 9092
Command: ```bash kubectl expose rc ubuntu --port=80 --target-port=909200 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port. A...
forward traffic from port 8080 on all addresses to port 6379 in the pod named "security-service-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/security-service-pod 8080: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 ...
List deployments in YAML output format, in the "legacy-1.0.0" version of the "legacy-apps" API group
Command: ```bash kubectl get deployments.legacy-1.0.0.legacy-apps -o yaml ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced y...
Set the resource request and limits for all containers in the nginx deployment to 10m CPU, 128Mi memory as the request and 200m CPU, 512Mi memory as the limit.
Command: ```bash kubectl set resources deployment nginx --limits=cpu=200m,memory=512Mi --requests=cpu=10,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...
List deployments in JSON output format using the "v1.1.1" version of the "api-v2" API group.
Command: ```bash kubectl get deployments.v1.1.1.api-v2 -o json ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you will onl...
Create a new ClusterIP service named order-service-clusterip with port mappings from local port 8089 to container port 5000.
Command: ```bash kubectl create service clusterip order-service-clusterip --tcp=8089:5000 ``` 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", ...
Get the details of a single pod in YAML format.
Command: ```bash kubectl get -o yaml pod security-service-pod ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you will only...
Forward local port 8081 to port 5432 in the pod web-app-pod
Command: ```bash kubectl port-forward pod/web-app-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 automa...
Set the service account of the deployment "notification-handler-deployment" to "istio"
Command: ```bash kubectl set serviceaccount deployment notification-handler-deployment istio ``` 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: ...
Create a cluster role named "custom_role" with the ResourceName specified
Command: ```bash kubectl create clusterrole custom_role --verb=get --resource=pods --resource-name=dev-database --resource-name=dashboard-ui ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|client|n...
Create a new config map named "app-config-dev" with the specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap app-config-dev --from-file=conf=/path/to/settings/file1.txt --from-file=data=/path/to/configurations/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creati...