prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Create a pod named 'hazelcast' using the 'ubuntu' image and expose port 5000
Command: ```bash kubectl run hazelcast --image=ubuntu --port=5000 ``` 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...
Forward local port 5432 to port 5432 in a pod selected by the email-server-deployment deployment.
Command: ```bash kubectl port-forward deployment/email-server-deployment 5432 5432 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will...
Copy the local file /tmp/foo_dir to the remote pod payment-gateway-pod-19, specifically to /tmp/bar in the web-app-container.
Command: ```bash kubectl cp /tmp/foo_dir payment-gateway-pod-19::/tmp/bar -c web-app-container ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If om...
Set the resource request and limits for all containers in the 'mysql' deployment
Command: ```bash kubectl set resources deployment mysql --limits=cpu=200m,memory=512Mi --requests=cpu=200m,memory=64Mi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource request...
Partially update the 'k8s-node-1' node by changing the password to 'new-password' using a strategic merge patch in JSON format.
Command: ```bash kubectl patch node k8s-node-1 -p '{"stringData":{"password":"new-password"}' ``` What it does: Update fields of a resource using strategic merge patch, a JSON merge patch, or a JSON patch. JSON and YAML formats are accepted. Syntax: `kubectl patch (-f FILENAME | TYPE NAME) [-p PATCH|--patch-file FILE...
Create an ingress named 'app1-ingress' that routes requests for 'site.com/example' to the service 'svc1' on port 8000, using the TLS secret named 'my-cert'.
Command: ```bash kubectl create ingress app1-ingress --rule="site.com/example=svc1:8000,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage"...
Copy the contents of the /var/run/secrets/kubernetes.io/serviceaccount/ directory from the pod "auth-service-pod-11" to the local directory /etc/kubernetes.
Command: ```bash kubectl cp kube-flannel/auth-service-pod-11:/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": "", "u...
List resources of different types and their names
Command: ```bash kubectl get rc/web service/database-rc pods/web-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 namespaced yo...
Import the 'smtp_server' key from the 'namespace-config' ConfigMap into the 'notification-handler-deployment' Deployment.
Command: ```bash kubectl set env --keys=smtp_server --from=configmap/namespace-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 varia...
Set the cluster field in the my-context context to my-k8s-cluster
Command: ```bash kubectl config set contexts.app-2-context.cluster my-k8s-cluster ``` What it does: Set an individual value in a kubeconfig file. PROPERTY_NAME is a dot delimited name where each token represents either an attribute name or a map key. Map keys may not contain dots. PROPERTY_VALUE is the new value you ...
Copy the ~/.config/kube directory from the remote pod "prometheus/load-balancer-pod-9" to the local directory "/tmp/bar_dir"
Command: ```bash kubectl cp prometheus/load-balancer-pod-9:~/.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, u...
Create a job named "monitoring-job" using the "redis" image, and run the command "redis-cli" inside the job
Command: ```bash kubectl create job monitoring-job --image=redis -- redis-cli ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. ...
Set the cluster field of the 'team-beta-context' context to 'cluster-alpha'.
Command: ```bash kubectl config set contexts.team-beta-context.cluster cluster-alpha ``` 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 y...
Update the description of a pod identified in the "pod.json" file.
Command: ```bash kubectl annotate -f pod.json description='Web server for marketing site' ``` 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...
Attach to a specific container in a pod to view its output.
Command: ```bash kubectl attach database-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 omitted,...
Set the limits and requests for CPU and memory resources for all containers in the 'mongo' deployment
Command: ```bash kubectl set resources deployment mongo --limits=cpu=200m,memory=512Mi --requests=cpu=500m,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 requeste...
Add a taint with key 'environment' on nodes having label app-type=microservice
Command: ```bash kubectl taint node -l app-type=microservice environment=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":...
Create an ingress named 'private-service-ingress' that routes requests to website.com/bar to svc1:8089 with a tls secret named "my-cert"
Command: ```bash kubectl create ingress private-service-ingress --rule="website.com/bar=svc1:8089,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": "...
Create an ingress called 'web-ingress' that routes requests from foo.com/bar to svc1:8081 and uses the tls secret "my-cert"
Command: ```bash kubectl create ingress web-ingress --rule="foo.com/bar=svc1:8081,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": "Out...
Create a service for a replicated deployment of Ubuntu, which serves on port 8443 and connects to the containers on port 808200.
Command: ```bash kubectl expose rs ubuntu --port=8443 --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 specified port....
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=external_api_url --from=configmap/namespace-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 d...
Add an annotation to the pod 'security' with the key 'expiration-date' and the value '2024-12-31'
Command: ```bash kubectl annotate pods security 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 and include ...
Open the web-service service in the gedit editor
Command: ```bash KUBE_EDITOR="gedit" kubectl edit svc/web-service ``` What it does: Edit a resource from the default editor. The edit command allows you to directly edit any API resource you can retrieve via the command-line tools. It will open the editor defined by your KUBE_EDITOR, or EDITOR environment variables, o...
Listen on all addresses on port 8000 and forward the traffic to port 5000 in the pod named 'analytics-pod'.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/analytics-pod 8000:5000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod wil...
Set the environment variable 'DEBUG' to 'true' in the 'notification-handler-deployment' deployment
Command: ```bash kubectl set env deployment/notification-handler-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 templat...
Create an ingress called 'app1-ingress' that routes requests from website.com/bar to svc1:3001 with a TLS secret named "my-cert"
Command: ```bash kubectl create ingress app1-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": "", "usage":...
Create a role named "admin_role" with the specified resource names
Command: ```bash kubectl create role admin_role --verb=connect --resource=pods --resource-name=web-frontend --resource-name=order-fulfillment ``` 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=...
Set the LOG_LEVEL environment variable for the api-server-deployment deployment using the values from the api-config config map.
Command: ```bash kubectl set env --keys=LOG_LEVEL --from=configmap/api-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 definitions in...
Create a role named "view" with the verb "delete" and resources "pods" and "dev-database"
Command: ```bash kubectl create role view --verb=delete --resource=pods --resource-name=dev-database --resource-name=dev-database ``` 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=server|clien...
Run the 'elasticsearch' command in the 'time-machine' container of the 'media-stream-pod' pod and get the output.
Command: ```bash kubectl exec media-stream-pod -c time-machine -- 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 omi...
Start the alpine pod with a custom command and arguments.
Command: ```bash kubectl run nginx --image=alpine --command -- <cmd> <arg1> ... <argN> ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args...]` Helpfu...
Delete the pods and services named "media-stream" and "analytics"
Command: ```bash kubectl delete pod,service media-stream analytics ``` 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 se...
Set the cluster field in the context named my-context to edge-cluster
Command: ```bash kubectl config set contexts.service-account-context.cluster edge-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 va...
Remove all the taints with key 'datacenter' from the node 'prod-node-5'
Command: ```bash kubectl taint nodes prod-node-5 datacenter- ``` 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|yam...
Show the deployments in the "v1.1.0" version of the "alpha-apps" API group in JSON format.
Command: ```bash kubectl get deployments.v1.1.0.alpha-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...
Forward local port 6379 to port 8081 in the pod "mypod" on specific IP addresses (localhost and 10.19.21.23)
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/mypod 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 p...
Enable autoscaling for the 'auth' replication controller with a target CPU utilization of 60%
Command: ```bash kubectl autoscale rc auth --max=2 --cpu-percent=60 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that uses th...
Add the annotation 'backup-strategy' with the value 'daily backups' to the pod named 'analytics'
Command: ```bash kubectl annotate pods analytics 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 incl...
Create a new ClusterIP service named notification-service-clusterip that maps port 8888 on the service to port 8000 on the pods
Command: ```bash kubectl create service clusterip notification-service-clusterip --tcp=8888:8000 ``` 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":...
Execute the command 'docker run -it ubuntu' inside the 'email-service-pod' pod, using the 'rocket-ranger' container.
Command: ```bash kubectl exec email-service-pod -c rocket-ranger -- docker run -it ubuntu ``` 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 na...
Create a cluster role named "foo" with specified resource names
Command: ```bash kubectl create clusterrole foo --verb=list --resource=pods --resource-name=file-uploader --resource-name=image-processor ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|client|none...
Attach to the nano-bot container in the proxy-server-pod and get its output.
Command: ```bash kubectl attach proxy-server-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, us...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=log_level --from=configmap/app-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 definitions in...
Create an ingress called 'api-ingress' with a rule that directs requests for website.com/example to svc1:27017, and use the TLS secret "my-cert"
Command: ```bash kubectl create ingress api-ingress --rule="website.com/example=svc1:27017,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...
Create a new config map named "app-secrets" and include the specified keys and corresponding files from disk.
Command: ```bash kubectl create configmap app-secrets --from-file=properties=/path/to/settings/file1.txt --from-file=key1=/path/to/profiles/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating ...
Set the resource request and limits for all containers in a golang deployment
Command: ```bash kubectl set resources deployment golang --limits=cpu=200m,memory=512Mi --requests=cpu=100m,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...
Set the client-key-data field for the app-service user using the --set-raw-bytes option and provide the certificate data as a raw byte array.
Command: ```bash kubectl config set users.app-service.client-key-data cert_data_here --set-raw-bytes=true ``` 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_VAL...
Set the CPU limits of the nginx container in the runtime deployment to "500m" and the memory limits to "512Mi"
Command: ```bash kubectl set resources deployment runtime -c=nginx --limits=cpu=500m,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 ...
Create a job named 'backup' using the 'golang' image, and the command 'go version'
Command: ```bash kubectl create job backup --image=golang -- go 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. One of...
Remove a specific taint from a node
Command: ```bash kubectl taint nodes db-node-7 special:NoSchedule- ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: js...
Get the output from running the 'mongo' command inside the 'web-app-pod' pod, using the 'lunar-launcher' container.
Command: ```bash kubectl exec web-app-pod -c lunar-launcher -- 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, use t...
Display the last 31 lines of logs for the pod 'web-app-pod'
Command: ```bash kubectl logs --tail=31 web-app-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", "short": "-c"...
Apply a taint with the key 'cpu-type' and value 'backup-node-14:PreferNoSchedule' to all nodes with the label 'zone=us-east-1'
Command: ```bash kubectl taint node -l zone=us-east-1 cpu-type=backup-node-14:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage...
Create a new ExternalName service named external-file-storage-service pointing to museum-example.museum
Command: ```bash kubectl create service externalname external-file-storage-service --external-name museum-example.museum ``` What it does: Create an ExternalName service with the specified name. ExternalName service references to an external DNS address instead of only pods, which will allow application authors to ref...
Set the server field on the edge-cluster cluster to the specified IP address.
Command: ```bash kubectl config set clusters.edge-cluster.server https://1.2.3.4 ``` 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...
Listen on port 8081 locally and forward traffic to port 8080 in the analytics-pod
Command: ```bash kubectl port-forward pod/analytics-pod 8081: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 auto...
Forward local port 3000 to port 8081 in the 'frontend-pod' pod
Command: ```bash kubectl port-forward pod/frontend-pod 3000: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 autom...
Forward port 9090 on all addresses to port 8888 on the pod named "e-commerce-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/e-commerce-pod 9090: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...
Embed the certificate authority data for the "staging-cluster" cluster entry
Command: ```bash kubectl config set-cluster staging-cluster --embed-certs --certificate-authority=~/.kube/sun-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 s...
Create an ingress named 'public-ingress' with a rule that directs requests to testing.com/bar to svc1:6379
Command: ```bash kubectl create ingress public-ingress --rule="testing.com/bar=svc1:6379,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...
Forward traffic from port 8081 on localhost and IP address 10.19.21.23 to port 3000 in the pod named "mypod".
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/mypod 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 p...
Remove the label named 'component' from pod 'log-aggregator'
Command: ```bash kubectl label pods log-aggregator 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", "usag...
Set the service account of the deployment "load-balancer-deployment" to "cert-manager"
Command: ```bash kubectl set serviceaccount deployment load-balancer-deployment cert-manager ``` 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 an ingress rule with a specific path and redirect requests to a service, with TLS enabled.
Command: ```bash kubectl create ingress app-loadbalancer-ingress --rule="site.com/bar=svc1:8089,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": "",...
Set the execution argument for the "web-app" entry in the kubeconfig file to arg1 and arg2.
Command: ```bash kubectl config set-credentials web-app --exec-arg=arg1 --exec-arg=arg2 ``` 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 fl...
Edit the configuration of a service using the nvim editor.
Command: ```bash KUBE_EDITOR="nvim" kubectl edit svc/monitoring-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 variab...
Apply a taint with the key 'environment' on nodes that have the label 'environment=production'
Command: ```bash kubectl taint node -l environment=production environment=gpu-node-12:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": ""...
Forward local port 5000 to port 6379 in the pod "chat-app-pod"
Command: ```bash kubectl port-forward pod/chat-app-pod 5000:6379 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected autom...
Create a new namespace named development
Command: ```bash kubectl create namespace development ``` What it does: Create a namespace with the specified name. Syntax: `kubectl create namespace NAME [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: json|yaml|name|go-template|go-te...
create a new ClusterIP service named database-service-clusterip and map port 8181 on the cluster to port 3306 on the service
Command: ```bash kubectl create service clusterip database-service-clusterip --tcp=8181: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...
Apply a taint on the nodes with the 'component=proxy' label
Command: ```bash kubectl taint node -l component=proxy dedicated=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": "", ...
Expose the hazelcast deployment as a service on port 8088, connecting to the containers on port 8000.
Command: ```bash kubectl expose deployment hazelcast --port=8088 --target-port=800000 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the spec...
Add a taint to nodes with the label "namespace=mynamespace" with the key "app" and value "gpu-node-12"
Command: ```bash kubectl taint node -l namespace=mynamespace app=gpu-node-12:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage"...
Set the cpu limits of the postgres container in the deployment to "3" and the memory limits to "128Mi"
Command: ```bash kubectl set resources deployment postgres -c=nginx --limits=cpu=3,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...
Enable the new exec auth plugin for the "robot-user" entry
Command: ```bash kubectl config set-credentials robot-user --exec-command=/path/to/the/executable --exec-api-version=client.authentication.k8s.io/v1beta1 ``` 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: ...
Set the custom TLS server name to use for validation for the testing-cluster cluster entry.
Command: ```bash kubectl config set-cluster testing-cluster --tls-server-name=app-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...
Remove all taints with the key 'disktype' from the node 'node-2'
Command: ```bash kubectl taint nodes node-2 disktype- ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: json|yaml|name|...
Forward data between local ports 8000 and 6000 and the corresponding ports in the specified pod
Command: ```bash kubectl port-forward pod/log-aggregator-pod 8000 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...
Create a copy of vpn-service-pod and name it my-debugger, with all container images changed to confluentinc/cp-kafka.
Command: ```bash kubectl debug vpn-service-pod --copy-to=my-debugger --set-image=*=confluentinc/cp-kafka ``` 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...
Embed the certificate authority data for the 'cluster-beta' cluster entry and specify the path to the certificate authority file as '~/.kube/cluster-gamma/kubernetes.ca.crt'
Command: ```bash kubectl config set-cluster cluster-beta --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 se...
Create a role named "custom_role" with the ability to update pods with the resource names "billing-service" and "monitoring-prometheus"
Command: ```bash kubectl create role custom_role --verb=update --resource=pods --resource-name=billing-service --resource-name=monitoring-prometheus ``` What it does: Create a role with single rule. Syntax: `kubectl create role NAME --verb=verb --resource=resource.group/subresource [--resource-name=resourcename] [--d...
Run the 'mongo' command inside the first container of the analytics-service pod and display the output
Command: ```bash kubectl exec svc/analytics-service -- 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, use the kubec...
Update the annotation 'git-repo' of the pod 'monitoring' with the value 'https://github.com/example/my-app'
Command: ```bash kubectl annotate pods monitoring git-repo='https://github.com/example/my-app' ``` 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 l...
Import the 'config_file_path' key from the 'namespace-config' config map and set it as an environment variable for the 'order-processing-deployment' deployment.
Command: ```bash kubectl set env --keys=config_file_path --from=configmap/namespace-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 vari...
Add a taint with the key 'dedicated' on nodes that have the label 'version=v1.0.0'
Command: ```bash kubectl taint node -l version=v1.0.0 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": "", "usage": ...
Create a pod named "hazelcast" running the "redis" image with labels "app=redis" and "env=prod"
Command: ```bash kubectl run hazelcast --image=redis --labels="app=redis,env=prod" ``` 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 fl...
Create a deployment named 'jenkins' that runs the 'ruby' image with 2 replicas.
Command: ```bash kubectl create deployment jenkins --image=ruby --replicas=2 ``` 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...
Forward traffic from local port 8000 to port 8080 in the 'e-commerce-pod' pod.
Command: ```bash kubectl port-forward pod/e-commerce-pod 8000: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 aut...
Set the cluster field to kube-cluster-1 in the my-context context
Command: ```bash kubectl config set contexts.user-a-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 value you...
Create a pod disruption budget named api-service-pdb that selects all pods with the region=us-east label and requires a minimum of four of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget api-service-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...
Remove the taints with key 'disktype' from node 'monitoring-node-15'
Command: ```bash kubectl taint nodes monitoring-node-15 disktype- ``` 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: jso...
Create a copy of e-commerce-pod, adding a debug container and changing container images
Command: ```bash kubectl debug e-commerce-pod -it --copy-to=my-debugger --image=debian --set-image=logger=logging-app:debug,mailer=mailer:latest ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by res...
Forward traffic from a local port to a specific port in a pod
Command: ```bash kubectl port-forward pod/api-service-pod :8088 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automa...
Create an ingress resource named 'www-ingress' that routes requests for 'foo.com/bar' to the service 'svc1' on port 5000
Command: ```bash kubectl create ingress www-ingress --rule="foo.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": "Out...
Execute the command 'kafka-console-producer --broker-list localhost:9092 --topic test' in the code-explorer container of the email-service-pod.
Command: ```bash kubectl exec email-service-pod -c code-explorer -- 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": ...
Retrieve the snapshot logs from the container database-deployment-1 in the deployment named database-pod.
Command: ```bash kubectl logs deployment/database-deployment -c database-pod-1 ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "...
Create an ingress that maps requests for "testing.com/bar" to "svc1:8082" with TLS encryption using the secret "my-cert"
Command: ```bash kubectl create ingress website-ingress --rule="testing.com/bar=svc1:8082,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usag...
Execute the 'ash' command inside the pod named mypod and display the output.
Command: ```bash kubectl exec mypod -- 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 kubectl.kubernetes.io/d...
Remove the taint with key 'hardware' and effect 'NoExecute' from the node 'worker-node-3' if it exists
Command: ```bash kubectl taint nodes worker-node-3 hardware:NoExecute- ``` 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...
Forward ports from local machine to pod
Command: ```bash kubectl port-forward pod/cdn-service-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 will be selected au...