prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Remove the label 'bar' from the pod 'email' if it exists
Command: ```bash kubectl label pods email role- ``` What it does: Update the labels on a resource. Syntax: `kubectl label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]` Helpful flags: "flag": "--all-namespaces", "short": "-A", "default": "false", "usage": "If true, ...
Start streaming the logs of the 'nebula-navigator' container in the 'frontend-pod' pod
Command: ```bash kubectl logs -f -c nebula-navigator frontend-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",...
Start a pod named "nginx" using the "amazonlinux" image, but customize its specification by providing a partial set of values in JSON format.
Command: ```bash kubectl run nginx --image=amazonlinux --overrides='{ "apiVersion": "custom-version", "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...
Add a taint with key 'app' on nodes labeled as 'environment=production'
Command: ```bash kubectl taint node -l environment=production 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":...
Listen on port 8080 locally and forward it to port 5000 in the pod named 'log-aggregator-pod'
Command: ```bash kubectl port-forward pod/log-aggregator-pod 8080: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...
Set a custom TLS server name for the cluster-beta cluster entry.
Command: ```bash kubectl config set-cluster cluster-beta --tls-server-name=my-k8s-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] [--certifica...
Import specific keys from a config map for a deployment
Command: ```bash kubectl set env --keys=EXTERNAL_API_URL --from=configmap/app-name-config deployment/web-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 defin...
Specify resource request and limits for all containers in the wordpress deployment
Command: ```bash kubectl set resources deployment wordpress --limits=cpu=200m,memory=512Mi --requests=cpu=50m,memory=4Gi ``` 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...
Remove all the taints with key 'environment' from node 'worker-node-3'
Command: ```bash kubectl taint nodes worker-node-3 environment- ``` 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|...
Update the image of all containers in the 'development' daemonset to 'httpd:2.4.48'.
Command: ```bash kubectl set image daemonset development *=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: ...
Create a service for a replication controller specified in "ubuntu-controller.yaml", which serves on port 8084 and connects to the containers on port 909100.
Command: ```bash kubectl expose -f ubuntu-controller.yaml --port=8084 --target-port=909100 ``` 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...
Add a taint with key 'disktype' on nodes that have the label customer=acme-corp.
Command: ```bash kubectl taint node -l customer=acme-corp disktype=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": "", "us...
List deployments in YAML output format, for the "custom-apps" API group in version "hotfix-1.1.2"
Command: ```bash kubectl get deployments.hotfix-1.1.2.custom-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 y...
Create a job for batch processing with a specific command
Command: ```bash kubectl create job batch-processing --image=ruby -- ruby --version ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output fo...
Create a pod disruption budget named logging-pdb with a selector for pods with the version=v2 label, and set the minimum required available pods to 4.
Command: ```bash kubectl create poddisruptionbudget logging-pdb --selector=version=v2 --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 [--dry-...
Update the image of a container in a pod using a JSON patch with positional arrays
Command: ```bash kubectl patch pod proxy-server-pod --type='json' -p='[{"op": "replace", "path": "/spec/containers/0/image", "value":"new image"}]' ``` 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...
Edit the api-service service using the notepad editor.
Command: ```bash KUBE_EDITOR="notepad" kubectl edit svc/api-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,...
List the replication controller 'web', service 'security-service-rc', and pod 'auth-service-pod'
Command: ```bash kubectl get rc/web service/security-service-rc pods/auth-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 ...
Set the CPU limits of the container in a deployment to "5" and the memory limits to "512Mi"
Command: ```bash kubectl set resources deployment go -c=nginx --limits=cpu=5,memory=512Mi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requested, but may burst up to its s...
Start a hazelcast pod and expose port 8082 on the container
Command: ```bash kubectl run hazelcast --image=hazelcast/hazelcast --port=8082 ``` 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:...
forward the local port 8088 to port 8080 in the 'api-service-pod' pod
Command: ```bash kubectl port-forward pod/api-service-pod 8088:8080 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected au...
import the DATABASE_URL key from the monitoring-config config map and set it as an environment variable in the api-server deployment
Command: ```bash kubectl set env --keys=DATABASE_URL --from=configmap/monitoring-config deployment/api-server-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defi...
Create a job called "security-scan-job" using the mysql image and run the command "mysql" within the job
Command: ```bash kubectl create job security-scan-job --image=mysql -- mysql ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. O...
Retrieve the output of the 'ruby --version' command running inside the 'lunar-launcher' container of the 'frontend-pod' pod.
Command: ```bash kubectl exec frontend-pod -c lunar-launcher -- ruby --version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omit...
Execute the command "nginx -g 'daemon off;'" in the 'cyber-sleuth' container of the 'media-stream-pod' pod and retrieve the output.
Command: ```bash kubectl exec media-stream-pod -c cyber-sleuth -- nginx -g "daemon off;" ``` 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 nam...
Open a raw terminal and attach to the specified pod and container
Command: ```bash kubectl attach backend-pod -c astro-container -i -t ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omi...
Import the 'smtp_server' key from the 'log-config' ConfigMap and set it as an environment variable in the 'web-app-deployment' deployment.
Command: ```bash kubectl set env --keys=smtp_server --from=configmap/log-config deployment/web-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 in ...
Create a LoadBalancer service named auth-service-lb to load balance traffic on port 8443 to port 5432.
Command: ```bash kubectl create service loadbalancer auth-service-lb --tcp=8443:5432 ``` 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", "de...
Copy the file 'foo' from the '/tmp' directory of the 'monitoring-agent-pod-6' pod in the 'metallb-system' namespace to the '/tmp/bar_dir' directory on your local machine.
Command: ```bash kubectl cp metallb-system/monitoring-agent-pod-6:/tmp/foo /tmp/bar_dir ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, ...
create a pod disruption budget named critical-services-pdb that selects pods with the component=web label and requires at least 9 of them to be available at any time
Command: ```bash kubectl create poddisruptionbudget critical-services-pdb --selector=component=web --min-available=9 ``` 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-availa...
Forcefully drain node "backup-node-14"
Command: ```bash kubectl drain backup-node-14 --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/ . Otherwis...
Retrieve the output from the command 'mysqld' running in the first container of the 'monitoring-stack-deployment' deployment
Command: ```bash kubectl exec deploy/monitoring-stack-deployment -- 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,...
Automatically scale the deployment "gateway" with a minimum of 4 pods and a maximum of 8 pods
Command: ```bash kubectl autoscale deployment gateway --min=4 --max=8 ``` 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 ...
create a ClusterIP service named security-service-clusterip that maps port 8181 on the service to port 8888 on the pods.
Command: ```bash kubectl create service clusterip security-service-clusterip --tcp=8181:8888 ``` What it does: Create a ClusterIP service with the specified name. Syntax: `kubectl create service clusterip NAME [--tcp=<port>:<targetPort>] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o...
List deployments in the specific version and API group, in JSON output format
Command: ```bash kubectl get deployments.dev-2.2.0.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 you w...
Get output from running the 'geth attach' command from the web-app-pod pod using the first container
Command: ```bash kubectl exec web-app-pod -- geth attach ``` 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...
Forward port 5432 on all addresses to port 3000 in the 'e-commerce-pod' pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/e-commerce-pod 5432:3000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod wi...
Get the output of running the 'pg_dump --version' command in the 'lunar-launcher' container from the 'monitoring-pod' pod.
Command: ```bash kubectl exec monitoring-pod -c lunar-launcher -- 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...
Create an ingress called 'myapp-ingress' that directs requests from site.com/bar to service 'svc1' on port 5432, using the TLS secret 'my-cert'.
Command: ```bash kubectl create ingress myapp-ingress --rule="site.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": "", "usage": "...
Create a job named 'database-seeding-job' using the 'jenkins' image and execute the command 'jenkins-plugin-cli'
Command: ```bash kubectl create job database-seeding-job --image=jenkins -- jenkins-plugin-cli ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage":...
Create a copy of the 'chat-app-pod' and change all container images to 'jenkins'
Command: ```bash kubectl debug chat-app-pod --copy-to=debug-image-1 --set-image=*=jenkins ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used by default if no reso...
update the container images of a deployment
Command: ```bash kubectl set image deployment/ubuntu busybox=busybox ubuntu=ubuntu:20.04 ``` What it does: Update existing container image(s) of resources. Possible resources include (case insensitive): pod (po), replicationcontroller (rc), deployment (deploy), daemonset (ds), statefulset (sts), cronjob (cj), replicas...
Switch to raw terminal mode and attach to the 'media-stream-pod' pod, using the 'lunar-launcher' container
Command: ```bash kubectl attach media-stream-pod -c lunar-launcher -i -t ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If...
Start a pod with Alpine image and expose port 3001
Command: ```bash kubectl run hazelcast --image=alpine --port=3001 ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args...]` Helpful flags: "flag": "--f...
Check if the current user has permission to list the 'load-testing-job' job in the 'kube-public' namespace.
Command: ```bash kubectl auth can-i list jobs.batch/load-testing-job -n kube-public ``` 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 U...
Delete pods and services with label feature=feature-xyz
Command: ```bash kubectl delete pods,services -l feature=feature-xyz ``` 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 ...
Copy the ~/.config/kube file from your local machine to the /tmp/bar_dir directory inside the "front-end-pod-12" pod, using the "monitoring-agent" container.
Command: ```bash kubectl cp ~/.config/kube front-end-pod-12:/tmp/bar_dir -c monitoring-agent ``` 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 omit...
Embed the certificate authority data for the testing-cluster cluster entry
Command: ```bash kubectl config set-cluster testing-cluster --embed-certs --certificate-authority=~/.kube/cluster-gamma/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...
View resource utilization metrics for all pods in a specific namespace
Command: ```bash kubectl top pod --namespace=external-git-service ``` What it does: Display resource (CPU/memory) usage of pods. The 'top pod' command allows you to see the resource consumption of pods. Due to the metrics pipeline delay, they may be unavailable for a few minutes since pod creation. Syntax: `kubectl t...
Import the keys 'DATABASE_URL' from the 'kube-system-config' config map into the 'search-engine-deployment' deployment
Command: ```bash kubectl set env --keys=DATABASE_URL --from=configmap/kube-system-config deployment/search-engine-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 an ingress called 'api-gateway-ingress' that routes requests to website.com/input to svc1:7000 with a tls secret named "my-cert"
Command: ```bash kubectl create ingress api-gateway-ingress --rule="website.com/input=svc1:7000,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": "",...
Execute the 'redis-cli' command in the 'nano-bot' container of the 'log-aggregator-pod' and retrieve the output.
Command: ```bash kubectl exec log-aggregator-pod -c nano-bot -- redis-cli ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, ...
Retrieve the output of the 'mongo --version' command executed in the mycontainer container of the backend-pod pod
Command: ```bash kubectl exec backend-pod -c mycontainer -- mongo --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...
Rename the context 'prod-context' to 'new-context' in your kubeconfig file
Command: ```bash kubectl config rename-context prod-context new-context ``` What it does: Renames a context from the kubeconfig file. CONTEXT_NAME is the context name that you want to change. NEW_NAME is the new name you want to set. Note: If the context being renamed is the 'current-context', this field will also be ...
Set up automatic scaling for the replication controller "media-stream"
Command: ```bash kubectl autoscale rc media-stream --max=4 --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...
Forward the local port 8000 to the pod's port 8888
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/web-app-pod 8000: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 criteri...
Set the cluster field in the cloud-context context to moon-cluster
Command: ```bash kubectl config set contexts.cloud-context.cluster moon-cluster ``` What it does: Set an individual value in a kubeconfig file. PROPERTY_NAME is a dot delimited name where each token represents either an attribute name or a map key. Map keys may not contain dots. PROPERTY_VALUE is the new value you wa...
Edit the last-applied-configuration annotations by the file 'setup.yaml' in JSON format
Command: ```bash kubectl apply edit-last-applied -f setup.yaml -o json ``` What it does: Edit the latest last-applied-configuration annotations of resources from the default editor. The edit-last-applied command allows you to directly edit any API resource you can retrieve via the command-line tools. It will open the ...
Scale the replica set 'api-service-rs' to 3 replicas
Command: ```bash kubectl scale --replicas=3 rs/api-service-rs ``` What it does: Set a new size for a deployment, replica set, replication controller, or stateful set. Scale also allows users to specify one or more preconditions for the scale action. If --current-replicas or --resource-version is specified, it is valid...
Forward local port 8080 to port 3000 in the pod "e-commerce-pod"
Command: ```bash kubectl port-forward pod/e-commerce-pod 8080 3000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected aut...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=SECRET_KEY --from=configmap/ui-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...
Create a job called 'certificate-renewal' using the 'centos' image, and execute the command 'sleep 3600'
Command: ```bash kubectl create job certificate-renewal --image=centos -- sleep 3600 ``` 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...
Set the CPU limits of the nginx container in the php deployment to 5 and the memory limit to 2Gi.
Command: ```bash kubectl set resources deployment php -c=nginx --limits=cpu=5,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 requested, but may burst up to its sp...
Update the cluster field in the specific context
Command: ```bash kubectl config set contexts.client-2-context.cluster star-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...
Update the annotation value of the pod named 'payment'
Command: ```bash kubectl annotate --overwrite pods payment 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 includ...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=external_api_url --from=configmap/app-config-prod 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 varia...
Get the output from running the 'elasticsearch-plugin --list' command on the first pod of the 'database-service' service, using the first container.
Command: ```bash kubectl exec svc/database-service -- elasticsearch-plugin --list ``` 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 o...
Update node 'db-node-7' by adding a taint with key 'workload', value 'high-priority', and effect 'NoSchedule'
Command: ```bash kubectl taint nodes db-node-7 workload=high-priority: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 form...
Add a taint with key 'special' on nodes having label owner=john-doe
Command: ```bash kubectl taint node -l owner=john-doe special=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": "", "usage": "O...
Update the label of the 'payment' pod to set the 'tier' label to 'frontend'
Command: ```bash kubectl label pods payment tier=frontend ``` 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": ...
Set the service account of the deployment 'proxy-service-deployment' to 'spinnaker'
Command: ```bash kubectl set serviceaccount deployment proxy-service-deployment spinnaker ``` 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: `ku...
Apply a taint with the key 'cpu-type' on the nodes that have the label app=web-app, setting the taint effect to PreferNoSchedule, and apply it specifically on the node named 'app-node-6'.
Command: ```bash kubectl taint node -l app=web-app cpu-type=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": "Out...
Delete the pods and services with the names 'frontend' and 'web'
Command: ```bash kubectl delete pod,service frontend web ``` 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. So...
Create a role named "reader" with the following permissions:
Command: ```bash kubectl create role reader --verb=proxy --resource=pods --resource-name=identity-provider --resource-name=payment-processor ``` What it does: Create a role with single rule. Syntax: `kubectl create role NAME --verb=verb --resource=resource.group/subresource [--resource-name=resourcename] [--dry-run=s...
List the replication controller 'web', service 'media-stream-rc', and pod 'chat-app-pod'
Command: ```bash kubectl get rc/web service/media-stream-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 namespac...
Get output from running the 'mysql' command in the 'astro-container' from the pod named 'chat-app-pod'.
Command: ```bash kubectl exec chat-app-pod -c astro-container -- 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, use...
List deployments in the "rc-1.1.0" version of the "testing-apps" API group in JSON output format.
Command: ```bash kubectl get deployments.rc-1.1.0.testing-apps -o json ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you ...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=DATABASE_URL --from=configmap/global-config deployment/frontend-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definition...
Import the secret_key from the global-config ConfigMap and set it as an environment variable in the load-balancer-deployment deployment.
Command: ```bash kubectl set env --keys=secret_key --from=configmap/global-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 definit...
Import environment variables from a secret to a deployment
Command: ```bash kubectl set env --from=secret/app-config-secret deployment/frontend-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more po...
Forward port 5432 on all addresses to port 9090 in the pod named "e-commerce-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/e-commerce-pod 5432: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 wi...
Set the cluster field in a specific context to a given cluster
Command: ```bash kubectl config set contexts.testing-context.cluster sun-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 w...
Get the output from running the 'node' command in the 'code-explorer' container of the 'monitoring-pod' pod.
Command: ```bash kubectl exec monitoring-pod -c code-explorer -- 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 ...
Start a python pod named "hazelcast" with the python image and expose port 8888.
Command: ```bash kubectl run hazelcast --image=python --port=8888 ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args...]` Helpful flags: "flag": "--f...
Create a copy of the backend-pod and change all container images to jenkins. The copy will be named debug-image-api.
Command: ```bash kubectl debug backend-pod --copy-to=debug-image-api --set-image=*=jenkins ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used by default if no res...
Create a service for the 'centos' deployment in the default namespace
Command: ```bash kubectl expose deployment centos --port=6379 --target-port=808200 ``` 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 CPU limit of the kafka container in the deployment to "10" and the memory limit to "1Gi".
Command: ```bash kubectl set resources deployment kafka -c=nginx --limits=cpu=10,memory=1Gi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requested, but may burst up to its...
Set the cpu limit to "50m" and memory limit to "512Mi" for the nginx container in the deployment named nginx.
Command: ```bash kubectl set resources deployment nginx -c=nginx --limits=cpu=50m,memory=512Mi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requested, but may burst up to ...
Get the output from running the 'node' command in the first pod of the 'log-aggregator-deployment' deployment.
Command: ```bash kubectl exec deploy/log-aggregator-deployment -- 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...
Create a new secret named aws-credentials-secret using the data in the path/to/data.env file
Command: ```bash kubectl create secret generic aws-credentials-secret --from-env-file=path/to/data.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 b...
Import the specific keys from a config map into a deployment
Command: ```bash kubectl set env --keys=external_api_url --from=configmap/ui-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 defi...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=external_api_url --from=configmap/global-config deployment/payment-processor-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 variab...
List the specified resources by their type and names
Command: ```bash kubectl get rc/web service/backend-rc pods/email-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 namespac...
Create a new ClusterIP service named 'billing-service-clusterip' that maps port 8083 to port 8443
Command: ```bash kubectl create service clusterip billing-service-clusterip --tcp=8083: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"...
Update the pod configuration specified in the "setup.json" file by adding an annotation for alert email with the value "alerts@example.com".
Command: ```bash kubectl annotate -f setup.json 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 includ...
Add the annotation 'backup-strategy' with the value 'daily backups' to the 'vpn' pod
Command: ```bash kubectl annotate pods vpn backup-strategy='daily backups' ``` 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 ar...
Listen on port 5432 locally, forwarding data to/from port 5000 in a pod selected by the 'api-server-deployment' deployment.
Command: ```bash kubectl port-forward deployment/api-server-deployment 5432 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 b...
List deployments in the "stable-2.0.0" version of the "legacy-apps" API group in JSON format
Command: ```bash kubectl get deployments.stable-2.0.0.legacy-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 y...
Create a copy of the pod "auth-service-pod" and change all container images to use the "python" image
Command: ```bash kubectl debug auth-service-pod --copy-to=debug-image-web --set-image=*=python ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used by default if no...
Get the phase value of a specific pod.
Command: ```bash kubectl get -o template pod/database-pod --template={{.status.phase}} ``` 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...