prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Forward traffic from port 6379 on all addresses to port 8088 in the pod "cdn-service-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/cdn-service-pod 6379: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 w...
Forward local port 8000 to port 5432 in the pod "security-service-pod"
Command: ```bash kubectl port-forward pod/security-service-pod 8000: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 select...
Update the node 'gpu-node-12' with a taint that has a key of 'environment' and a value of 'production' with an effect of 'NoSchedule'
Command: ```bash kubectl taint nodes gpu-node-12 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 fo...
import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=CONFIG_FILE_PATH --from=configmap/ui-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 d...
Delete the pods and services with the names "frontend" and "monitoring".
Command: ```bash kubectl delete pod,service frontend 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 selec...
Create an ingress with TLS enabled using the default ingress certificate, with different paths for different services
Command: ```bash kubectl create ingress ingtls --class=default \ --rule="site.com/=svc:https,tls" \ --rule="website.com/path/subpath*=othersvc:7000" ``` 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": "...
Retrieve the YAML configuration for the 'frontend-pod' pod
Command: ```bash kubectl get -o yaml pod frontend-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 see res...
Create a copy of the auth-service-pod named my-custom-dbg, adding a debug container and changing the container images to debian for the debug container, logger to logging-app:debug for the logger container, and app to app:debug for the app container.
Command: ```bash kubectl debug auth-service-pod -it --copy-to=my-custom-dbg --image=debian --set-image=logger=logging-app:debug,app=app:debug ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resour...
Autoscale the deployment named "analytics" with a minimum of 3 pods and a maximum of 12 pods
Command: ```bash kubectl autoscale deployment analytics --min=3 --max=12 ``` 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 us...
Update the 'cdn' pod by adding the annotation 'security-scan-status' with the value 'pass'
Command: ```bash kubectl annotate pods cdn security-scan-status=pass ``` 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 arbitrar...
Add a taint with key 'special' on nodes having label region=eu-west-2
Command: ```bash kubectl taint node -l region=eu-west-2 special=kube-master-9:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage...
Create a copy of the proxy-service-pod with a debug container and different container images
Command: ```bash kubectl debug proxy-service-pod -it --copy-to=debug-image-app --image=debian --set-image=proxy=nginx:1.21,web=nginx:latest ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource...
Forward traffic from port 8081 on all addresses to port 8888 in the specified pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/proxy-server-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 pod ...
Auto scale the deployment "media-stream" with the number of pods between 1 and 10.
Command: ```bash kubectl autoscale deployment media-stream --min=1 --max=10 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that...
Forward traffic from your local machine's port 8888 to port 5432 in the pod named `api-service-pod`.
Command: ```bash kubectl port-forward pod/api-service-pod 8888: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 au...
Create an ingress called 'website-ingress' that directs requests to website.com/input to svc1:6379 with a tls secret "my-cert"
Command: ```bash kubectl create ingress website-ingress --rule="website.com/input=svc1:6379,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...
edit a service using an alternative editor, in this case, "code".
Command: ```bash KUBE_EDITOR="code" kubectl edit svc/search-service ``` What it does: Edit a resource from the default editor. The edit command allows you to directly edit any API resource you can retrieve via the command-line tools. It will open the editor defined by your KUBE_EDITOR, or EDITOR environment variables,...
Add a taint with key 'app' on nodes having label region=eu-west-2
Command: ```bash kubectl taint node -l region=eu-west-2 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": "Ou...
Import environment variables from a config map with a specific prefix for a deployment.
Command: ```bash kubectl set env --from=configmap/app-config-dev --prefix=MYSQL_ 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 definiti...
Update the annotation of pod 'cdn' with the value '99.9% uptime'
Command: ```bash kubectl annotate --overwrite pods cdn SLA='99.9% uptime' ``` 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 arb...
Take the environment variables starting with "RAILS_" from the local shell and set them in the "cache-cluster-deployment" deployment config on the server.
Command: ```bash env | grep RAILS_ | kubectl set env -e - deployment/cache-cluster-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 more pod ...
Add the annotation 'monitoring-tool' with the value 'Prometheus' to the 'proxy-server' pod.
Command: ```bash kubectl annotate pods proxy-server 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 includ...
Start a centos pod with a partially overridden spec using JSON
Command: ```bash kubectl run nginx --image=centos --overrides='{ "apiVersion": "legacy-1.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] [--command] -- [...
Create a Pod Disruption Budget (PDB) named "critical-services-pdb" to ensure the availability of at least four pods with the label "component=web" at all times.
Command: ```bash kubectl create poddisruptionbudget critical-services-pdb --selector=component=web --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-availa...
Forward traffic from port 5000 on all addresses to port 8080 in the CDN service pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/cdn-service-pod 5000:8080 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod w...
Forward local port to pod port
Command: ```bash kubectl port-forward pod/security-service-pod :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 a...
Create a new ExternalName service with the name "external-cloud-storage-service" and map it to the external name "bar.com"
Command: ```bash kubectl create service externalname external-cloud-storage-service --external-name bar.com ``` 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 servic...
Create a service for a replicated alpine, which serves on port 3001 and connects to the containers on port 900000
Command: ```bash kubectl expose rc alpine --port=3001 --target-port=900000 ``` 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....
Update the annotation value for pod 'frontend' with the new value 'auto-horizontal-scaling'
Command: ```bash kubectl annotate --overwrite pods frontend scaling-policy='auto-horizontal-scaling' ``` 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 ...
Add a taint with the key 'hardware' and the value 'db-node-7:PreferNoSchedule' on nodes that have the label 'namespace=mynamespace'
Command: ```bash kubectl taint node -l namespace=mynamespace hardware=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...
Forward local port 8080 to port 8080 in the pod "mypod"
Command: ```bash kubectl port-forward pod/mypod 8080:8080 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automaticall...
Delete the pods and services named "cdn" and "proxy"
Command: ```bash kubectl delete pod,service cdn proxy ``` What it does: Delete resources by file names, stdin, resources and names, or by resources and label selector. JSON and YAML formats are accepted. Only one type of argument may be specified: file names, resources and names, or resources and label selector. Some ...
Create a job to build an image using the specified command.
Command: ```bash kubectl create job image-build-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": "Output ...
Set up an autoscaling policy for the 'gateway' deployment
Command: ```bash kubectl autoscale deployment gateway --min=6 --max=8 ``` 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 ...
Forward ports from local machine to a pod
Command: ```bash kubectl port-forward pod/frontend-pod 8080 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 autom...
Apply a taint with the key 'app' and the value 'worker-node-3:PreferNoSchedule' on the nodes that have the label 'role=database'
Command: ```bash kubectl taint node -l role=database 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": "Out...
Create a new config map named 'global-config' with the specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap global-config --from-file=properties=/path/to/preferences/file1.txt --from-file=key1=/path/to/parameters/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When cr...
Forward local port 8888 to port 8000 in the pod named security-service-pod
Command: ```bash kubectl port-forward pod/security-service-pod 8888: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 select...
Start a hazelcast pod with elasticsearch image and expose port 8081
Command: ```bash kubectl run hazelcast --image=docker.elastic.co/elasticsearch/elasticsearch --port=8081 ``` 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] ...
Create a new config map named kube-system-config and populate it with the contents of the specified files
Command: ```bash kubectl create configmap kube-system-config --from-file=settings=/path/to/properties/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 ...
List multiple resources by their type and names
Command: ```bash kubectl get rc/web service/security-service-rc pods/proxy-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...
Get the output from running the 'irb' command in the astro-container from the proxy-server-pod
Command: ```bash kubectl exec proxy-server-pod -c astro-container -- irb ``` 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, u...
Forward local traffic from port 9090 to port 5432 in the pod selected by the 'analytics-platform-deployment' deployment.
Command: ```bash kubectl port-forward deployment/analytics-platform-deployment 9090 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 po...
Replace the existing pod with the new pod definition provided in the pod.json file.
Command: ```bash cat pod.json | kubectl replace -f - ``` What it does: Replace a resource by file name or stdin. JSON and YAML formats are accepted. If replacing an existing resource, the complete resource spec must be provided. This can be obtained by $ kubectl get TYPE NAME -o yaml Syntax: `kubectl replace -f FILEN...
Create a copy of the `api-service-pod` and change all container images to `node`
Command: ```bash kubectl debug api-service-pod --copy-to=dgb-img --set-image=*=node ``` 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 resource i...
Copy the local directory /tmp/foo_dir_dir to the remote pod backend-pod-13 in the default namespace at /etc/kubernetes_dir
Command: ```bash kubectl cp /tmp/foo_dir_dir backend-pod-13:/etc/kubernetes_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 ...
Set the CPU limit of the nginx container in the 'centos' deployment to "200m" and the memory limit to "128Mi"
Command: ```bash kubectl set resources deployment centos -c=nginx --limits=cpu=200m,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 requested, but may burst up t...
Create a deployment named 'api' using the 'alpine' image and expose port 3001
Command: ```bash kubectl create deployment api --image=alpine --port=3001 ``` 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...
Create a cron job named 'alerts-cleanup' in the default namespace, using the 'docker.elastic.co/elasticsearch/elasticsearch' image, with a schedule of running every minute
Command: ```bash kubectl create cronjob alerts-cleanup --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 into a deployment
Command: ```bash kubectl set env --keys=CONFIG_FILE_PATH --from=configmap/log-config deployment/email-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 defin...
Create a pod called hazelcast using the mysql image and expose port 8083
Command: ```bash kubectl run hazelcast --image=mysql --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] [args...]` Helpful flags: "flag": "--fi...
Create a role binding for jane.doe, bob.smith, and developers using the reader cluster role
Command: ```bash kubectl create rolebinding reader --clusterrole=reader --user=jane.doe --user=bob.smith --group=developers ``` What it does: Create a role binding for a particular role or cluster role. Syntax: `kubectl create rolebinding NAME --clusterrole=NAME|--role=NAME [--user=username] [--group=groupname] [--se...
Remove the taint with key 'special' and effect 'NoSchedule' from the node 'worker-node-3' if it exists.
Command: ```bash kubectl taint nodes worker-node-3 special: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 new secret named `api-secret-key` using the options from the `options.env` file.
Command: ```bash kubectl create secret generic api-secret-key --from-env-file=path/to/options.env ``` 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 basena...
Add the annotation 'contact-email' with the value 'support@example.com' to the pod named 'api'
Command: ```bash kubectl annotate pods api contact-email=support@example.com ``` 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 ...
Forward traffic from port 8080 on localhost and IP 10.19.21.23 to port 8081 in the pod named "cdn-service-pod"
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/cdn-service-pod 8080: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 cri...
Configure the Kubernetes cluster entry by disabling certificate checking.
Command: ```bash kubectl config set-cluster my-k8s-cluster --insecure-skip-tls-verify=true ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certific...
Attach to the rocket-ranger container in the api-service-pod to get the output from it
Command: ```bash kubectl attach api-service-pod -c rocket-ranger ``` 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 the local port 5432 to port 8081 in the 'web-app-pod' pod
Command: ```bash kubectl port-forward pod/web-app-pod 5432: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 automa...
Create a pod disruption budget named notification-service-pdb that requires at least one pod with the release=1.0.0 label to be available at all times.
Command: ```bash kubectl create poddisruptionbudget notification-service-pdb --selector=release=1.0.0 --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-ava...
Create a debug session for the 'gateway-pod' pod, with a copy named 'my-debugger', and change all container images to 'mcr.microsoft.com/dotnet/core/runtime'
Command: ```bash kubectl debug gateway-pod --copy-to=my-debugger --set-image=*=mcr.microsoft.com/dotnet/core/runtime ``` 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...
Forward all traffic from port 6379 on all addresses to port 8888 in the pod named proxy-server-pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/proxy-server-pod 6379: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 ...
Create a new config map named 'namespace-config' in the default namespace
Command: ```bash kubectl create configmap namespace-config --from-file=conf=/path/to/profiles/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 crea...
Set the CPU limits of the 'elasticsearch' deployment's 'nginx' container to "500m" and the memory limits to "64Mi"
Command: ```bash kubectl set resources deployment elasticsearch -c=nginx --limits=cpu=500m,memory=64Mi ``` 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 burs...
Remove taint from a node
Command: ```bash kubectl taint nodes app-node-6 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:...
Update the 'admin' cluster role binding for the 'vault' service account in the 'namespace' namespace.
Command: ```bash kubectl set subject clusterrolebinding admin --serviceaccount=namespace:vault ``` What it does: Update the user, group, or service account in a role binding or cluster role binding. Syntax: `kubectl set subject (-f FILENAME | TYPE NAME) [--user=username] [--group=groupname] [--serviceaccount=namespac...
Forward the local ports 8088 and 6000 to ports 8000 and 6000, respectively, in a pod selected by the authentication-service-deployment deployment.
Command: ```bash kubectl port-forward deployment/authentication-service-deployment 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, ...
Create a debug copy of the log-aggregator-pod and change all container images to mysql.
Command: ```bash kubectl debug log-aggregator-pod --copy-to=debug-image-api --set-image=*=mysql ``` 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 n...
Set the cluster field to cloud-cluster in the my-context context for the app-1-context config.
Command: ```bash kubectl config set contexts.app-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 you w...
Create an ingress called 'public-service-ingress' that routes requests from website.com/module to svc1:8181 and uses the tls secret "my-cert".
Command: ```bash kubectl create ingress public-service-ingress --rule="website.com/module=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":...
Create a cron job named 'data-processing' using the 'mysql' image, with a schedule of running every minute, executing the 'mysql' command.
Command: ```bash kubectl create cronjob data-processing --image=mysql --schedule="*/1 * * * *" -- mysql ``` What it does: Create a cron job with the specified name. Syntax: `kubectl create cronjob NAME --image=image --schedule='0/5 * * * ?' -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "d...
Get output from running the 'irb' command in the cyber-sleuth container within the vpn-service-pod.
Command: ```bash kubectl exec vpn-service-pod -c cyber-sleuth -- irb ``` 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...
Add a taint with key 'hardware' and no value to the node 'db-node-7'
Command: ```bash kubectl taint nodes db-node-7 hardware: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: js...
Forward local traffic from port 8088 to port 8081 in the 'proxy-server-pod' pod.
Command: ```bash kubectl port-forward pod/proxy-server-pod 8088 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 a...
List the deployments in the "legacy-1.0.0" version of the "api-v1" API group, and display the output in JSON format.
Command: ```bash kubectl get deployments.legacy-1.0.0.api-v1 -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 wi...
Import the 'SECRET_KEY' key from the 'env-vars' config map into the 'frontend-deployment' deployment.
Command: ```bash kubectl set env --keys=SECRET_KEY --from=configmap/env-vars 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 on...
Set the CPU limits of the nginx container in the wordpress deployment to 10 and the memory limit to 128Mi.
Command: ```bash kubectl set resources deployment wordpress -c=nginx --limits=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 requested, but may burst up ...
Automatically scale the replication controller "web" with the number of pods ranging from 1 to 7, based on a target CPU utilization of 90%.
Command: ```bash kubectl autoscale rc web --max=7 --cpu-percent=90 ``` 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...
Update the cluster field in the specified context
Command: ```bash kubectl config set contexts.staging-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 you...
Update the annotation 'backup-strategy' of pod 'backend' to 'daily-backups', replacing any existing value.
Command: ```bash kubectl annotate --overwrite pods backend 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 label...
Copy the auth-service-pod and change the container images to use Jenkins
Command: ```bash kubectl debug auth-service-pod --copy-to=debug-image-1 --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 ...
Create a cron job named 'backup-job' with the command 'jenkins --version' using the 'jenkins' image
Command: ```bash kubectl create cronjob backup-job --image=jenkins --schedule="*/1 * * * *" -- jenkins --version ``` What it does: Create a cron job with the specified name. Syntax: `kubectl create cronjob NAME --image=image --schedule='0/5 * * * ?' -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short":...
Update the cluster field in the context named "my-context" to "web-cluster" using the kubectl config set command.
Command: ```bash kubectl config set contexts.on-prem-context.cluster web-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...
Add a taint with key 'datacenter' and value 'app-node-6:PreferNoSchedule' on nodes that have the label 'component=proxy'
Command: ```bash kubectl taint node -l component=proxy datacenter=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"...
Create a ClusterIP service named "shipping-service-clusterip" with a TCP port mapping from 5001 to 8084.
Command: ```bash kubectl create service clusterip shipping-service-clusterip --tcp=5001:8084 ``` 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...
Retrieve the phase value of a specific pod.
Command: ```bash kubectl get -o template pod/payment-gateway-pod --template={{.status.phase}} ``` 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 ...
Forward port 3000 from the pod "proxy-server-pod" to ports 3000 on localhost and IP 10.19.21.23
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/proxy-server-pod 3000:3000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the cr...
List all resources specified in the kustomization.yaml file located in the "parameters" directory.
Command: ```bash kubectl get -k parameters/ ``` 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 see results in yo...
Return the snapshot logs from the first container of the content-import-job job.
Command: ```bash kubectl logs job/content-import-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...
Remove the taint on node 'kube-master-9' with key 'zone' and effect 'PreferNoSchedule', if it exists.
Command: ```bash kubectl taint nodes kube-master-9 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...
Create a new ClusterIP service named monitoring-service-clusterip with port mapping from local port 8089 to target port 3001
Command: ```bash kubectl create service clusterip monitoring-service-clusterip --tcp=8089:3001 ``` 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": "...
Add a taint with the key 'hardware' on nodes having the label 'app=web-app'
Command: ```bash kubectl taint node -l app=web-app hardware=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": "", "usag...
Set the client-key-data field in the admin user configuration by providing the certificate data and using the --set-raw-bytes=true option.
Command: ```bash kubectl config set users.admin.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_VALUE is ...
View the logs from container "web-app-pod" in the deployment "analytics-platform-deployment-1"
Command: ```bash kubectl logs deployment/analytics-platform-deployment -c web-app-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: ...
Create a new config map named app-name-config and populate it with the specified keys and file paths
Command: ```bash kubectl create configmap app-name-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 cr...
Import the log_level key from the app-name-config config map and set it as an environment variable in the gateway-deployment deployment.
Command: ```bash kubectl set env --keys=log_level --from=configmap/app-name-config deployment/gateway-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions ...
Create a service for the 'hazelcast' deployment that serves on port 80 and connects to the containers on port 8000.
Command: ```bash kubectl expose deployment hazelcast --port=8082 --target-port=500000 ``` 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 spec...
Forward local port 8081 to port 8000 in the pod named "proxy-server-pod"
Command: ```bash kubectl port-forward pod/proxy-server-pod 8081: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 a...
Forward local port 9090 to port 8080 in the frontend-pod pod
Command: ```bash kubectl port-forward pod/frontend-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 will be selected autom...
List deployments in JSON output format from the "beta-1.0" version of the "prod-apps" API group
Command: ```bash kubectl get deployments.beta-1.0.prod-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...