prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Update the pod 'chat-app' with the annotation 'deployment-script' and the value 'https', overwriting any existing value.
Command: ```bash kubectl annotate --overwrite pods chat-app deployment-script='https://example.com/deploy.sh' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can b...
Add or update the 'git-repo' annotation for the pod named 'web' with the value 'https://github.com/example/my-app'
Command: ```bash kubectl annotate pods web 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 larger than labels a...
Provide a detailed description of the admin-dashboard-pod pod.
Command: ```bash kubectl describe pods/admin-dashboard-pod ``` What it does: Show details of a specific resource or group of resources. Print a detailed description of the selected resources, including related resources such as events or controllers. You may select a single object by name, all objects of that type, pr...
Forward local ports 5000 to 6000 to the specified pod and vice versa
Command: ```bash kubectl port-forward pod/web-app-pod 5000 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...
Assign the service account "istio" to the deployment "authentication-service-deployment"
Command: ```bash kubectl set serviceaccount deployment authentication-service-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...
Import the EXTERNAL_API_URL key from the log-config config map and set it as an environment variable in the scheduler-app-deployment deployment.
Command: ```bash kubectl set env --keys=EXTERNAL_API_URL --from=configmap/log-config deployment/scheduler-app-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defi...
Add a taint with the key 'disktype' and value 'backup-node-14:PreferNoSchedule' to all nodes with the label 'tier=frontend'.
Command: ```bash kubectl taint node -l tier=frontend disktype=backup-node-14:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage"...
Create a service for a replication controller specified in a YAML file, serving on port 8010 and connecting to the containers on port 800000
Command: ```bash kubectl expose -f ubuntu-controller.yaml --port=8010 --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...
Set the custom TLS server name to "app-cluster" for the "my-k8s-cluster" cluster entry.
Command: ```bash kubectl config set-cluster my-k8s-cluster --tls-server-name=app-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...
Update the cluster associated with a specific context in the Kubernetes configuration
Command: ```bash kubectl config set contexts.client-2-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 y...
Create a new config map named api-config from the key=value pairs in the file located at path/to/profiles.
Command: ```bash kubectl create configmap api-config --from-file=path/to/profiles ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a config map based on a file, the key will default to the basename o...
Execute the command `gem --version` inside the first pod of the deployment `proxy-service-deployment`, using the first container by default.
Command: ```bash kubectl exec deploy/proxy-service-deployment -- gem --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...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=redis_host --from=configmap/app-config deployment/frontend-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in ...
Return the snapshot logs from the container frontend-deployment-1 of the deployment named chat-app-pod
Command: ```bash kubectl logs deployment/frontend-deployment -c chat-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: "flag": "...
Forward local ports 5000 to 6379 in a selected pod of the deployment named "api-server-deployment"
Command: ```bash kubectl port-forward deployment/api-server-deployment 5000 6379 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will b...
Update the annotation of the 'payment' pod only if the resource version is still 1.
Command: ```bash kubectl annotate pods payment description='my frontend running nginx' --resource-version=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 ...
Embed the certificate authority data for the "sun-cluster" cluster entry
Command: ```bash kubectl config set-cluster sun-cluster --embed-certs --certificate-authority=~/.kube/testing-cluster/kubernetes.ca.crt ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config s...
Execute the 'wp' command inside the pod named 'api-service-pod' and display the output
Command: ```bash kubectl exec api-service-pod -- wp ``` 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.kubern...
Create a new ClusterIP service named messaging-service-clusterip with the TCP port mapping of 9090 to 8888.
Command: ```bash kubectl create service clusterip messaging-service-clusterip --tcp=9090: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": "-...
Forward traffic from local port 8080 to the target port of the "https" service port in the selected pod in order to access the payment service.
Command: ```bash kubectl port-forward service/payment-service 8080: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 select...
Execute the command 'yum install -y wget' in the 'rocket-ranger' container of the 'analytics-pod' pod and display the output.
Command: ```bash kubectl exec analytics-pod -c rocket-ranger -- yum install -y wget ``` 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...
Embed the certificate authority data for the 'cluster-gamma' cluster entry
Command: ```bash kubectl config set-cluster cluster-gamma --embed-certs --certificate-authority=~/.kube/cloud-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...
List the specified resources by their type and names.
Command: ```bash kubectl get rc/web service/auth-service-rc pods/proxy-server-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 name...
Update the scaling policy for the pod specified in the "parameters.json" file to "auto-horizontal-scaling"
Command: ```bash kubectl annotate -f parameters.json 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 than labe...
Forward traffic from port 5000 on localhost and IP 10.19.21.23 to port 3000 in the pod named "api-service-pod"
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/api-service-pod 5000:3000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the cri...
Forward local port 5000 to port 9090 in the cdn-service-pod
Command: ```bash kubectl port-forward pod/cdn-service-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 be selected au...
Forward traffic from port 6379 on localhost and IP 10.19.21.23 to port 8000 in the pod named security-service-pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/security-service-pod 6379: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 th...
Autoscale the deployment named "database", with the number of pods ranging from 2 to 12.
Command: ```bash kubectl autoscale deployment database --min=2 --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 use...
List the resources of type 'rc' with the name 'web', the resources of type 'service' with the name 'proxy-server-rc', and the resources of type 'pods' with the name 'security-service-pod'.
Command: ```bash kubectl get rc/web service/proxy-server-rc pods/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 ...
List the specified resources by their type and names
Command: ```bash kubectl get rc/web service/auth-service-rc pods/database-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...
Update the label of the pod 'chat-app' with the label 'env' and the value 'staging'
Command: ```bash kubectl label pods chat-app env=staging ``` 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": "...
List deployments in JSON output format, using the "v3.0.0" version of the "mobile-apps" API group.
Command: ```bash kubectl get deployments.v3.0.0.mobile-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 running the 'kafka-console-producer --broker-list localhost:9092 --topic test' command from the pod 'web-app-pod' using the first container.
Command: ```bash kubectl exec web-app-pod -- kafka-console-producer --broker-list localhost:9092 --topic test ``` 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": "", "u...
Copy the local file '/tmp/foo' to the remote pod 'file-server-pod-14' in the 'logging' namespace and save it as '/tmp/bar'
Command: ```bash kubectl cp :/tmp/foo logging/file-server-pod-14::/tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubec...
Create a debug copy of a pod with container images changed to mysql
Command: ```bash kubectl debug cdn-service-pod --copy-to=debug-image-web --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 no r...
Forward port 8081 on localhost and IP 10.19.21.23 to port 9090 in the pod named cdn-service-pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/cdn-service-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 cri...
Create a new ExternalName service named 'external-payment-gateway-service' with the external name 'museum-example.museum'
Command: ```bash kubectl create service externalname external-payment-gateway-service --external-name museum-example.museum ``` 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 ...
Import the 'api_key' key from the 'db-config' config map into the deployment named 'backend-microservice-deployment'
Command: ```bash kubectl set env --keys=api_key --from=configmap/db-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 definit...
Create a new generic secret named password-secret with specified keys instead of names on disk
Command: ```bash kubectl create secret generic password-secret --from-file=ssh-privatekey=path/to/id_rsa --from-file=ssh-publickey=path/to/id_rsa.pub ``` 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...
Create a service for the 'wordpress' deployment with port 80 exposed that connects to the containers on port 8000.
Command: ```bash kubectl expose deployment wordpress --port=8010 --target-port=808900 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the spec...
Create a debug copy of the media-stream-pod with the rocket-ranger container and enter an interactive shell on it
Command: ```bash kubectl debug media-stream-pod -it --copy-to=my-debugger --container=rocket-ranger -- sh ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used by de...
Create a new config map named kube-system-config with the keys "conf" and "data" mapped to the files "/path/to/preferences/file1.txt" and "/path/to/profiles/file2.txt" respectively
Command: ```bash kubectl create configmap kube-system-config --from-file=conf=/path/to/preferences/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 creat...
Forward local port 8888 to the pod's port 8080 in the deployment 'authentication-service-deployment'.
Command: ```bash kubectl port-forward deployment/authentication-service-deployment 8888 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, ...
create a LoadBalancer service named database-lb with a mapping from port 6379 to port 7000
Command: ```bash kubectl create service loadbalancer database-lb --tcp=6379:7000 ``` 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", "defaul...
Execute the command 'kafka-server-start /etc/kafka/server.properties' in the 'frontend-pod' pod and get the output.
Command: ```bash kubectl exec frontend-pod -- kafka-server-start /etc/kafka/server.properties ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Containe...
Create a debug copy of the web-app-pod by adding a debug container and changing container images.
Command: ```bash kubectl debug web-app-pod -it --copy-to=debug-image-app --image=debian --set-image=mailer=mailer:latest,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 a...
Create an ingress called 'internal-ingress' that directs requests to website.com/example to a service named svc1 on port 9090
Command: ```bash kubectl create ingress internal-ingress --rule="website.com/example=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": "", ...
Start a new pod named "hazelcast" using the Alpine image and expose port 8443 on the container.
Command: ```bash kubectl run hazelcast --image=alpine --port=8443 ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args...]` Helpful flags: "flag": "--f...
Apply the taint 'workload=worker-node-3:PreferNoSchedule' to all nodes with the label 'customer=acme-corp'
Command: ```bash kubectl taint node -l customer=acme-corp workload=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": "", "us...
Scale the 'mysql' deployment to 3 replicas if the current size of the 'bar' deployment is 1.
Command: ```bash kubectl scale --current-replicas=1 --replicas=3 deployment/bar ``` 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...
Run the 'redis-cli' command in the 'quantum-quark' container of the 'security-service-pod' pod and get the output.
Command: ```bash kubectl exec security-service-pod -c quantum-quark -- redis-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 om...
Create a ClusterIP service named "cache-service-clusterip" that maps port 5000 on the service to port 8088 on the target pod
Command: ```bash kubectl create service clusterip cache-service-clusterip --tcp=5000:8088 ``` 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", ...
Forward local ports 8088 and 6000 to ports 6379 and 6000 in a pod selected by the deployment log-aggregator-deployment
Command: ```bash kubectl port-forward deployment/log-aggregator-deployment 8088 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 wi...
Create a service for a replication controller using a YAML file, exposing it on port 8084 and connecting to the containers on port 637900.
Command: ```bash kubectl expose -f wordpress-controller.yaml --port=8084 --target-port=637900 ``` 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 ...
Forward local traffic on port 8080 to port 8081 of a pod selected by the 'log-aggregator-deployment' deployment.
Command: ```bash kubectl port-forward deployment/log-aggregator-deployment 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 criteria, a pod wi...
Update the image of all containers in a daemonset named 'namespace-3' to 'ubuntu:20.04'.
Command: ```bash kubectl set image daemonset namespace-3 *=ubuntu:20.04 ``` 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: ...
List all deployments in JSON output format, using the "alpha-2.0" version of the "custom-apps" API group.
Command: ```bash kubectl get deployments.alpha-2.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 ...
Forward traffic from port 8080 on all addresses to port 5432 in the pod named "api-service-pod".
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/api-service-pod 8080:5432 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod w...
Create a single ingress named 'myapp-ingress' with the following rules:
Command: ```bash kubectl create ingress myapp-ingress --rule="testing.com/bar=svc1:9091,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 an ingress named 'api-v2-ingress' that routes requests from site.com/bar to svc1:5001 and uses the TLS secret "my-cert"
Command: ```bash kubectl create ingress api-v2-ingress --rule="site.com/bar=svc1:5001,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": ...
Add a taint with key 'disktype' and no value to the node 'monitoring-node-15'
Command: ```bash kubectl taint nodes monitoring-node-15 disktype:NoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. O...
Copy a file from a remote pod to a local directory.
Command: ```bash kubectl cp istio-system/payment-gateway-pod-19:/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, us...
Forward traffic from port 9090 on all addresses to port 5000 in the pod "mypod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/mypod 9090: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 sel...
Create an ingress called 'app-loadbalancer-ingress' that routes requests to 'testing.com/module' to 'svc1:8443' with the TLS secret "my-cert"
Command: ```bash kubectl create ingress app-loadbalancer-ingress --rule="testing.com/module=svc1:8443,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default...
Edit the 'analytics-service' service using the vim editor
Command: ```bash KUBE_EDITOR="vim" kubectl edit svc/analytics-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...
Import environment variables from a specific secret
Command: ```bash kubectl set env --from=secret/my-secret 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 variable definitions in one or more po...
Forward traffic from port 3000 on localhost and IP address 10.19.21.23 to port 8888 in the pod named "analytics-pod"
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/analytics-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 crite...
Return snapshot logs from the container auth-service-pod-1 of the deployment email-server-deployment
Command: ```bash kubectl logs deployment/email-server-deployment -c auth-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 flags: "...
Create an ingress named 'api-gateway-ingress' that routes requests to testing.com/module to the service 'svc1' on port 8080
Command: ```bash kubectl create ingress api-gateway-ingress --rule="testing.com/module=svc1:8080,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 binding for multiple users and groups using a specific cluster role
Command: ```bash kubectl create clusterrolebinding default_role --clusterrole=default_role --user=app-operator --user=sysadmin --group=security-auditors ``` What it does: Create a cluster role binding for a particular cluster role. Syntax: `kubectl create clusterrolebinding NAME --clusterrole=NAME [--user=username] [...
Configure the OpenID Connect authentication provider for the "k8s-admin" entry with additional arguments
Command: ```bash kubectl config set-credentials k8s-admin --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: --c...
Listen on port 9090 on all addresses and forward the traffic to port 9090 in the 'cdn-service-pod' pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/cdn-service-pod 9090: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 w...
Create a new config map named app-settings with specified keys from file paths
Command: ```bash kubectl create configmap app-settings --from-file=settings=/path/to/data/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 creating a c...
Add a taint with key 'environment' on nodes having label app=web-app
Command: ```bash kubectl taint node -l app=web-app environment=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": "Outp...
Create a new config map named "namespace-config" using specified files
Command: ```bash kubectl create configmap namespace-config --from-file=conf=/path/to/configs/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 creat...
Import the 'api_key' key from the 'app-config-dev' ConfigMap into the 'proxy-service-deployment' deployment
Command: ```bash kubectl set env --keys=api_key --from=configmap/app-config-dev 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 definitio...
Create a service for the replication controller defined in the "python-controller.yaml" file
Command: ```bash kubectl expose -f python-controller.yaml --port=80 --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 s...
Create a new secret named tls-certificate-secret with the specified keys instead of names on disk.
Command: ```bash kubectl create secret generic tls-certificate-secret --from-file=ssh-privatekey=path/to/id_rsa --from-file=ssh-publickey=path/to/id_rsa.pub ``` 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...
Retrieve the details of the 'frontend-rc' replication controller in ps output format
Command: ```bash kubectl get replicationcontroller frontend-rc ``` 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...
Set environment variable GOOGLE_API_KEY for deployment 'payment-processor-deployment'
Command: ```bash kubectl set env deployment/payment-processor-deployment GOOGLE_API_KEY=your-google-api-key ``` 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...
Create a cluster role named "admin_role" with API Group specified
Command: ```bash kubectl create clusterrole admin_role --verb=proxy,update,patch --resource=deployments.apps ``` 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": "-...
Set the CPU and memory limits and requests for all containers in the mysql deployment to 200m CPU limit, 512Mi memory limit, and 50m CPU request, 512Mi memory request.
Command: ```bash kubectl set resources deployment mysql --limits=cpu=200m,memory=512Mi --requests=cpu=50m,memory=512Mi ``` 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 request...
Forward the local port 8081 to port 8088 in the pod named "api-service-pod", allowing access from both localhost and the IP address 10.19.21.23.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/api-service-pod 8081:8088 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the cri...
Forward traffic from port 8888 on all addresses to port 8081 in the pod named "api-service-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/api-service-pod 8888: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 w...
Forward traffic from port 8888 on all addresses to port 8888 in the backend-pod pod. Listen on all addresses.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/backend-pod 8888: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 ...
Add a taint with key 'cpu-type' on nodes having label tier=frontend
Command: ```bash kubectl taint node -l tier=frontend cpu-type=db-node-7:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Ou...
Retrieve the output from executing the 'ash' command in the 'mycontainer' container of the 'vpn-service-pod' pod.
Command: ```bash kubectl exec vpn-service-pod -c mycontainer -- ash ``` 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 th...
Retrieve the output from running the 'nginx -t' command in the 'cyber-sleuth' container of the 'security-service-pod' pod.
Command: ```bash kubectl exec security-service-pod -c cyber-sleuth -- 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 omit...
Update the pod identified by type and name in the "docker-registry.yaml" file by annotating it with the compliance level "PCI-DSS"
Command: ```bash kubectl annotate -f docker-registry.yaml compliance-level=PCI-DSS ``` 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 in...
Create a job called "monitoring-job" using the MySQL image and run the MySQL command.
Command: ```bash kubectl create job monitoring-job --image=mysql -- mysql ``` 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 ...
Copy a directory from a remote pod to a local directory
Command: ```bash kubectl cp logging/file-server-pod-14:/tmp/foo_dir /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...
Remove the 'dedicated' taint from the 'worker-node-3' node.
Command: ```bash kubectl taint nodes worker-node-3 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|ya...
Attach to pod mypod and get output from the cyber-sleuth container
Command: ```bash kubectl attach mypod -c cyber-sleuth ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the k...
List deployments in the "legacy-1.0.0" version of the "alpha-apps" API group in JSON output format
Command: ```bash kubectl get deployments.legacy-1.0.0.alpha-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 local port 8888 to port 3000 in a pod selected by the 'email-server-deployment' deployment.
Command: ```bash kubectl port-forward deployment/email-server-deployment 8888 3000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will...
Update the 'monitoring' pod with the annotation 'scaling-policy' and set the value to 'auto-horizontal-scaling'.
Command: ```bash kubectl annotate pods monitoring 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 than labels ...
Create a copy of the analytics-pod called my-custom-dbg and change all container images to python.
Command: ```bash kubectl debug analytics-pod --copy-to=my-custom-dbg --set-image=*=python ``` 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...
Import the SECRET_KEY key from the env-vars config map into the load-balancer-deployment deployment
Command: ```bash kubectl set env --keys=SECRET_KEY --from=configmap/env-vars 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 ...
Create a new ClusterIP service named 'auth-service-clusterip' with the TCP port mapping of 8083 to the target port 8088.
Command: ```bash kubectl create service clusterip auth-service-clusterip --tcp=8083:8088 ``` 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", "...
Create a job named "monitoring-job" using the ruby image and run the command "irb" inside the job.
Command: ```bash kubectl create job monitoring-job --image=ruby -- irb ``` 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:...