prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Set the custom TLS server name to "star-cluster" for the "dev-cluster" cluster entry.
Command: ```bash kubectl config set-cluster dev-cluster --tls-server-name=star-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-...
Update the compliance level annotation of a pod specified in the "preferences.json" file.
Command: ```bash kubectl annotate -f preferences.json 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 includ...
Create a cron job named 'data-sync' with the image 'nginx' that runs every minute
Command: ```bash kubectl create cronjob data-sync --image=nginx --schedule="*/1 * * * *" -- nginx -t ``` What it does: Create a cron job with the specified name. Syntax: `kubectl create cronjob NAME --image=image --schedule='0/5 * * * ?' -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "defa...
Create a new generic secret named 'ssl-key-secret' from the files in the 'path/to/settings' folder.
Command: ```bash kubectl create secret generic ssl-key-secret --from-file=path/to/settings ``` What it does: Create a secret based on a file, directory, or specified literal value. A single secret may package one or more key/value pairs. When creating a secret based on a file, the key will default to the basename of t...
Set the service account of the deployment named 'gateway-deployment' to 'metrics-server'
Command: ```bash kubectl set serviceaccount deployment gateway-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: `kub...
Scale the deployment named "webapp-replicaset" to have 7 replicas, if the current size is 5.
Command: ```bash kubectl scale --current-replicas=5 --replicas=7 deployment/webapp-replicaset ``` 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-v...
Forward traffic from local port 9090 to port 8081 in the specified pod
Command: ```bash kubectl port-forward pod/backend-pod 9090:8081 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automa...
Execute the command 'apache2ctl -D FOREGROUND' in container 'mycontainer' of pod 'mypod' and get the output.
Command: ```bash kubectl exec mypod -c mycontainer -- apache2ctl -D FOREGROUND ``` 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...
Add or update an annotation on the pod 'email' with the key 'SLA' and the value '99.9% uptime'
Command: ```bash kubectl annotate 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 arbitrary str...
Import the 'smtp_server' key from the 'monitoring-config' ConfigMap into the 'scheduler-app-deployment' deployment.
Command: ```bash kubectl set env --keys=smtp_server --from=configmap/monitoring-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 de...
Attach to the `code-explorer` container in the `log-aggregator-pod` pod
Command: ```bash kubectl attach log-aggregator-pod -c code-explorer ``` 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...
create a LoadBalancer service named cdn-service-lb on port 8081, forwarding traffic to port 5001
Command: ```bash kubectl create service loadbalancer cdn-service-lb --tcp=8081:5001 ``` 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...
Start a pod with a PostgreSQL container and expose port 8080 for communication
Command: ```bash kubectl run hazelcast --image=postgres --port=8080 ``` 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": "-...
Create a deployment with the name "app" using the golang image and set the number of replicas to 7.
Command: ```bash kubectl create deployment app --image=golang --replicas=7 ``` 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: jso...
Create an ingress called 'myapp-ingress' that directs requests from site.com/example to svc1:8443 with the tls secret "my-cert"
Command: ```bash kubectl create ingress myapp-ingress --rule="site.com/example=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": "", "usage...
Start listening on port 8888 on localhost and IP address 10.19.21.23, and forward the traffic to port 8080 in the 'chat-app-pod' pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/chat-app-pod 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 criter...
Update the annotation 'deployment-script' of the pod 'frontend' with the value 'https://example.com/deploy.sh'
Command: ```bash kubectl annotate pods frontend 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 be larger tha...
Create a new secret named azure-storage-secret using the parameters from the env file located at path/to/parameters.env
Command: ```bash kubectl create secret generic azure-storage-secret --from-env-file=path/to/parameters.env ``` What it does: Create a secret based on a file, directory, or specified literal value. A single secret may package one or more key/value pairs. When creating a secret based on a file, the key will default to t...
Remove all the taints with the key 'dedicated' from the node 'k8s-node-1'
Command: ```bash kubectl taint nodes k8s-node-1 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|...
Create a new pod named 'jenkins' using the Jenkins image, and pass custom arguments `<arg1> <arg2> ..
Command: ```bash kubectl run nginx --image=jenkins -- <arg1> <arg2> ... <argN> ``` 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:...
Create a copy of the 'analytics-pod' pod, changing all container images to 'docker.elastic.co/elasticsearch/elasticsearch'
Command: ```bash kubectl debug analytics-pod --copy-to=debug-image-1 --set-image=*=docker.elastic.co/elasticsearch/elasticsearch ``` 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. ...
Import environment variables from a secret into a deployment
Command: ```bash kubectl set env --from=secret/my-secret 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 definitions in one or mor...
forward traffic from port 8888 on all addresses to port 6379 in the pod named 'mypod'
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/mypod 8888: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 sel...
Set the cluster field of the my-context context to web-cluster
Command: ```bash kubectl config set contexts.cluster-1-context.cluster web-cluster ``` What it does: Set an individual value in a kubeconfig file. PROPERTY_NAME is a dot delimited name where each token represents either an attribute name or a map key. Map keys may not contain dots. PROPERTY_VALUE is the new value you...
Add a taint with the key 'special' on nodes that have the label project=project-alpha
Command: ```bash kubectl taint node -l project=project-alpha special=gpu-node-12: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...
Embed certificate authority data for the web-cluster cluster entry.
Command: ```bash kubectl config set-cluster web-cluster --embed-certs --certificate-authority=~/.kube/galaxy-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 se...
Copy the local file '/tmp/foo' to '/tmp/bar' in the 'backend-pod-13' pod, specifically in the 'api-server-container' container.
Command: ```bash kubectl cp :/tmp/foo backend-pod-13::/tmp/bar -c api-server-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, u...
Apply the configuration from the parameters.json file to a pod
Command: ```bash kubectl apply -f ./parameters.json ``` What it does: Apply a configuration to a resource by file name or stdin. The resource name must be specified. This resource will be created if it doesn't exist yet. To use 'apply', always create the resource initially with either 'apply' or 'create --save-config'...
Create a new secret named 'api-key-secret' using the values from the 'configs.env' file
Command: ```bash kubectl create secret generic api-key-secret --from-env-file=path/to/configs.env ``` What it does: Create a secret based on a file, directory, or specified literal value. A single secret may package one or more key/value pairs. When creating a secret based on a file, the key will default to the basena...
Expose the alpine deployment as a service on port 8888
Command: ```bash kubectl expose deployment alpine --port=8888 --target-port=500100 ``` 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...
Start a node pod with the name 'nginx' and the image 'node', but override the spec with a partial set of values parsed from the provided JSON
Command: ```bash kubectl run nginx --image=node --overrides='{ "apiVersion": "legacy-1.0.0", "spec": { ... } }' ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [CO...
Import the 'debug_mode' key from the 'app-name-config' config map into the 'monitoring-stack-deployment' deployment.
Command: ```bash kubectl set env --keys=debug_mode --from=configmap/app-name-config deployment/monitoring-stack-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable de...
List deployments in YAML output format, in the "custom-version" version of the "api-v2" API group
Command: ```bash kubectl get deployments.custom-version.api-v2 -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 ...
Update the image of all containers in the 'test' DaemonSet to 'centos:8.4.2105'
Command: ```bash kubectl set image daemonset test *=centos:8.4.2105 ``` 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: `kub...
List the replication controller named "web", the service named "frontend-rc", and the pod named "vpn-service-pod".
Command: ```bash kubectl get rc/web service/frontend-rc pods/vpn-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 namespace...
Set the service account of the deployment named `proxy-service-deployment` to `tekton`
Command: ```bash kubectl set serviceaccount deployment proxy-service-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: `kubec...
update the image of all containers in the daemonset named 'prod' to 'httpd:2.4.48'
Command: ```bash kubectl set image daemonset prod *=httpd:2.4.48 ``` 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: `kubect...
Create an ingress called 'app-gateway-ingress' with a rule that directs requests to foo.com/bar to the service svc1:5432
Command: ```bash kubectl create ingress app-gateway-ingress --rule="foo.com/bar=svc1:5432,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usag...
Import the CONFIG_FILE_PATH key from the app-config-dev ConfigMap into the backend-microservice-deployment deployment.
Command: ```bash kubectl set env --keys=CONFIG_FILE_PATH --from=configmap/app-config-dev 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 va...
Import only the 'redis_host' key from the 'monitoring-config' ConfigMap to the 'load-balancer-deployment' Deployment.
Command: ```bash kubectl set env --keys=redis_host --from=configmap/monitoring-config 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 def...
Delete a pod specified in the setup.json file
Command: ```bash kubectl delete -f ./setup.json ``` What it does: Delete resources by file names, stdin, resources and names, or by resources and label selector. JSON and YAML formats are accepted. Only one type of argument may be specified: file names, resources and names, or resources and label selector. Some resour...
Forward port 8081 on all addresses to port 5432 in the 'mypod' pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/mypod 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 sel...
Partially update a node by applying a strategic merge patch in YAML format
Command: ```bash kubectl patch node k8s-node-1 -p $'spec:\n containers:\n- name: container-name\n resources:\n limits:\n 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 (-f FI...
Create a new ExternalName service named 'external-messaging-service' with the external name 'example-domain.com'
Command: ```bash kubectl create service externalname external-messaging-service --external-name example-domain.com ``` What it does: Create an ExternalName service with the specified name. ExternalName service references to an external DNS address instead of only pods, which will allow application authors to reference...
Forward local port 8888 to port 8080 in a pod selected by the deployment
Command: ```bash kubectl port-forward deployment/mydeployment 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, a pod will be selecte...
Create a new config map named 'ui-config' with the specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap ui-config --from-file=settings=/path/to/settings/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 ...
Copy the file /var/run/secrets/kubernetes.io/serviceaccount/ from your local machine to the directory /tmp/bar in the remote pod named "backend-pod-13" in the "prometheus" namespace.
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ prometheus/backend-pod-13:/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": "Contai...
Update the environment variable 'SMTP_USERNAME' in the deployment 'load-balancer-deployment'.
Command: ```bash kubectl set env deployment/load-balancer-deployment SMTP_USERNAME=your-username ``` 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 p...
Add a taint with the key 'hardware' and the value 'worker-node-3:PreferNoSchedule' on all nodes labeled with 'customer=acme-corp'
Command: ```bash kubectl taint node -l customer=acme-corp 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": "", "us...
Add a taint to the 'web-node-8' node with key 'environment' and value 'production' and effect 'NoSchedule'
Command: ```bash kubectl taint nodes web-node-8 environment=production:NoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output for...
Add a taint on nodes labeled with zone=us-east-1 to indicate a preference for scheduling
Command: ```bash kubectl taint node -l zone=us-east-1 zone=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": "Ou...
Add the annotation "monitoring-tool=Prometheus" to the pod specified in "params.json"
Command: ```bash kubectl annotate -f params.json monitoring-tool=Prometheus ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels and include a...
Create an ingress called 'public-ingress' that directs requests to a specific URL path to a service, and configure TLS using a specific certificate
Command: ```bash kubectl create ingress public-ingress --rule="site.com/bar=svc1:3306,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": ...
Set the resource request and limits for all containers in the 'kafka' deployment
Command: ```bash kubectl set resources deployment kafka --limits=cpu=200m,memory=512Mi --requests=cpu=1,memory=64Mi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requested,...
Create an ingress called 'private-service-ingress' that directs requests to 'testing.com/bar' to 'svc1:8082' with a TLS secret named 'my-cert'.
Command: ```bash kubectl create ingress private-service-ingress --rule="testing.com/bar=svc1:8082,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": "...
Delete pods and services with names "monitoring" and "backend"
Command: ```bash kubectl delete pod,service monitoring backend ``` 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 select...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=external_api_url --from=configmap/db-config deployment/monitoring-stack-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable de...
List deployments in YAML format for the "v1.0.0" version of the "legacy-apps" API group.
Command: ```bash kubectl get deployments.v1.0.0.legacy-apps -o yaml ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you wil...
Auto scale the deployment "proxy" with a minimum of 7 pods and a maximum of 12 pods.
Command: ```bash kubectl autoscale deployment proxy --min=7 --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 uses t...
Create a service for a replication controller by providing the YAML file and setting the ports correctly.
Command: ```bash kubectl expose -f ruby-controller.yaml --port=3001 --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 s...
Switch to raw terminal mode on the security-service-pod container called lunar-launcher and interact with the shell
Command: ```bash kubectl attach security-service-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...
Add a taint with the key 'app' on nodes having the label role=database
Command: ```bash kubectl taint node -l role=database app=db-node-7:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output ...
List pod details from a YAML file in YAML format.
Command: ```bash kubectl get -f pod.yaml -o yaml ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you will only see results ...
Update the image of all containers in the daemonset "namespace-2" to "php:7.4.22"
Command: ```bash kubectl set image daemonset namespace-2 *=php:7.4.22 ``` 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: `k...
Forward local port 8088 to port 8000 in a pod selected by the deployment "mydeployment"
Command: ```bash kubectl port-forward deployment/mydeployment 8088 8000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selecte...
Update the 'proxy-server' pod with the annotation 'SLA' and the value '99.9% uptime'
Command: ```bash kubectl annotate pods proxy-server 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 arbitr...
Delete pods and services with the names "web" and "email"
Command: ```bash kubectl delete pod,service web email ``` What it does: Delete resources by file names, stdin, resources and names, or by resources and label selector. JSON and YAML formats are accepted. Only one type of argument may be specified: file names, resources and names, or resources and label selector. Some ...
Remove the taint with key 'cpu-type' and effect 'NoSchedule' from the 'db-node-7' node, if it exists.
Command: ```bash kubectl taint nodes db-node-7 cpu-type:NoSchedule- ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: j...
Forward traffic from local port 8081 to port 5000 in the pod named "chat-app-pod"
Command: ```bash kubectl port-forward pod/chat-app-pod 8081:5000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected autom...
Create a single ingress called 'public-ingress' that directs requests to website.com/example to svc # svc1:8000 with a tls secret "my-cert"
Command: ```bash kubectl create ingress public-ingress --rule="website.com/example=svc1:8000,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...
Open the email-service service for editing using the nvim editor.
Command: ```bash KUBE_EDITOR="nvim" kubectl edit svc/email-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, ...
Set the current context to use the on-prem-cluster cluster.
Command: ```bash kubectl config use-context on-prem-cluster ``` What it does: Set the current-context in a kubeconfig file. Syntax: `kubectl config use-context CONTEXT_NAME`
Taint nodes with label "customer=acme-corp" by adding a taint with key "special" and value "app-node-6:PreferNoSchedule"
Command: ```bash kubectl taint node -l customer=acme-corp special=app-node-6:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage"...
Create a deployment named "scheduler" with the image "jenkins"
Command: ```bash kubectl create deployment scheduler --image=jenkins ``` What it does: Create a deployment with the specified name. Syntax: `kubectl create deployment NAME --image=image -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: json|yaml...
Create a new config map named 'monitoring-config' with the keys 'properties' and 'key1'
Command: ```bash kubectl create configmap monitoring-config --from-file=properties=/path/to/options/file1.txt --from-file=key1=/path/to/properties/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When cr...
Execute the command 'yum install -y aws-cli' inside the first pod of the deployment 'proxy-service-deployment', using the default container.
Command: ```bash kubectl exec deploy/proxy-service-deployment -- yum install -y aws-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...
Create a new config map with the name 'api-config' using the files 'file1.txt' and 'file2.txt' from the specified paths
Command: ```bash kubectl create configmap api-config --from-file=settings=/path/to/parameters/file1.txt --from-file=key2=/path/to/configurations/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When crea...
Set the service account of the 'user-management-deployment' deployment to 'tekton'
Command: ```bash kubectl set serviceaccount deployment user-management-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: `kub...
Listen on port 8088 locally and forward data to/from port 8000 in the pod 'proxy-server-pod'.
Command: ```bash kubectl port-forward pod/proxy-server-pod 8088 8000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected a...
Create an ingress called 'website-ingress' that directs requests to 'site.com/example' to the service 'svc1' on port '9090', using the TLS secret named 'my-cert'.
Command: ```bash kubectl create ingress website-ingress --rule="site.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": "", "usa...
Execute the 'mysql --version' command in the 'frontend-pod' pod and display the output.
Command: ```bash kubectl exec frontend-pod -- mysql --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 kube...
Start a golang pod with custom configuration by using overrides in a JSON format.
Command: ```bash kubectl run nginx --image=golang --overrides='{ "apiVersion": "v2.0.0", "spec": { ... } }' ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAN...
Listen on port 8088 of your local machine, forwarding requests to port 6379 inside the 'chat-app-pod' pod.
Command: ```bash kubectl port-forward pod/chat-app-pod 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 will be selected autom...
Return the snapshot logs from the log-aggregator-pod, including all containers
Command: ```bash kubectl logs log-aggregator-pod --all-containers=true ``` 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...
Forward local ports 5432 and 6000 to ports 6379 and 6000 in a selected pod from the deployment named "analytics-platform-deployment"
Command: ```bash kubectl port-forward deployment/analytics-platform-deployment 5432 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 po...
Forward port 8081 on localhost and IP 10.19.21.23 to port 6379 in the pod named "api-service-pod"
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/api-service-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 cri...
List the replication controller named 'web', the service named 'e-commerce-rc', and the pod named 'payment-gateway-pod'
Command: ```bash kubectl get rc/web service/e-commerce-rc pods/payment-gateway-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 nam...
List the deployments in the "v1.1.1" version of the "alpha-apps" API group in YAML format
Command: ```bash kubectl get deployments.v1.1.1.alpha-apps -o yaml ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you will...
Update the 'log-aggregator' pod by adding or updating the annotation 'team' with the value 'frontend-team', and overwrite any existing value.
Command: ```bash kubectl annotate --overwrite pods log-aggregator team='frontend-team' ``` 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 an...
Create a job named "certificate-renewal" with the image "php" and run the command "php --version" inside the job
Command: ```bash kubectl create job certificate-renewal --image=php -- php --version ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output f...
Create a new config map named 'env-vars' with the specified keys (settings and key2) and their corresponding values from the specified files (/path/to/configs/file1.txt and /path/to/preferences/file2.txt)
Command: ```bash kubectl create configmap env-vars --from-file=settings=/path/to/configs/file1.txt --from-file=key2=/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...
Update the deployment 'scheduler-app-deployment' with a new environment variable DEBUG=true
Command: ```bash kubectl set env deployment/scheduler-app-deployment DEBUG=true ``` 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 templates (wit...
List the name and image of the first container in the analytics-pod
Command: ```bash kubectl get pod analytics-pod -o custom-columns=CONTAINER:.spec.containers[0].name,IMAGE:.spec.containers[0].image ``` 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 --s...
Create an ingress named 'api-ingress' with a rule that directs requests to 'site.com/bar' to 'svc1:8088'
Command: ```bash kubectl create ingress api-ingress --rule="site.com/bar=svc1:8088,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": "Ou...
Get the output from running the 'redis-server' command in the first container of the first pod of the deployment 'authentication-service-deployment'.
Command: ```bash kubectl exec deploy/authentication-service-deployment -- redis-server ``` 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....
Set up autoscaling for the deployment "monitoring" with a minimum of 3 pods and a maximum of 13 pods.
Command: ```bash kubectl autoscale deployment monitoring --min=3 --max=13 ``` 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 u...
Forward local port 8000 to port 8081 on the pod named 'api-service-pod'
Command: ```bash kubectl port-forward pod/api-service-pod 8000 8081 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected au...
List deployments in the "v1.1.1" version of the "api-v2" API group in YAML output format
Command: ```bash kubectl get deployments.v1.1.1.api-v2 -o yaml ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you will onl...
Forward local port 5000 to port 8888 in the 'frontend-pod' pod
Command: ```bash kubectl port-forward pod/frontend-pod 5000:8888 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected autom...
Forward local port 6379 to port 8088 in the pod selected by the web-app-deployment deployment
Command: ```bash kubectl port-forward deployment/web-app-deployment 6379 8088 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be s...