prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Set the CPU and memory limits for the Elasticsearch container in a deployment to 500m and 128Mi, respectively.
Command: ```bash kubectl set resources deployment elasticsearch -c=nginx --limits=cpu=500m,memory=128Mi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requested, but may bur...
Remove exec auth plugin environment variables for the "john.doe" entry
Command: ```bash kubectl config set-credentials john.doe --exec-env=var-to-remove- ``` What it does: Set a user entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values. Client-certificate flags: --client-certificate=certfile --client-key=keyfile Bearer token flags: ...
Copy service account file to remote pod container
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ metrics-exporter-pod-10:/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"...
Create the ingress 'internal-ingress' with a rule that maps requests from foo.com/module to svc1:8888
Command: ```bash kubectl create ingress internal-ingress --rule="foo.com/module=svc1:8888,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...
Update the 'gateway-deployment' deployment by adding a new environment variable DEBUG=true.
Command: ```bash kubectl set env deployment/gateway-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 (within re...
Create a service for the replicated python using the replica set, which serves on port 3306 and connects to the containers on port 8000
Command: ```bash kubectl expose rs python --port=3306 --target-port=8000 ``` 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...
Forward local port 8888 to port 8081 in the pod named "proxy-server-pod"
Command: ```bash kubectl port-forward pod/proxy-server-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 will be selected a...
List the specified resources by their type and names.
Command: ```bash kubectl get rc/web service/auth-service-rc pods/analytics-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 namespa...
Forward all traffic received on port 3000 to port 8080 inside the pod named `cdn-service-pod`, listening on all available IP addresses.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/cdn-service-pod 3000:8080 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod w...
Remove the label 'component' from the 'backend' pod
Command: ```bash kubectl label pods backend component- ``` 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...
Start a hazelcast pod named nginx with the hazelcast/hazelcast image, but override the spec with a set of values parsed from JSON.
Command: ```bash kubectl run nginx --image=hazelcast/hazelcast --overrides='{ "apiVersion": "v2.1.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] [--comman...
Update the 'email' pod by adding or modifying the 'alert-email' annotation with the value 'alerts@example.com'
Command: ```bash kubectl annotate pods email alert-email=alerts@example.com ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels and include a...
Execute the 'go run hello.go' command in the time-machine container of the security-service-pod and get the output.
Command: ```bash kubectl exec security-service-pod -c time-machine -- go run hello.go ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. ...
Update the 'log-aggregator' pod by adding or updating the annotation 'custom-label' with the value 'my-custom-value'
Command: ```bash kubectl annotate --overwrite pods log-aggregator custom-label='my-custom-value' ``` 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...
Add a label 'unhealthy=true' to the pod 'chat-app'
Command: ```bash kubectl label pods chat-app unhealthy=true ``` 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"...
Execute the 'mongo' command in the 'cdn-service-pod' pod, using the 'rocket-ranger' container.
Command: ```bash kubectl exec cdn-service-pod -c rocket-ranger -- mongo ``` 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, us...
Get output from the 'astro-container' in the 'proxy-service-pod' pod
Command: ```bash kubectl attach proxy-service-pod -c astro-container ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omi...
Taint nodes with the key 'datacenter' for the label 'app=web-app' with the value 'kube-master-9:PreferNoSchedule'
Command: ```bash kubectl taint node -l app=web-app datacenter=kube-master-9:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage":...
Create a new config map named kube-system-config from the key=value pairs in the file located at path/to/properties.
Command: ```bash kubectl create configmap kube-system-config --from-file=path/to/properties ``` 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 ...
Forward port 6379 from all addresses to port 8088 in the analytics-pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/analytics-pod 6379:8088 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod wil...
Copy the '/tmp/foo' file from the local machine to the '/tmp/bar' path inside the 'worker-pod-4' pod in the 'ingress-nginx' namespace
Command: ```bash kubectl cp :/tmp/foo ingress-nginx/worker-pod-4::/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...
Delete the pods and services with the names "cdn" and "backend"
Command: ```bash kubectl delete pod,service cdn 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 selector. Som...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=secret_key --from=configmap/kube-system-config 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 ...
Create a new secret named jwt-secret from an env file
Command: ```bash kubectl create secret generic jwt-secret --from-env-file=path/to/properties.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 basenam...
Retrieve the logs from container auth-service-pod-1 in deployment gateway-deployment.
Command: ```bash kubectl logs deployment/gateway-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: "flag"...
Forward local port 8888 to port 8080 in the pod "e-commerce-pod" in all addresses.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/e-commerce-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 criteria, a pod wi...
Update the image of all containers in the daemonset named 'nginx' to 'amazonlinux:2'
Command: ```bash kubectl set image daemonset nginx *=amazonlinux:2 ``` 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: `kube...
Run the 'go' command inside the first container of the 'frontend-deployment' deployment.
Command: ```bash kubectl exec deploy/frontend-deployment -- go ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kub...
Update the annotation 'expiration-date' for pod 'chat-app' with the value '2024-12-31', overwriting any existing value
Command: ```bash kubectl annotate --overwrite pods chat-app expiration-date='2024-12-31' ``` 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 ...
Forward traffic from port 3000 on all addresses to port 5432 in the pod named "mypod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/mypod 3000: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...
Update the label of the 'api' pod with the key 'tier' and the value 'backend'
Command: ```bash kubectl label pods api tier=backend ``` 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 t...
Get a list of deployments in the "rc-1.1.0" version of the "alpha-apps" API group and output the result in YAML format.
Command: ```bash kubectl get deployments.rc-1.1.0.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 wi...
List resources by type and names
Command: ```bash kubectl get rc/web service/monitoring-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...
Set a custom TLS server name for the cluster entry named "sun-cluster" to "galaxy-cluster".
Command: ```bash kubectl config set-cluster sun-cluster --tls-server-name=galaxy-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...
partially update a node configuration using a YAML-based strategic merge patch
Command: ```bash kubectl patch node db-node-7 -p $'spec:\n rules:\n- http:\n paths:\n - path: /\n backend:\n service:\n 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. Synt...
Update the SMTP_PASSWORD environment variable of the order-processing-deployment deployment with the value "your-password" and display the modified deployment in YAML format
Command: ```bash kubectl set env deployment/order-processing-deployment SMTP_PASSWORD=your-password -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 on...
Retrieve the snapshot logs from container "api-service-pod-1" of the deployment "authentication-service-deployment".
Command: ```bash kubectl logs deployment/authentication-service-deployment -c api-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...
Create a cron job named "alerts-cleanup" that runs a kafka-console-producer command every minute
Command: ```bash kubectl create cronjob alerts-cleanup --image=confluentinc/cp-kafka --schedule="*/1 * * * *" -- kafka-console-producer --broker-list localhost:9092 --topic test ``` What it does: Create a cron job with the specified name. Syntax: `kubectl create cronjob NAME --image=image --schedule='0/5 * * * ?' -- ...
Get the output from running the 'ash' command in lunar-launcher from the pod named backend-pod
Command: ```bash kubectl exec backend-pod -c lunar-launcher -- 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 the...
Drain the node "node-1" even if there are pods not managed by a replication controller, replica set, job, daemon set, or stateful set on it.
Command: ```bash kubectl drain node-1 --force ``` What it does: Drain node in preparation for maintenance. The given node will be marked unschedulable to prevent new pods from arriving. 'drain' evicts the pods if the API server supports https://kubernetes.io/docs/concepts/workloads/pods/disruptions/ . Otherwise, it wi...
Expose the alpine deployment as a service on port 8088, connecting to containers on port 844300.
Command: ```bash kubectl expose deployment alpine --port=8088 --target-port=844300 ``` 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...
Set the custom TLS server name to "on-prem-cluster" for the "testing-cluster" cluster entry in the kubeconfig file
Command: ```bash kubectl config set-cluster testing-cluster --tls-server-name=on-prem-cluster ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certi...
List the replication controller 'web', the service 'backend-rc', and the pod 'gateway-pod'
Command: ```bash kubectl get rc/web service/backend-rc pods/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 namespaced you...
Import the environment variables from the 'monitoring-credentials-secret' secret into the 'log-aggregator-deployment' deployment.
Command: ```bash kubectl set env --from=secret/monitoring-credentials-secret deployment/log-aggregator-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 config map named app-settings, using the properties file at /path/to/configs/file1.txt and the key1 file at /path/to/settings/file2.txt as the values for the specified keys.
Command: ```bash kubectl create configmap app-settings --from-file=properties=/path/to/configs/file1.txt --from-file=key1=/path/to/settings/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating ...
Forward port 8080 on all addresses to port 8088 in the pod "chat-app-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/chat-app-pod 8080:8088 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will...
Forward port 8081 on all addresses to port 3000 in the pod named "log-aggregator-pod", using the command "kubectl port-forward" with the parameters "--address 0.0.0.0 pod/log-aggregator-pod 8081:3000".
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/log-aggregator-pod 8081: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 po...
List deployments in JSON output format for the "hotfix-1.1.2" version of the "sandbox-apps" API group
Command: ```bash kubectl get deployments.hotfix-1.1.2.sandbox-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 ...
Forward local port 9090 to pod port 9090 in the cdn-service-pod
Command: ```bash kubectl port-forward 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 will be selected au...
Edit the frontend-service using the notepad editor
Command: ```bash KUBE_EDITOR="notepad" kubectl edit svc/frontend-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 varia...
Create an ingress called 'external-ingress' with a rule that directs requests to 'website.com/bar' to 'svc1:3001', and use the 'my-cert' TLS secret
Command: ```bash kubectl create ingress external-ingress --rule="website.com/bar=svc1:3001,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usa...
execute the 'bash' command inside the log-aggregator-pod and display the output using the first container
Command: ```bash kubectl exec log-aggregator-pod -- bash ``` 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.k...
Execute the 'kafka-console-producer' command in the 'cyber-sleuth' container of the 'cdn-service-pod', providing the necessary parameters to connect to the Kafka broker and specify the topic.
Command: ```bash kubectl exec cdn-service-pod -c cyber-sleuth -- 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...
Import the 'log_level' key from the 'app-config-dev' config map into the 'cache-cluster-deployment' deployment.
Command: ```bash kubectl set env --keys=log_level --from=configmap/app-config-dev deployment/cache-cluster-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definit...
Display the client and server versions for the current context
Command: ```bash kubectl version ``` What it does: Print the client and server version information for the current context. Syntax: `kubectl version` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "One of 'yaml' or 'json'. "
Delete the pods and services named "security" and "media-stream"
Command: ```bash kubectl delete pod,service security media-stream ``` 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 sel...
Forward traffic from port 8080 on all addresses to port 8888 in the pod named "e-commerce-pod".
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/e-commerce-pod 8080: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 wi...
Add a taint with key 'special' on nodes having label owner=john-doe
Command: ```bash kubectl taint node -l owner=john-doe special=kube-master-9:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage":...
Execute the 'node' command in the vpn-service-pod and display the output.
Command: ```bash kubectl exec vpn-service-pod -- node ``` 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.kube...
Create a service for a replicated nginx using replica set, which serves on port 80 and connects to the containers on port 8000.
Command: ```bash kubectl expose rs nginx --port=8080 --target-port=500000 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port. ...
Apply a taint with key 'datacenter' and value 'worker-node-3:PreferNoSchedule' to nodes that have the label 'feature=feature-xyz'
Command: ```bash kubectl taint node -l feature=feature-xyz datacenter=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": "", ...
Import specific keys from a config map into a deployment
Command: ```bash kubectl set env --keys=debug_mode --from=configmap/kube-system-config deployment/gateway-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definiti...
Set the environment variables REDIS_HOST from the app-config config map for the backend-microservice-deployment deployment.
Command: ```bash kubectl set env --keys=REDIS_HOST --from=configmap/app-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 def...
Forward local port 6379 to port 8000 of a pod selected by the mydeployment deployment
Command: ```bash kubectl port-forward deployment/mydeployment 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 the criteria, a pod will be selecte...
Create an ingress called 'api-v2-ingress' with a rule that directs requests from "testing.com/module" to the service "svc1" on port 9092 using the TLS secret "my-cert"
Command: ```bash kubectl create ingress api-v2-ingress --rule="testing.com/module=svc1:9092,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "us...
Execute the command 'apk add curl' in the first pod of the 'database-service' service.
Command: ```bash kubectl exec svc/database-service -- apk add curl ``` 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...
Create a job named "report-generation-job" using the Alpine image, and run the command "ash" inside the job.
Command: ```bash kubectl create job report-generation-job --image=alpine -- ash ``` 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...
Set the CPU limit to "1" and memory limit to "128Mi" for the nginx container in the runtime deployment.
Command: ```bash kubectl set resources deployment runtime -c=nginx --limits=cpu=1,memory=128Mi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requested, but may burst up to ...
Create a single ingress called 'internal-ingress' with the rule "site.com/bar" directed to "svc1:5000" and using the TLS secret "my-cert"
Command: ```bash kubectl create ingress internal-ingress --rule="site.com/bar=svc1:5000,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage"...
Add a taint with the key 'disktype' on nodes having the label instance=app-instance-1.
Command: ```bash kubectl taint node -l instance=app-instance-1 disktype=k8s-node-1:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "...
Start a nginx pod with the image "nginx", but use a partial set of values from a JSON file to override the spec.
Command: ```bash kubectl run nginx --image=nginx --overrides='{ "apiVersion": "v1.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] -- [COMMAND...
Create a new config map named db-config using the data from the environment file located at path/to/data.env.
Command: ```bash kubectl create configmap db-config --from-env-file=path/to/data.env ``` 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 basenam...
create a job named "report-generation-job" using the Ruby image and execute the command "irb" within the job
Command: ```bash kubectl create job report-generation-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. ...
Embed the certificate authority data for the "moon-cluster" cluster entry
Command: ```bash kubectl config set-cluster moon-cluster --embed-certs --certificate-authority=~/.kube/star-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 set...
Add a taint on nodes with the label "tier=frontend" with the key "hardware" and the value "monitoring-node-15" and set its effect to "PreferNoSchedule".
Command: ```bash kubectl taint node -l tier=frontend hardware=monitoring-node-15:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "us...
Create a deployment named "ingress" using the "mysql" image and exposing port 5001.
Command: ```bash kubectl create deployment ingress --image=mysql --port=5001 ``` 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 resource request and limits for all containers in the 'wordpress' deployment to 100m CPU, 2Gi memory for requests and 200m CPU, 512Mi memory for limits.
Command: ```bash kubectl set resources deployment wordpress --limits=cpu=200m,memory=512Mi --requests=cpu=100m,memory=2Gi ``` 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 requ...
Create a single ingress resource called 'public-ingress' with a rule that directs requests from 'site.com/input' to the service 'svc1' on port '8080'
Command: ```bash kubectl create ingress public-ingress --rule="site.com/input=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": "", "usage"...
Get the version of the 'pg_dump' command from the 'proxy-server-pod' pod.
Command: ```bash kubectl exec proxy-server-pod -- pg_dump --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 th...
Set the environment variables from your local shell into a deployment config on the server
Command: ```bash env | grep RAILS_ | kubectl set env -e - deployment/email-server-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more pod t...
set the environment variables "debug_mode" from the "app-config" config map in the "load-balancer-deployment" deployment.
Command: ```bash kubectl set env --keys=debug_mode --from=configmap/app-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 definition...
Output the modified deployment in YAML format without making any changes to the object on the server
Command: ```bash kubectl set env deployment/authentication-service-deployment DB_HOST=localhost -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...
Create a new ClusterIP service named security-service-clusterip
Command: ```bash kubectl create service clusterip security-service-clusterip --tcp=9090:3306 ``` 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...
Open the authentication-service service for editing using the Emacs editor.
Command: ```bash KUBE_EDITOR="emacs" kubectl edit svc/authentication-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 v...
Update the 'media-stream' pod with the annotation 'criticality' set to 'high', replacing any existing value
Command: ```bash kubectl annotate --overwrite pods media-stream 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 in...
Create an ingress resource called 'internal-ingress' that routes requests for site.com/example to svc1:8083 with a TLS secret named "my-cert"
Command: ```bash kubectl create ingress internal-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": "", "us...
Listen on port 3000 locally and forward the traffic to port 9090 in the specified pod.
Command: ```bash kubectl port-forward pod/mypod 3000: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 automaticall...
Create a cron job named "system-health-check" that runs the command "pg_dump --version" every minute.
Command: ```bash kubectl create cronjob system-health-check --image=postgres --schedule="*/1 * * * *" -- pg_dump --version ``` What it does: Create a cron job with the specified name. Syntax: `kubectl create cronjob NAME --image=image --schedule='0/5 * * * ?' -- [COMMAND] [args...]` Helpful flags: "flag": "--output"...
Get information about the specified resources by their types and names
Command: ```bash kubectl get rc/web service/email-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 nam...
Import specified keys from a config map and set them as environment variables for a deployment
Command: ```bash kubectl set env --keys=CONFIG_FILE_PATH --from=configmap/db-config deployment/order-processing-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...
Get the output from the 'redis-server --version' command of the first container in the first pod of the 'email-server-deployment' deployment
Command: ```bash kubectl exec deploy/email-server-deployment -- redis-server --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....
List the ReplicaSets with the name "web", the Services with the name "proxy-server-rc", and the Pods with the name "api-service-pod".
Command: ```bash kubectl get rc/web service/proxy-server-rc pods/api-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 names...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=smtp_server --from=configmap/app-secrets 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 d...
Update the annotation 'alert-email' of the pod 'analytics' with the value 'alerts@example.com'
Command: ```bash kubectl annotate pods analytics alert-email=alerts@example.com ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels and inclu...
Set the service account of the 'web-app-deployment' deployment to 'tiller'
Command: ```bash kubectl set serviceaccount deployment web-app-deployment tiller ``` 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 a custom TLS server name for validation for the "kube-cluster-1" cluster entry.
Command: ```bash kubectl config set-cluster kube-cluster-1 --tls-server-name=galaxy-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] [--certifi...
Retrieve the output from running the 'mysqld' command in the first container of the 'mypod' pod.
Command: ```bash kubectl exec mypod -- mysqld ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubectl.kubernetes.i...
Add a taint with the key 'datacenter' to nodes that have the label 'myLabel' with the value 'edge-node-10', and set the effect to 'PreferNoSchedule'
Command: ```bash kubectl taint node -l myLabel datacenter=edge-node-10:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Out...
Import specific keys from a config map into a deployment's environment variables
Command: ```bash kubectl set env --keys=debug_mode --from=configmap/api-config deployment/log-aggregator-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 deployment named drupal using the ubuntu image and expose port 8000.
Command: ```bash kubectl create deployment drupal --image=ubuntu --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. One of: j...