prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Update the runtime deployment's nginx container to have a CPU limit of "5" and a memory limit of "256Mi".
Command: ```bash kubectl set resources deployment runtime -c=nginx --limits=cpu=5,memory=256Mi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requested, but may burst up to ...
Retrieve the snapshot logs from the container "frontend-pod-1" of the "web-app-deployment" deployment
Command: ```bash kubectl logs deployment/web-app-deployment -c frontend-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": "-...
Create a new secret named api-secret-key with the key1 set to "supersecret" and key2 set to "topsecret"
Command: ```bash kubectl create secret generic api-secret-key --from-literal=key1=supersecret --from-literal=key2=topsecret ``` 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 ...
view the rollout history of the deployment named "namespace-1"
Command: ```bash kubectl rollout history deployment/namespace-1 ``` What it does: View previous rollout revisions and configurations. Syntax: `kubectl rollout history (TYPE NAME | TYPE/NAME) [flags]` Helpful flags: "flag": "--filename", "short": "-f", "default": "[]", "usage": "Filename, directory, or URL to files i...
create a new ExternalName service named external-file-storage-service with an external name of sandbox-site.co
Command: ```bash kubectl create service externalname external-file-storage-service --external-name sandbox-site.co ``` 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...
Forward traffic from port 8088 on localhost and IP 10.19.21.23 to port 8080 in the analytics-pod pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/analytics-pod 8088: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 crite...
Check if you have permission to list the "log-rotation-job" job in the "kube-node-lease" namespace.
Command: ```bash kubectl auth can-i list jobs.batch/log-rotation-job -n kube-node-lease ``` What it does: Check whether an action is allowed. VERB is a logical Kubernetes API verb like 'get', 'list', 'watch', 'delete', etc. TYPE is a Kubernetes resource. Shortcuts and groups will be resolved. NONRESOURCEURL is a parti...
Create a deployment named my-dep with the mysql image, and set the number of replicas to 6.
Command: ```bash kubectl create deployment my-dep --image=mysql --replicas=6 ``` 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: j...
Set the user field for the team-alpha-context without modifying any other values
Command: ```bash kubectl config set-context team-alpha-context --user=cluster-admin ``` What it does: Set a context 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-context [NAME | --current] [--cluster=cluster_nic...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=DATABASE_URL --from=configmap/global-config deployment/api-server-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definiti...
Output the modified 'order-processing-deployment' deployment in YAML format after setting the 'DEBUG' environment variable to 'true' and without modifying the object on the server
Command: ```bash kubectl set env deployment/order-processing-deployment DEBUG=true -o yaml ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more pod tem...
Forward ports 8081 and 6000 locally to a pod selected by the deployment "log-aggregator-deployment"
Command: ```bash kubectl port-forward deployment/log-aggregator-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 wi...
Create a service named "frontend" for the pod "proxy-service-pod" and expose it on port 8443
Command: ```bash kubectl expose pod proxy-service-pod --port=8443 --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 specifie...
Set the service account of the deployment 'order-processing-deployment' to 'dashboard'
Command: ```bash kubectl set serviceaccount deployment order-processing-deployment dashboard ``` 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: ...
Retrieve a list of deployments in the "feature-branch-2.3.0" version of the "api-v1" API group, and format the output in JSON format.
Command: ```bash kubectl get deployments.feature-branch-2.3.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 namespace...
Import environment variables from a ConfigMap with a prefix
Command: ```bash kubectl set env --from=configmap/global-config --prefix=MYSQL_ deployment/user-management-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definit...
List all deployments in the "stable-2.0.0" version of the "testing-apps" API group in JSON output format.
Command: ```bash kubectl get deployments.stable-2.0.0.testing-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 ...
Create a copy of the vpn-service-pod and change all container images to ubuntu, using the command kubectl debug vpn-service-pod --copy-to=debug-image-web --set-image=*=ubuntu
Command: ```bash kubectl debug vpn-service-pod --copy-to=debug-image-web --set-image=*=ubuntu ``` 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 ...
Retrieve the logs of the previous terminated cyber-sleuth container from the log-aggregator-pod pod.
Command: ```bash kubectl logs -p -c cyber-sleuth log-aggregator-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container...
Update the pod named 'email' by setting the annotation 'SLA' to '99.9% uptime', replacing any existing value.
Command: ```bash kubectl annotate --overwrite pods email 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 a...
Print the namespaced resources supported by the Kubernetes API server,
Command: ```bash kubectl api-resources --shortnamesspaced=true ``` What it does: Print the supported API resources on the server. Syntax: `kubectl api-resources` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: wide|name. "
Automatically adjust the number of pods for the "log-aggregator" deployment, with a minimum of 1 pod and a maximum of 9 pods.
Command: ```bash kubectl autoscale deployment log-aggregator --min=1 --max=9 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler tha...
get deployments in JSON format, using a specific API group and version
Command: ```bash kubectl get deployments.v1.0.0.testing-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 wi...
Create a single ingress named 'internal-ingress' that routes requests from 'site.com/bar' to the service 'svc1' on port 3000, using the TLS secret 'my-cert'.
Command: ```bash kubectl create ingress internal-ingress --rule="site.com/bar=svc1:3000,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"...
Copy the local file /tmp/foo_dir to the remote pod security-scanner-pod-18 in the monitoring namespace, renaming it as /tmp/bar
Command: ```bash kubectl cp /tmp/foo_dir monitoring/security-scanner-pod-18::/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, us...
Listen on port 5432 on all addresses, forwarding to port 5432 in the 'log-aggregator-pod' pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/log-aggregator-pod 5432: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...
Start a pod named 'nginx' with the 'wordpress' image, and customize the pod specification by overriding some values using a JSON file.
Command: ```bash kubectl run nginx --image=wordpress --overrides='{ "apiVersion": "hotfix-1.1.2", "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 an ingress called 'api-v1-ingress' that directs requests to site.com/example to svc # svc1:8083 with a tls secret "my-cert"
Command: ```bash kubectl create ingress api-v1-ingress --rule="site.com/example=svc1:8083,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usag...
Set the 'criticality' annotation of the 'monitoring' pod to 'high'.
Command: ```bash kubectl annotate pods monitoring criticality=high ``` 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 ...
Create a deployment named "db" using the ethereum/client-go image and expose port 8000.
Command: ```bash kubectl create deployment db --image=ethereum/client-go --port=8000 ``` 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. O...
Embed the certificate authority data for the 'cluster-alpha' cluster entry using the command:
Command: ```bash kubectl config set-cluster cluster-alpha --embed-certs --certificate-authority=~/.kube/e2e/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 set-cluster...
Add a taint with key 'app' on nodes having label customer=acme-corp
Command: ```bash kubectl taint node -l customer=acme-corp app=web-node-8:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "O...
Forward traffic from port 5000 on all addresses to port 9090 in the pod named "cdn-service-pod
Command: ```bash kubectl port-forward --address 0.0.0.0 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 w...
Partially update a node using strategic merge patch
Command: ```bash kubectl patch -f machine-configuration.yaml -p '{"spec":{"rules":[{"http":{"paths":[{"path":"/","backend":{"service": {"name": "new-service"}}}]}}' ``` 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. Synta...
Create a service for the 'hazelcast' replica set that serves on port 9000 and connects to the containers on port 300000.
Command: ```bash kubectl expose rs hazelcast --port=9000 --target-port=300000 ``` 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 po...
Create a copy of the proxy-service-pod, adding a debug container and changing the container images
Command: ```bash kubectl debug proxy-service-pod -it --copy-to=my-custom-dbg --image=debian --set-image=database=mysql:5.7,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...
Remove the label 'env' from the 'vpn' pod
Command: ```bash kubectl label pods vpn env- ``` 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 true, che...
Add a taint with the key "cpu-type" on nodes having the label "namespace=mynamespace" and set the taint to "PreferNoSchedule" for the node with name "monitoring-node-15".
Command: ```bash kubectl taint node -l namespace=mynamespace cpu-type=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":...
Create a job named 'database-seeding-job' using the 'ruby' image and run the 'ruby --version' command within the job
Command: ```bash kubectl create job database-seeding-job --image=ruby -- ruby --version ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Outpu...
Rename the 'prod-context' to 'user-a-context' in your kubeconfig file
Command: ```bash kubectl config rename-context prod-context user-a-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 also ...
Set the custom TLS server name for the "data-cluster" cluster entry.
Command: ```bash kubectl config set-cluster data-cluster --tls-server-name=moon-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...
Import environment variables with the prefix "MYSQL_" from the config map "kube-system-config" and apply them to the deployment named "load-balancer-deployment"
Command: ```bash kubectl set env --from=configmap/kube-system-config --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 defi...
Switch to raw terminal mode and attach to the 'analytics-pod' container 'lunar-launcher'
Command: ```bash kubectl attach analytics-pod -c lunar-launcher -i -t ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If om...
Forward traffic from a local random port to port 5000 in the specified pod
Command: ```bash kubectl port-forward pod/proxy-server-pod :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 autom...
Create a service for a replicated node using a replica set, which serves on port 9000 and connects to the containers on port 8081.
Command: ```bash kubectl expose rs node --port=9000 --target-port=808100 ``` 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 an ingress named 'api-v2-ingress' with a rule that directs requests from "testing.com/example" to "svc1:9090" using a TLS secret named "my-cert".
Command: ```bash kubectl create ingress api-v2-ingress --rule="testing.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": "", "u...
Set the service account of the deployment "email-server-deployment" to "metrics-server"
Command: ```bash kubectl set serviceaccount deployment email-server-deployment metrics-server ``` What it does: Update the service account of pod template resources. Possible resources (case insensitive) can be: replicationcontroller (rc), deployment (deploy), daemonset (ds), job, replicaset (rs), statefulset Syntax:...
Update the 'authentication-service-deployment' deployment with a new environment variable for the database host.
Command: ```bash kubectl set env deployment/authentication-service-deployment DB_HOST=localhost ``` 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...
Set the cluster field in a specific context to a specified cluster
Command: ```bash kubectl config set contexts.edge-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 wa...
forward the local port 5000 to port 6379 in the 'backend-pod' pod.
Command: ```bash kubectl port-forward pod/backend-pod 5000:6379 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automa...
Begin streaming the logs of the 'rocket-ranger' container in the 'security-service-pod' pod
Command: ```bash kubectl logs -f -c rocket-ranger security-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": "--contai...
Create a job with the command "apache2ctl -D FOREGROUND" and use the WordPress image
Command: ```bash kubectl create job batch-processing --image=wordpress -- apache2ctl -D FOREGROUND ``` 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": "", "usa...
Create a job called deployment-rollout-job using the redis image. The job should run the command "redis-cli".
Command: ```bash kubectl create job deployment-rollout-job --image=redis -- redis-cli ``` 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 ...
Create a new config map named app-secrets by importing options from a folder path.
Command: ```bash kubectl create configmap app-secrets --from-file=path/to/options ``` 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...
Forward data between localhost ports 5000 and 8000 to the selected pod ports 5000 and 8000 of the 'api-server-deployment' deployment.
Command: ```bash kubectl port-forward deployment/api-server-deployment 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 pod will b...
Update the CPU and memory limits for the Ruby container in the deployment named "ruby" by setting the CPU limit to "50m" and the memory limit to "1Gi".
Command: ```bash kubectl set resources deployment ruby -c=nginx --limits=cpu=50m,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 to its...
Execute 'yum install -y wget' command in the first container of the loadbalancer-service pod and get the output
Command: ```bash kubectl exec svc/loadbalancer-service -- 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 omitt...
Create a service for a replicated python app
Command: ```bash kubectl expose rc python --port=80 --target-port=909200 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port. A...
Add a taint to nodes with label 'cluster=my-cluster' indicating that they prefer not to schedule pods that require a specific disk type.
Command: ```bash kubectl taint node -l cluster=my-cluster disktype=storage-node-13:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "...
Create a service for the 'ubuntu' deployment, which serves on port 8083 and connects to the containers on port 909000 in default namespace
Command: ```bash kubectl expose deployment ubuntu --port=8083 --target-port=909000 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specifi...
Forward local port 3000 to port 8088 in the pod selected by the deployment "analytics-platform-deployment"
Command: ```bash kubectl port-forward deployment/analytics-platform-deployment 3000 8088 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a po...
Copy the local file /tmp/foo_dir to /tmp/bar inside the remote pod api-server-pod-3, specifically in the front-end-container container.
Command: ```bash kubectl cp /tmp/foo_dir api-server-pod-3:/tmp/bar -c front-end-container ``` 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...
Update the label of the pod named 'auth' to have the key 'component' and the value 'api'
Command: ```bash kubectl label pods auth component=api ``` 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...
Add a taint with the key 'hardware' on nodes having the label version=v1.0.0, with the value 'worker-node-3:PreferNoSchedule'
Command: ```bash kubectl taint node -l version=v1.0.0 hardware=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"...
Create a new config map named 'namespace-config' with specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap namespace-config --from-file=settings=/path/to/preferences/file1.txt --from-file=key2=/path/to/options/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...
remove the label 'unhealthy' from the pod named 'auth'
Command: ```bash kubectl label pods auth unhealthy- ``` 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 tr...
Create a new config map named ui-config with the specified files as keys: settings=/path/to/settings/file1.txt and key2=/path/to/profiles/file2.txt
Command: ```bash kubectl create configmap ui-config --from-file=settings=/path/to/settings/file1.txt --from-file=key2=/path/to/profiles/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a co...
Update the deployment 'email-server-deployment' by adding a new environment variable 'DB_PASSWORD' with the value 'secretpassword'
Command: ```bash kubectl set env deployment/email-server-deployment DB_PASSWORD=secretpassword ``` 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...
Create a cluster role binding named "cluster-admin" that grants the "cluster-admin" cluster role to the users "app-operator" and "sysadmin", as well as the "security-auditors" group
Command: ```bash kubectl create clusterrolebinding cluster-admin --clusterrole=cluster-admin --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]...
Partially update a node using a strategic merge patch
Command: ```bash kubectl patch -f node-specific.yaml -p '{"spec":{"containers":[{"name":"container-name", "resources":{"limits":{"cpu":"200m"}}}]}' ``` 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...
Forward all traffic on port 9090 to the analytics-pod's port 9090, allowing access on any IP address.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/analytics-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 wil...
Retrieve the previous terminated logs of the nebula-navigator container from the media-stream-pod pod
Command: ```bash kubectl logs -p -c nebula-navigator media-stream-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...
Create a copy of the 'frontend-pod' with the container 'mycontainer' and change the command to 'sh'
Command: ```bash kubectl debug frontend-pod -it --copy-to=my-custom-dbg --container=mycontainer -- 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 defaul...
Add a taint with key 'hardware' on nodes having label customer=acme-corp
Command: ```bash kubectl taint node -l customer=acme-corp 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": "", "usage"...
Embed the certificate authority data for the 'on-prem-cluster' cluster entry by running the command "kubectl config set-cluster on-prem-cluster --embed-certs --certificate-authority=~/.kube/on-prem-cluster/kubernetes.ca.crt"
Command: ```bash kubectl config set-cluster on-prem-cluster --embed-certs --certificate-authority=~/.kube/on-prem-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 conf...
Forward local port 8000 to port 3000 in the pod named chat-app-pod
Command: ```bash kubectl port-forward pod/chat-app-pod 8000 3000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected autom...
Create a new config map named app-config with specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap app-config --from-file=properties=/path/to/settings/file1.txt --from-file=key1=/path/to/configs/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a ...
Create a pod named "hazelcast" using the NGINX image, and expose port 3001 for the container.
Command: ```bash kubectl run hazelcast --image=nginx --port=3001 ``` 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...
Set the service account of the deployment "gateway-deployment" to "tekton".
Command: ```bash kubectl set serviceaccount deployment gateway-deployment tekton ``` 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: `kubectl set...
Set up autoscaling for the "payment" replication controller with a target CPU utilization of 60% and the number of pods ranging from 1 to 6.
Command: ```bash kubectl autoscale rc payment --max=6 --cpu-percent=60 ``` 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...
Scale the frontend-rs deployment to 1 replica if its current size is also 1
Command: ```bash kubectl scale --current-replicas=1 --replicas=1 deployment/frontend-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-version...
delete multiple pods and services with specific names
Command: ```bash kubectl delete pod,service log-aggregator security ``` 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 s...
Create a job named "audit-job" using the provided Elasticsearch image and command
Command: ```bash kubectl create job audit-job --image=docker.elastic.co/elasticsearch/elasticsearch -- elasticsearch --version ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short...
Execute the command 'kafka-server-start /etc/kafka/server.properties' in the warp-drive container of the database-pod pod.
Command: ```bash kubectl exec database-pod -c warp-drive -- 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": "", "usa...
Create a job named "indexing" using the specified image and command
Command: ```bash kubectl create job indexing --image=mcr.microsoft.com/dotnet/core/runtime -- dotnet --list-runtimes ``` 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", "...
Execute the 'go version' command inside the rocket-ranger container of the mypod pod and display the output.
Command: ```bash kubectl exec mypod -c rocket-ranger -- 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 omitted, use the...
Start streaming the logs of the 'mycontainer' container in the 'proxy-service-pod' pod
Command: ```bash kubectl logs -f -c mycontainer proxy-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": "--container",...
Open the web-service service definition for editing using the 'nvim' editor
Command: ```bash KUBE_EDITOR="nvim" kubectl edit svc/web-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, or...
Create a job to build an image and run a command on it
Command: ```bash kubectl create job image-build-job --image=confluentinc/cp-kafka -- kafka-console-producer --broker-list localhost:9092 --topic test ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "fl...
Add a taint on nodes with the label "project=project-alpha" with the key "disktype" and value "backup-node-14" and set the effect to "PreferNoSchedule".
Command: ```bash kubectl taint node -l project=project-alpha 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": "",...
Start a pod named 'nginx' using the 'ubuntu' image
Command: ```bash kubectl run nginx --image=ubuntu ``` 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": "--filename", "short...
Set the cluster field in the 'on-prem-context' context to 'data-cluster'
Command: ```bash kubectl config set contexts.on-prem-context.cluster data-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 ...
Copy the local file "/tmp/foo" to the remote pod "cache-pod-5" in the "/tmp/bar_dir" directory, specifically in the "payment-gateway" container.
Command: ```bash kubectl cp /tmp/foo cache-pod-5:/tmp/bar_dir -c payment-gateway ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the...
Create a new ClusterIP service named order-service-clusterip
Command: ```bash kubectl create service clusterip order-service-clusterip --tcp=8081:9090 ``` 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", ...
rename the context "testing-context" to "client-2-context"
Command: ```bash kubectl config rename-context testing-context client-2-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 ...
Forward local port 8000 to port 5000 in the database-deployment pod
Command: ```bash kubectl port-forward deployment/database-deployment 8000 5000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be ...
Forward local port 5432 to the targetPort of the "https" service port in the selected pod by the email-service service
Command: ```bash kubectl port-forward service/email-service 5432: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 selected...
Get the output from running the 'elasticsearch' command in the 'code-explorer' container of the 'security-service-pod' pod
Command: ```bash kubectl exec security-service-pod -c code-explorer -- elasticsearch ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. I...
Add a taint with the key 'environment' on nodes that have the label 'project=project-alpha'
Command: ```bash kubectl taint node -l project=project-alpha environment=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": "", "...
Approve a Certificate Signing Request (CSR) with the name 'csr-redis-11'
Command: ```bash kubectl certificate approve csr-redis-11 ``` What it does: Approve a certificate signing request. kubectl certificate approve allows a cluster admin to approve a certificate signing request (CSR). This action tells a certificate signing controller to issue a certificate to the requestor with the attri...