prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Execute the 'python' command in the first container of the first pod of the 'order-service' service and capture the output.
Command: ```bash kubectl exec svc/order-service -- python ``` 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....
Forward local port 8080 to port 8000 in the 'chat-app-pod' pod
Command: ```bash kubectl port-forward pod/chat-app-pod 8080: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 autom...
create a job named 'audit-job' using the 'jenkins' image, running the command 'java -jar /usr/share/jenkins/jenkins.war'
Command: ```bash kubectl create job audit-job --image=jenkins -- java -jar /usr/share/jenkins/jenkins.war ``` 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": "...
Add a taint with key 'dedicated' on nodes having label customer=acme-corp
Command: ```bash kubectl taint node -l customer=acme-corp dedicated=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": "", ...
Copy the local file /tmp/foo_dir to the remote pod argocd/security-scanner-pod-18 in the namespace, and place it at /tmp/bar.
Command: ```bash kubectl cp /tmp/foo_dir argocd/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, use th...
Create a pod disruption budget named worker-pdb that selects pods with the region=us-east label and enforces a minimum availability of four pods at all times.
Command: ```bash kubectl create poddisruptionbudget worker-pdb --selector=region=us-east --min-available=4 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-available=N [--d...
Forward traffic from port 8081 on both localhost and IP address 10.19.21.23 to port 9090 in the analytics-pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/analytics-pod 8081:9090 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the crite...
Import the max_connections key from the global-config config map and set it as an environment variable in the authentication-service-deployment deployment.
Command: ```bash kubectl set env --keys=max_connections --from=configmap/global-config deployment/authentication-service-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment va...
Partially update the 'db-node-7' node by applying a strategic merge patch specified in JSON format
Command: ```bash kubectl patch node db-node-7 -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. Syntax: `kubectl pat...
Set the resource request and limits for all containers in the centos deployment to 200m CPU and 512Mi memory for limits, and 200m CPU and 256Mi memory for requests
Command: ```bash kubectl set resources deployment centos --limits=cpu=200m,memory=512Mi --requests=cpu=200m,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 reque...
Start a pod named "hazelcast" using the Wordpress image and expose port 8089
Command: ```bash kubectl run hazelcast --image=wordpress --port=8089 ``` 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 new config map named app-config using the files file1.txt and file2.txt as values for the keys "conf" and "data" respectively
Command: ```bash kubectl create configmap app-config --from-file=conf=/path/to/profiles/file1.txt --from-file=data=/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 creating a config...
Create a new secret named 'my-secret' using the files in the 'path/to/settings' folder.
Command: ```bash kubectl create secret generic my-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 the fi...
Create an autoscaler for the replication controller "database" with a maximum of 6 pods and a target CPU utilization of 60%.
Command: ```bash kubectl autoscale rc database --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 use...
Copy the '/tmp/foo_dir' directory from the 'kube-dns/load-balancer-pod-9' pod to the '/tmp/bar' directory locally.
Command: ```bash kubectl cp kube-dns/load-balancer-pod-9:/tmp/foo_dir :/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 ...
Forward traffic from port 6379 on all addresses to port 6379 in the frontend-pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/frontend-pod 6379: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...
Create a pod disruption budget named 'replica-set-pdb' that will select all pods with the 'tier=frontend' label and require at least four of them being available at any point in time
Command: ```bash kubectl create poddisruptionbudget replica-set-pdb --selector=tier=frontend --min-available=4 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-available=N ...
Update the 'chat-app' pod with the annotation 'app-version' set to 2.5.1
Command: ```bash kubectl annotate pods chat-app app-version=2.5.1 ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels and include arbitrary s...
Retrieve the details of the replication controller 'web', service 'proxy-service-rc', and pod 'chat-app-pod'.
Command: ```bash kubectl get rc/web service/proxy-service-rc pods/chat-app-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...
Create an ingress called 'api-v2-ingress' with the following rules:
Command: ```bash kubectl create ingress api-v2-ingress --rule="testing.com/example=svc1:8084,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 named "load-balancer-deployment" to "kube-scheduler"
Command: ```bash kubectl set serviceaccount deployment load-balancer-deployment kube-scheduler ``` 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...
Execute the command 'elasticsearch' in the container 'mycontainer' of the pod 'e-commerce-pod' and retrieve the output.
Command: ```bash kubectl exec e-commerce-pod -c mycontainer -- 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. If omitte...
Create a service for the replicated python application, which serves on port 8083 and connects to the containers on port 300100
Command: ```bash kubectl expose rc python --port=8083 --target-port=300100 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port....
Create a single ingress called 'api-v2-ingress' that directs requests to website.com/example to svc1:5432 with a tls secret "my-cert"
Command: ```bash kubectl create ingress api-v2-ingress --rule="website.com/example=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": "", "u...
Create a pod disruption budget named worker-pdb that selects pods with the app=rails label and requires at least one of them to be available at all times.
Command: ```bash kubectl create poddisruptionbudget worker-pdb --selector=app=rails --min-available=1 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-available=N [--dry-ru...
Copy the file "~/.config/kube" from the remote pod "argocd/message-broker-pod-15" to the local directory "/tmp/bar_dir"
Command: ```bash kubectl cp argocd/message-broker-pod-15:~/.config/kube /tmp/bar_dir ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use...
Forward port 8088 on all addresses to port 8081 in the pod named "log-aggregator-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/log-aggregator-pod 8088: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 po...
Set up autoscaling for the deployment named "frontend"
Command: ```bash kubectl autoscale deployment frontend --min=1 --max=11 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that use...
Create a pod named 'hazelcast' using the 'mongo' image and expose port 8080
Command: ```bash kubectl run hazelcast --image=mongo --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": "--fi...
Create a secret named private-key-secret and use the files in the specified path to generate keys for each file
Command: ```bash kubectl create secret generic private-key-secret --from-file=path/to/profiles ``` 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 ...
Import the CONFIG_FILE_PATH key from the db-config config map and set it as an environment variable in the authentication-service-deployment deployment.
Command: ```bash kubectl set env --keys=CONFIG_FILE_PATH --from=configmap/db-config deployment/authentication-service-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment varia...
Update the 'cdn' pod by adding the annotation 'release-notes' with the value 'https://example.com/release-notes/v2.5.1'.
Command: ```bash kubectl annotate pods cdn release-notes='https://example.com/release-notes/v2.5.1' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger t...
Create a new LoadBalancer service named ingress-controller-lb that maps incoming traffic on port 9092 to port 3000
Command: ```bash kubectl create service loadbalancer ingress-controller-lb --tcp=9092:3000 ``` 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...
Forward traffic from port 9090 on your local machine to port 8080 in the specified pod.
Command: ```bash kubectl port-forward pod/proxy-server-pod 9090: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 selected a...
Import the 'database_url' key from the 'db-config' config map into the 'backend-microservice-deployment' deployment.
Command: ```bash kubectl set env --keys=database_url --from=configmap/db-config deployment/backend-microservice-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable de...
Retrieve the output of the 'pip --version' command from the time-machine container inside the security-service-pod.
Command: ```bash kubectl exec security-service-pod -c time-machine -- pip --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...
Add a taint with key 'dedicated' to nodes labeled with 'instance=app-instance-1'
Command: ```bash kubectl taint node -l instance=app-instance-1 dedicated=dev-node-4: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": "", ...
Embed the certificate authority data for the cluster-gamma cluster entry
Command: ```bash kubectl config set-cluster cluster-gamma --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 ...
Create a deployment named monitoring using the ethereum/client-go image, and expose port 9092.
Command: ```bash kubectl create deployment monitoring --image=ethereum/client-go --port=9092 ``` 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 f...
Attach to the monitoring-pod and get output from the nano-bot container.
Command: ```bash kubectl attach monitoring-pod -c nano-bot ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use ...
Forward port 5000 on all addresses to port 5432 in the pod named "e-commerce-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/e-commerce-pod 5000: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 wi...
Create a copy of the security-service-pod with all container images set to ubuntu
Command: ```bash kubectl debug security-service-pod --copy-to=debug-image-memcached --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 def...
Import the log_level key from the namespace-config config map and set it as an environment variable in the database-deployment deployment.
Command: ```bash kubectl set env --keys=log_level --from=configmap/namespace-config deployment/database-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...
Start streaming the logs of the 'astro-container' container in the 'vpn-service-pod' pod
Command: ```bash kubectl logs -f -c astro-container vpn-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...
Create a secret named 'payment-gateway-secret' from an environment file
Command: ```bash kubectl create secret generic payment-gateway-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 th...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=my-example-key --from=configmap/db-config deployment/backend-microservice-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable ...
Check if you have permission to list the "cleanup-job" job in the "kube-node-lease" namespace.
Command: ```bash kubectl auth can-i list jobs.batch/cleanup-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 partial UR...
Create a service for the 'ruby' replication controller, serving on port 5000, and connecting to the containers on port 8084.
Command: ```bash kubectl expose rc ruby --port=5000 --target-port=808400 ``` 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 traffic from port 6379 to port 8081 in the pod named 'cdn-service-pod'.
Command: ```bash kubectl port-forward pod/cdn-service-pod 6379 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...
Import specific keys from a config map into the environment variables of a deployment
Command: ```bash kubectl set env --keys=log_level --from=configmap/app-name-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 defin...
Retrieve a JSON representation of all deployments in the "v3.0.0" version of the "my-apps" API group
Command: ```bash kubectl get deployments.v3.0.0.my-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 will on...
Execute the 'wp' command on the first pod of the deployment 'proxy-service-deployment', using the first container.
Command: ```bash kubectl exec deploy/proxy-service-deployment -- wp ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use th...
Add or update a label on a pod named 'log-aggregator' to specify that it belongs to the 'production' environment.
Command: ```bash kubectl label pods log-aggregator env=production ``` 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", "...
List the replication controller named "analytics-rc" in the default output format
Command: ```bash kubectl get replicationcontroller analytics-rc ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you will on...
List all pods in wide output format with additional information such as the node name
Command: ```bash kubectl get pods -o wide ``` 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 in your...
Import the log_level key from the app-config config map and set it as an environment variable in the notification-handler-deployment deployment.
Command: ```bash kubectl set env --keys=log_level --from=configmap/app-config deployment/notification-handler-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defi...
Forward local port 8088 to port 5432 in the pod named web-app-pod
Command: ```bash kubectl port-forward pod/web-app-pod 8088:5432 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automa...
Execute the 'go run hello.go' command in the first pod of the 'proxy-service-deployment' deployment and retrieve the output.
Command: ```bash kubectl exec deploy/proxy-service-deployment -- go run hello.go ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If om...
Create a pod disruption budget that ensures at least one pod with the label "tier=frontend" is always available.
Command: ```bash kubectl create poddisruptionbudget replica-set-pdb --selector=tier=frontend --min-available=1 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-available=N ...
Execute the 'mongod' command in the quantum-quark container of the pod proxy-service-pod and retrieve the output.
Command: ```bash kubectl exec proxy-service-pod -c quantum-quark -- mongod ``` 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,...
Create a new secret named database-secret from the environment variables defined in the file located at path/to/settings.env.
Command: ```bash kubectl create secret generic database-secret --from-env-file=path/to/settings.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 base...
Scale the replication controller named "foo" automatically based on CPU utilization, allowing a maximum of 7 pods and targeting a CPU utilization of 20%.
Command: ```bash kubectl autoscale rc foo --max=7 --cpu-percent=20 ``` 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 the...
Create a new secret named my-secret by using the files in the path/to/preferences folder
Command: ```bash kubectl create secret generic my-secret --from-file=path/to/preferences ``` 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 the...
Add a taint with key "dedicated" on nodes having label "namespace=mynamespace" and value "dedicated=web-node-8:PreferNoSchedule"
Command: ```bash kubectl taint node -l namespace=mynamespace dedicated=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": "", "u...
replace the pod with the configuration provided in the 'parameters.yaml' file
Command: ```bash cat parameters.yaml | kubectl replace -f - ``` What it does: Replace a resource by file name or stdin. JSON and YAML formats are accepted. If replacing an existing resource, the complete resource spec must be provided. This can be obtained by $ kubectl get TYPE NAME -o yaml Syntax: `kubectl replace -...
Copy the service account file from a remote pod to a local directory.
Command: ```bash kubectl cp kube-system/database-pod-2:/var/run/secrets/kubernetes.io/serviceaccount/ /etc/kubernetes ``` 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":...
replace the pod with the settings provided in the settings.json file.
Command: ```bash cat settings.json | kubectl replace -f - ``` What it does: Replace a resource by file name or stdin. JSON and YAML formats are accepted. If replacing an existing resource, the complete resource spec must be provided. This can be obtained by $ kubectl get TYPE NAME -o yaml Syntax: `kubectl replace -f ...
Execute the 'mysql' command in the 'cyber-sleuth' container of the 'security-service-pod' pod and retrieve the output.
Command: ```bash kubectl exec security-service-pod -c cyber-sleuth -- mysql ``` 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...
Attach to 'mypod' and interact with 'mycontainer'
Command: ```bash kubectl attach mypod -c mycontainer ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the ku...
Copy the /tmp/foo_dir directory from the remote pod to the local /tmp/bar directory.
Command: ```bash kubectl cp kube-server/front-end-pod-12:/tmp/foo_dir :/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 ...
Add a taint with the key 'dedicated' on nodes that have the label feature=feature-xyz.
Command: ```bash kubectl taint node -l feature=feature-xyz dedicated=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": "", "usa...
Forward local port 9090 to port 8080 in a pod selected by the deployment named "monitoring-stack-deployment".
Command: ```bash kubectl port-forward deployment/monitoring-stack-deployment 9090 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 ...
Autoscale the deployment "web" with a range of 6 to 14 pods.
Command: ```bash kubectl autoscale deployment web --min=6 --max=14 ``` 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 the...
Forward local port 5000 to port 8000 in the backend pod
Command: ```bash kubectl port-forward pod/backend-pod 5000:8000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automa...
Update the service account for the 'api-server-deployment' deployment to 'istio'
Command: ```bash kubectl set serviceaccount deployment api-server-deployment istio ``` What it does: Update the service account of pod template resources. Possible resources (case insensitive) can be: replicationcontroller (rc), deployment (deploy), daemonset (ds), job, replicaset (rs), statefulset Syntax: `kubectl s...
Set the custom TLS server name to be used for validation for the 'cluster-beta' cluster entry
Command: ```bash kubectl config set-cluster cluster-beta --tls-server-name=web-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-...
Create a pod disruption budget named 'payment-gateway-pdb' that will select all pods with the label 'app=rails'
Command: ```bash kubectl create poddisruptionbudget payment-gateway-pdb --selector=app=rails --min-available=1 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-available=N ...
Print the result of updating the nginx container image to redis:6.2.5 in the local file specified at path/to/file.yaml, without hitting the server, in YAML format.
Command: ```bash kubectl set image -f path/to/file.yaml redis=redis:6.2.5 --local -o yaml ``` 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), replica...
Execute the command 'docker run -d ubuntu sleep 3600' inside the first pod of the 'load-balancer-deployment' deployment.
Command: ```bash kubectl exec deploy/load-balancer-deployment -- docker run -d ubuntu sleep 3600 ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Conta...
Replace a pod using the data specified in the setup.json file
Command: ```bash kubectl replace -f ./setup.json ``` What it does: Replace a resource by file name or stdin. JSON and YAML formats are accepted. If replacing an existing resource, the complete resource spec must be provided. This can be obtained by $ kubectl get TYPE NAME -o yaml Syntax: `kubectl replace -f FILENAME`...
Create a new ClusterIP service named frontend-service-clusterip with the port mapping TCP port 8081 on the service to port 8443 on the backend
Command: ```bash kubectl create service clusterip frontend-service-clusterip --tcp=8081:8443 ``` 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...
Embed the certificate authority data for the 'cloud-cluster' cluster entry by running the command 'kubectl config set-cluster cloud-cluster --embed-certs --certificate-authority=~/.kube/testing-cluster/kubernetes.ca.crt'
Command: ```bash kubectl config set-cluster cloud-cluster --embed-certs --certificate-authority=~/.kube/testing-cluster/kubernetes.ca.crt ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config...
Import the log_level key from the api-config config map and set it as an environment variable for the scheduler-app-deployment deployment.
Command: ```bash kubectl set env --keys=log_level --from=configmap/api-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 definitions...
Set the service account of a deployment named "analytics-platform-deployment" to "fluentd"
Command: ```bash kubectl set serviceaccount deployment analytics-platform-deployment fluentd ``` 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: ...
Create a new config map named 'app-secrets' using the specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap app-secrets --from-file=settings=/path/to/configurations/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 creati...
Run the command 'pip --version' in the rocket-ranger container of the pod proxy-server-pod and print the output.
Command: ```bash kubectl exec proxy-server-pod -c rocket-ranger -- pip --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 om...
Add a taint with key 'datacenter' on nodes having label project=project-alpha
Command: ```bash kubectl taint node -l project=project-alpha datacenter=testing-node-11:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": ...
Switch to the context for the 'cluster-gamma' cluster
Command: ```bash kubectl config use-context cluster-gamma ``` What it does: Set the current-context in a kubeconfig file. Syntax: `kubectl config use-context CONTEXT_NAME`
Forward local port 8000 to port 9090 in the frontend-pod
Command: ```bash kubectl port-forward pod/frontend-pod 8000:9090 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected autom...
update the environment variable 'LOG_LEVEL' for the deployment 'backend-microservice-deployment'
Command: ```bash kubectl set env deployment/backend-microservice-deployment LOG_LEVEL=info ``` 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...
Create an ingress resource called 'app-ingress' that routes requests for 'testing.com/input' to the service 'svc1' on port 3001
Command: ```bash kubectl create ingress app-ingress --rule="testing.com/input=svc1:3001,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage"...
Create a copy of the database-pod and add a debug container using the debian image
Command: ```bash kubectl debug database-pod -it --copy-to=my-debugger --image=debian --set-image=database=mysql:5.7,logger=logging-app:debug ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resourc...
Create a job with a specific command
Command: ```bash kubectl create job backup --image=php -- composer --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 format. O...
Create a new config map named db-config with the specified keys
Command: ```bash kubectl create configmap db-config --from-file=properties=/path/to/options/file1.txt --from-file=key1=/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 creati...
Add a taint with key 'app' on nodes having label app-type=microservice
Command: ```bash kubectl taint node -l app-type=microservice app=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":...
Update the annotation 'security-scan-status' of pod 'proxy' with the value 'pass'
Command: ```bash kubectl annotate --overwrite pods proxy security-scan-status='pass' ``` 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 ...
Edit the configuration of the 'scheduler-service' service.
Command: ```bash kubectl edit svc/scheduler-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 fall back to...
Create a service for the replication controller specified in the "nginx-controller.yaml" file
Command: ```bash kubectl expose -f nginx-controller.yaml --port=6379 --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 ...
Set the cluster field in the context to a specific cluster
Command: ```bash kubectl config set contexts.service-account-context.cluster kube-cluster-1 ``` 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 ...
List deployments in JSON output format, in the "custom-version" version of the "extensions" API group.
Command: ```bash kubectl get deployments.custom-version.extensions -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 ...