prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Create an ingress named 'api-gateway-ingress' that routes requests from 'website.com/input' to 'svc1:6379' with the TLS secret 'my-cert'.
Command: ```bash kubectl create ingress api-gateway-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": "",...
Create a cluster role named "reader" with the ability to get pods and specifically access the "file-storage" and "auth-service" resources.
Command: ```bash kubectl create clusterrole reader --verb=get --resource=pods --resource-name=file-storage --resource-name=auth-service ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|client|none]`...
Create a single ingress called 'private-ingress' that directs requests to foo.com/bar to svc1:5000 with a tls secret "my-cert"
Command: ```bash kubectl create ingress private-ingress --rule="foo.com/bar=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": "", "usage": ...
Retrieve the snapshot logs from the 'email-service-pod-1' container of the 'analytics-platform-deployment' deployment.
Command: ```bash kubectl logs deployment/analytics-platform-deployment -c email-service-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 f...
Forward traffic from port 9090 on all addresses to port 8000 in the pod named "mypod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/mypod 9090: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 sel...
Create a cluster role named "default_role" with a specified NonResourceURL
Command: ```bash kubectl create clusterrole "default_role" --verb=patch --non-resource-url=/metrics ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|client|none]` Helpful flags: "flag": "--output",...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=SMTP_SERVER --from=configmap/log-config deployment/analytics-platform-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defi...
Import the log_level key from the app-config config map into the analytics-platform-deployment deployment.
Command: ```bash kubectl set env --keys=log_level --from=configmap/app-config deployment/analytics-platform-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defini...
Run the 'sleep 3600' command in the 'cosmic-container' of the 'log-aggregator-pod' pod and get the output.
Command: ```bash kubectl exec log-aggregator-pod -c cosmic-container -- sleep 3600 ``` 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 ...
Port forward the pod "log-aggregator-pod" to listen on port 5000 on all addresses and forward the traffic to port 8000 in the pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/log-aggregator-pod 5000: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 po...
Get output from running the 'jenkins-plugin-cli' command in the first pod of the 'analytics-service' service.
Command: ```bash kubectl exec svc/analytics-service -- 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. If omitted, ...
Forward traffic from port 9090 on all addresses to port 8000 in the web-app-pod pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/web-app-pod 9090: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 ...
Enable the Google Compute Platform auth provider for the "service-account" entry
Command: ```bash kubectl config set-credentials service-account --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:...
Get live output from the "quantum-quark" container in the "gateway-pod" pod.
Command: ```bash kubectl attach gateway-pod -c quantum-quark ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, us...
Forward local port 9090 to port 8088 in the backend-pod, listening on all addresses.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/backend-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 criteria, a pod will ...
Forward traffic from port 8080 on all addresses to port 6379 in the pod named "web-app-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/web-app-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 pod will ...
Forward the traffic from port 8080 on all addresses to port 3000 in the 'frontend-pod' pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/frontend-pod 8080: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...
Retrieve the output from the 'geth' command running inside the 'mypod' pod
Command: ```bash kubectl exec mypod -- geth ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubectl.kubernetes.io/...
Apply a taint with the key 'hardware' and value 'k8s-node-1:PreferNoSchedule' to all nodes with the label 'tier=frontend'.
Command: ```bash kubectl taint node -l tier=frontend hardware=k8s-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": "O...
Add or update the annotation 'git-repo' with the value 'https://github.com/example/my-app' on the pod named 'database'
Command: ```bash kubectl annotate --overwrite pods database 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 lar...
Import specific keys from a config map into a deployment named "notification-handler-deployment"
Command: ```bash kubectl set env --keys=CONFIG_FILE_PATH --from=configmap/app-secrets 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 varia...
Get the output of the 'go version' command running inside the warp-drive container of the security-service-pod.
Command: ```bash kubectl exec security-service-pod -c warp-drive -- go version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omit...
Set the custom TLS server name to use for validation for the staging-cluster cluster entry
Command: ```bash kubectl config set-cluster staging-cluster --tls-server-name=my-k8s-cluster ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certif...
Import the REDIS_HOST key from the app-config-prod ConfigMap and set it as an environment variable in the authentication-service-deployment deployment.
Command: ```bash kubectl set env --keys=REDIS_HOST --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 varia...
Apply a taint with the key 'app' and the value 'edge-node-10:PreferNoSchedule' on the nodes that have the label owner=john-doe
Command: ```bash kubectl taint node -l owner=john-doe app=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": "", "usage": "Out...
Import specific keys from a config map to a deployment's environment variables
Command: ```bash kubectl set env --keys=external_api_url --from=configmap/app-secrets 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 varia...
Import the environment variables from the monitoring-credentials-secret secret into the api-server-deployment deployment.
Command: ```bash kubectl set env --from=secret/monitoring-credentials-secret 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 in ...
Create a service for the replicated ruby controller with the following parameters: - Port: 8082 - Target Port: 300100
Command: ```bash kubectl expose rc ruby --port=8082 --target-port=300100 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port. A...
Create a new config map named app-config-prod with specific key-value pairs
Command: ```bash kubectl create configmap app-config-prod --from-literal=conf=config1 --from-literal=data=config2 ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a config map based on a file, the ke...
Retrieve the output of the 'nginx -t' command running inside the stardust-shuttle container of the 'analytics-pod' pod.
Command: ```bash kubectl exec analytics-pod -c stardust-shuttle -- nginx -t ``` 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...
import the 'api_key' key from the 'log-config' config map and set it as an environment variable for the 'email-server-deployment' deployment
Command: ```bash kubectl set env --keys=api_key --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 definitions in...
Forward incoming requests on port 9090 to the HTTPS port of the pods selected by the "search-service" service.
Command: ```bash kubectl port-forward service/search-service 9090: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 selecte...
Scale the deployment named baz to 1 replica if its current size is 3.
Command: ```bash kubectl scale --current-replicas=3 --replicas=1 deployment/baz ``` What it does: Set a new size for a deployment, replica set, replication controller, or stateful set. Scale also allows users to specify one or more preconditions for the scale action. If --current-replicas or --resource-version is spec...
Update the pod named 'web' with the annotation 'app-version' and set its value to '2.5.1'
Command: ```bash kubectl annotate pods web 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 include arbitrary string...
Execute the 'go run hello.go' command inside the first container of the 'web-app-pod' pod.
Command: ```bash kubectl exec web-app-pod -- go run hello.go ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubec...
Create a single ingress called 'app-ingress' with the rule "site.com/input" that directs requests to the service 'svc1' on port 5000
Command: ```bash kubectl create ingress app-ingress --rule="site.com/input=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": "", "usage": "...
Create a service to expose a replicated alpine using a replica set, serving on port 8082, and connecting to the containers on port 8000.
Command: ```bash kubectl expose rs alpine --port=8082 --target-port=800000 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port....
Update the image of all containers in the daemonset "namespace-2" to "redis:6.2.5"
Command: ```bash kubectl set image daemonset namespace-2 *=redis:6.2.5 ``` 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: `...
Create a service for the replicated ubuntu pods, which will serve on port 8080 and connect to the containers on port 801000.
Command: ```bash kubectl expose rc ubuntu --port=8080 --target-port=801000 ``` 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....
Set the cluster field in the my-context context to kube-cluster-2
Command: ```bash kubectl config set contexts.user-b-context.cluster kube-cluster-2 ``` 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...
Import the 'MAX_CONNECTIONS' key from the 'app-config' ConfigMap to the 'proxy-service-deployment' Deployment.
Command: ```bash kubectl set env --keys=MAX_CONNECTIONS --from=configmap/app-config deployment/proxy-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 defin...
Create a pod disruption budget with the name 'cron-jobs-pdb' that selects all pods with the label 'project=my-project' and requires at least one of them to be available at any point in time
Command: ```bash kubectl create poddisruptionbudget cron-jobs-pdb --selector=project=my-project --min-available=1 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-available...
Forward local port 8888 to port 8000 in the pod named "e-commerce-pod"
Command: ```bash kubectl port-forward pod/e-commerce-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 selected aut...
Create a new config map named 'app-secrets' with the 'conf' key sourced from '/path/to/profiles/file1.txt' and the 'data' key sourced from '/path/to/preferences/file2.txt'
Command: ```bash kubectl create configmap app-secrets --from-file=conf=/path/to/profiles/file1.txt --from-file=data=/path/to/preferences/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...
Run the 'mysqld' command in the nebula-navigator container of the frontend-pod, and get the output.
Command: ```bash kubectl exec frontend-pod -c nebula-navigator -- mysqld ``` 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...
Retrieve information about specific resources by type and name
Command: ```bash kubectl get rc/web service/media-stream-rc pods/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 namespac...
Set the CPU and memory resource limits and requests for all containers in the 'alpine' deployment
Command: ```bash kubectl set resources deployment alpine --limits=cpu=200m,memory=512Mi --requests=cpu=2,memory=1Gi ``` 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,...
Listen on ports 8081 and 6000 on your local machine and forward the data to and from ports 8081 and 6000 in the pod selected by the deployment named 'search-engine-deployment'.
Command: ```bash kubectl port-forward deployment/search-engine-deployment 8081 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 wil...
Create a job named "cleanup" using the "node" image and execute the command "node"
Command: ```bash kubectl create job cleanup --image=node -- node ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: json|...
Copy the local file '/tmp/foo' to the '/tmp/bar_dir' directory inside the remote pod named 'cache-pod-5', specifically in the 'logging-agent' container.
Command: ```bash kubectl cp /tmp/foo cache-pod-5:/tmp/bar_dir -c logging-agent ``` 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 k...
Attach to the 'rocket-ranger' container in the 'media-stream-pod' pod and get its output.
Command: ```bash kubectl attach media-stream-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 omitte...
Forward port 8081 locally 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...
Use the 'emacs' editor to edit the 'payment-service' service
Command: ```bash KUBE_EDITOR="emacs" kubectl edit svc/payment-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 variable...
Enable the OpenID Connect auth provider for the "robot-user" entry with the client-id set to "foo" and client-secret set to "bar"
Command: ```bash kubectl config set-credentials robot-user --auth-provider=oidc --auth-provider-arg=client-id=foo --auth-provider-arg=client-secret=bar ``` 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: --...
Add a taint with the key 'environment' on nodes with the label 'zone=us-east-1'.
Command: ```bash kubectl taint node -l zone=us-east-1 environment=testing-node-11:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "u...
expose a deployment named "ruby" on port 8181, with the containers listening on port 818100
Command: ```bash kubectl expose deployment ruby --port=8181 --target-port=818100 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified...
Attach to the astro-container in the media-stream-pod and get the output
Command: ```bash kubectl attach media-stream-pod -c astro-container ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omit...
Forward local port 8081 to port 6379 in the 'e-commerce-pod' pod
Command: ```bash kubectl port-forward pod/e-commerce-pod 8081 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 aut...
Scale the staging-app-rs deployment to 7 replicas if the current size is 1
Command: ```bash kubectl scale --current-replicas=1 --replicas=7 deployment/staging-app-rs ``` What it does: Set a new size for a deployment, replica set, replication controller, or stateful set. Scale also allows users to specify one or more preconditions for the scale action. If --current-replicas or --resource-vers...
Create a pod disruption budget named 'frontend-pdb' that will select all pods with the 'region=us-east' label and require at least 9 of them being available at any point in time
Command: ```bash kubectl create poddisruptionbudget frontend-pdb --selector=region=us-east --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 [-...
Execute the 'elasticsearch --version' command in the cosmic-container from the pod chat-app-pod and display the output.
Command: ```bash kubectl exec chat-app-pod -c cosmic-container -- elasticsearch --version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container na...
Return the logs of the previously terminated "lunar-launcher" container from the "web-app-pod" pod.
Command: ```bash kubectl logs -p -c lunar-launcher web-app-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", "s...
Set the cpu limits of the postgres container in the 'postgres' deployment to "100m" and memory limits to "1Gi"
Command: ```bash kubectl set resources deployment postgres -c=nginx --limits=cpu=100m,memory=1Gi ``` 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 service for a replication controller by specifying the configuration file "centos-controller.yaml"
Command: ```bash kubectl expose -f centos-controller.yaml --port=9091 --target-port=818100 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the...
Change the service account of the deployment "database-deployment" to "kube-proxy".
Command: ```bash kubectl set serviceaccount deployment database-deployment kube-proxy ``` 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: `kubect...
Start a php pod and expose port 8181
Command: ```bash kubectl run hazelcast --image=php --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": "--file...
Create an ingress called 'web-ingress' that directs requests from website.com/input to svc1:3001 with a TLS secret "my-cert"
Command: ```bash kubectl create ingress web-ingress --rule="website.com/input=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": "", "usage"...
Forward local traffic from port 9090 to port 6379 in the search-engine-deployment deployment
Command: ```bash kubectl port-forward deployment/search-engine-deployment 9090 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 wil...
Copy the local file ~/.config/kube to the remote pod message-broker-pod-15 in the container security-scanner, and place it at /tmp/bar.
Command: ```bash kubectl cp ~/.config/kube message-broker-pod-15::/tmp/bar -c security-scanner ``` 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 om...
create a config map named app-config using specific keys from files
Command: ```bash kubectl create configmap app-config --from-file=settings=/path/to/preferences/file1.txt --from-file=key2=/path/to/data/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 co...
Set the custom TLS server name to "on-prem-cluster" for the e2e cluster entry.
Command: ```bash kubectl config set-cluster e2e --tls-server-name=on-prem-cluster ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certificate-autho...
Create a new ExternalName service named external-email-service with the external name education-edu.edu.
Command: ```bash kubectl create service externalname external-email-service --external-name education-edu.edu ``` 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...
Forward traffic from port 8000 on your local machine to port 9090 in the pod named "cdn-service-pod"
Command: ```bash kubectl port-forward pod/cdn-service-pod 8000: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 au...
Remove all the taints with the key 'dedicated' from the 'gpu-node-12' node
Command: ```bash kubectl taint nodes gpu-node-12 dedicated- ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: json|yaml...
Forward ports 5000 and 6000 locally to ports 8088 and 6000 in the selected pod
Command: ```bash kubectl port-forward deployment/authentication-service-deployment 5000 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, ...
Create a pod disruption budget named logging-pdb that will select all pods with the tier=frontend label and require a minimum of four of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget logging-pdb --selector=tier=frontend --min-available=4 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-available=N [--d...
Create a copy of the "cdn-service-pod" with all container images changed to "golang" for debugging.
Command: ```bash kubectl debug cdn-service-pod --copy-to=my-debugger --set-image=*=golang ``` 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 reso...
Start an Alpine pod named 'nginx', but override the pod's specifications with a partial set of values parsed from a JSON file
Command: ```bash kubectl run nginx --image=alpine --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] [--overrides=inline-json] [--command] --...
Set the custom TLS server name to use for validation for the app-cluster cluster entry to "edge-cluster".
Command: ```bash kubectl config set-cluster app-cluster --tls-server-name=edge-cluster ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certificate-...
Rename the context 'cluster-1-context' to 'new-context' in your kubeconfig file
Command: ```bash kubectl config rename-context cluster-1-context new-context ``` What it does: Renames a context from the kubeconfig file. CONTEXT_NAME is the context name that you want to change. NEW_NAME is the new name you want to set. Note: If the context being renamed is the 'current-context', this field will als...
Expose a pod as a service on a specific port with a given name
Command: ```bash kubectl expose pod media-stream-pod --port=5000 --name=frontend ``` 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...
Forward traffic from port 5000 on all addresses to port 9090 in the pod "chat-app-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/chat-app-pod 5000: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...
Remove the 'tier' label from pod 'proxy-server'
Command: ```bash kubectl label pods proxy-server tier- ``` What it does: Update the labels on a resource. Syntax: `kubectl label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]` Helpful flags: "flag": "--all-namespaces", "short": "-A", "default": "false", "usage": "If...
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=properties=/path/to/properties/file1.txt --from-file=key1=/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 ...
Get the output from the time-machine container in the proxy-server-pod pod.
Command: ```bash kubectl attach proxy-server-pod -c time-machine ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted...
Add a taint with key 'app' on the nodes that have the label 'tier=frontend'
Command: ```bash kubectl taint node -l tier=frontend app=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": "", "usage":...
Start streaming the logs of the stardust-shuttle container in the auth-service-pod pod
Command: ```bash kubectl logs -f -c stardust-shuttle auth-service-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": "--contain...
Show the last 23 lines of logs for the pod named 'e-commerce-pod'
Command: ```bash kubectl logs --tail=23 e-commerce-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": "...
List the deployments in the "rc-1.1.0" version of the "testing-apps" API group in YAML output format.
Command: ```bash kubectl get deployments.rc-1.1.0.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 ...
Forward local port 8088 to port 5000 in the pod "web-app-pod"
Command: ```bash kubectl port-forward pod/web-app-pod 8088: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 automa...
Create a new NodePort service named gateway-nodeport
Command: ```bash kubectl create service nodeport gateway-nodeport --tcp=8080:8888 ``` 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": "",...
Create a new LoadBalancer service named vpn-service-lb that forwards traffic from port 9090 on the service to port 9090 on the pods
Command: ```bash kubectl create service loadbalancer vpn-service-lb --tcp=9090:9090 ``` 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", "def...
Copy the local file /tmp/foo_dir to the remote pod named file-server-pod-14 in the container named file-server, and place it in the /tmp/bar_dir directory
Command: ```bash kubectl cp /tmp/foo_dir file-server-pod-14:/tmp/bar_dir -c file-server ``` 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, ...
Copy the file /tmp/foo from the backend-pod-13 pod in the logging namespace to the local directory /tmp/bar_dir.
Command: ```bash kubectl cp logging/backend-pod-13::/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 kubect...
Create a copy of the 'database-pod' and add a debug container, changing the container's images
Command: ```bash kubectl debug database-pod -it --copy-to=dgb-img --image=debian --set-image=cache=redis:alpine,mailer=mailer:latest ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and na...
Approve a certificate signing request with the name 'csr-backend-5'
Command: ```bash kubectl certificate approve csr-backend-5 ``` 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 attr...
Add a taint with the key 'hardware' on nodes having the label role=database, such that the node-1 should PreferNoSchedule
Command: ```bash kubectl taint node -l role=database 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": "Outpu...
Set the cluster field to moon-cluster in the my-context context for client-2-context
Command: ```bash kubectl config set contexts.client-2-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...
Partially update a node using a strategic merge patch and a YAML file.
Command: ```bash kubectl patch node backup-node-14 -p $'data:\n key: new-value' ``` What it does: Update fields of a resource using strategic merge patch, a JSON merge patch, or a JSON patch. JSON and YAML formats are accepted. Syntax: `kubectl patch (-f FILENAME | TYPE NAME) [-p PATCH|--patch-file FILE]` Helpful fl...
Create a pod disruption budget named elastic-search-pdb that will select all pods with the release=1.0.0 label and require at least 9 of them being available at any point in time
Command: ```bash kubectl create poddisruptionbudget elastic-search-pdb --selector=release=1.0.0 --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...