prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Scale the prod-app-rs deployment to 1 replica, when the current size is 5 replicas
Command: ```bash kubectl scale --current-replicas=5 --replicas=1 deployment/prod-app-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...
Expose a deployment as a service on port 5432, which connects to the containers on port 300100
Command: ```bash kubectl expose deployment python --port=5432 --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 specifi...
Run the command 'elasticsearch-plugin --list' in the quantum-quark container of the proxy-server-pod pod and display the output
Command: ```bash kubectl exec proxy-server-pod -c quantum-quark -- 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": "Contain...
Auto scale deployment "foo" with a minimum of 2 pods and a maximum of 10 pods
Command: ```bash kubectl autoscale deployment foo --min=2 --max=10 ``` 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...
import specific keys from a config map into a deployment
Command: ```bash kubectl set env --keys=config_file_path --from=configmap/app-settings 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 definiti...
Set the CPU limits to "200m" and memory limits to "128Mi" for the 'nginx' container of the 'node' deployment
Command: ```bash kubectl set resources deployment node -c=nginx --limits=cpu=200m,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 ...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=external_api_url --from=configmap/ui-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 defin...
create a cron job with a given command
Command: ```bash kubectl create cronjob database-maintenance --image=jenkins --schedule="*/1 * * * *" -- jenkins-plugin-cli ``` What it does: Create a cron job with the specified name. Syntax: `kubectl create cronjob NAME --image=image --schedule='0/5 * * * ?' -- [COMMAND] [args...]` Helpful flags: "flag": "--output...
Create a debug pod from chat-app-pod, copy it to my-debugger with the container cyber-sleuth and open a shell in it
Command: ```bash kubectl debug chat-app-pod -it --copy-to=my-debugger --container=cyber-sleuth -- sh ``` 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...
Create a cluster role with non-resource url specified
Command: ```bash kubectl create clusterrole "admin_role" --verb=proxy --non-resource-url=/oapi/* ``` 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]` Helpful flags: "flag": "--output", "s...
Create a new config map with specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap log-config --from-file=properties=/path/to/settings/file1.txt --from-file=key1=/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 ...
create a pod based on the JSON content in the 'docker-registry.yaml' file
Command: ```bash cat docker-registry.yaml | kubectl create -f - ``` What it does: Create a resource from a file or from stdin. JSON and YAML formats are accepted. Syntax: `kubectl create -f FILENAME` Helpful flags: "flag": "--filename", "short": "-f", "default": "[]", "usage": "Filename, directory, or URL to files t...
Import environment variables from a secret to a deployment
Command: ```bash kubectl set env --from=secret/my-secret deployment/analytics-platform-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 ...
Update the image of all containers in the daemonset named namespace-2 to 'ubuntu:20.04'
Command: ```bash kubectl set image daemonset namespace-2 *=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), replicaset (rs) Syntax: ...
Forward local port 8888 to port 8000 in the pod "log-aggregator-pod"
Command: ```bash kubectl port-forward pod/log-aggregator-pod 8888: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 cluster role binding named 'foo' that grants the 'foo' cluster role to the 'app-operator' user, 'sysadmin' user, and 'security-auditors' group.
Command: ```bash kubectl create clusterrolebinding foo --clusterrole=foo --user=app-operator --user=sysadmin --group=security-auditors ``` What it does: Create a cluster role binding for a particular cluster role. Syntax: `kubectl create clusterrolebinding NAME --clusterrole=NAME [--user=username] [--group=groupname]...
list specific resources by their type and names
Command: ```bash kubectl get rc/web service/log-aggregator-rc pods/api-service-pod ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is nam...
Create a deployment named 'loadbalancer' running the 'mongo' image and exposing port '3000'
Command: ```bash kubectl create deployment loadbalancer --image=mongo --port=3000 ``` 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 ...
Create an ingress called 'internal-ingress' that directs requests to foo.com/example to svc1:27017 with a tls secret named "my-cert"
Command: ```bash kubectl create ingress internal-ingress --rule="foo.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": "", "us...
Start a new nginx pod with the image 'redis', but use a custom set of specifications provided in the JSON override.
Command: ```bash kubectl run nginx --image=redis --overrides='{ "apiVersion": "alpha-2.0", "spec": { ... } }' ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMM...
Autoscale the deployment "log-aggregator" with the minimum number of pods set to 2 and the maximum number of pods set to 9.
Command: ```bash kubectl autoscale deployment log-aggregator --min=2 --max=9 ``` 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 tha...
Embed certificate authority data for the cluster entry
Command: ```bash kubectl config set-cluster on-prem-cluster --embed-certs --certificate-authority=~/.kube/cluster-alpha/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 pod disruption budget named messaging-pdb that selects all pods with the label project=my-project and requires a minimum of 9 of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget messaging-pdb --selector=project=my-project --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-available...
Start a pod running the Jenkins image and expose port 8089.
Command: ```bash kubectl run hazelcast --image=jenkins --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": "--...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=log_level --from=configmap/app-config-prod 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 defini...
Remove the 'disktype' taint from node 'node-1'
Command: ```bash kubectl taint nodes node-1 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|...
Start streaming the logs of the "quantum-quark" container in the pod named "vpn-service-pod"
Command: ```bash kubectl logs -f -c quantum-quark 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",...
Apply a taint with key 'app' on nodes that have the label feature=feature-xyz
Command: ```bash kubectl taint node -l feature=feature-xyz app=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": "", "usage": "...
Start a pod with a specific image, but customize its configuration using JSON overrides
Command: ```bash kubectl run nginx --image=mcr.microsoft.com/dotnet/core/runtime --overrides='{ "apiVersion": "hotfix-1.1.2", "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] [--override...
Copy a file named "foo" from a remote pod to your local machine at "/tmp/bar"
Command: ```bash kubectl cp kube-system/ingress-controller-pod-8:/tmp/foo /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 t...
Check if you have permission to list the job named "data-synchronization-job" in the "kube-dns" namespace
Command: ```bash kubectl auth can-i list jobs.batch/data-synchronization-job -n kube-dns ``` 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 part...
Create a new config map named db-config with specified keys instead of file basenames on disk.
Command: ```bash kubectl create configmap db-config --from-file=properties=/path/to/settings/file1.txt --from-file=key1=/path/to/configs/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a c...
Set the cluster field to "galaxy-cluster" for the "my-context" context.
Command: ```bash kubectl config set contexts.cloud-context.cluster galaxy-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 ...
Listen on port 6379 locally and forward traffic to port 8080 in the backend-pod
Command: ```bash kubectl port-forward pod/backend-pod 6379: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 automa...
Add/update the annotation 'last-deployment' with the value '2023-03-15' for the pod 'frontend'.
Command: ```bash kubectl annotate pods frontend last-deployment=2023-03-15 ``` 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...
Set the service account of the web-app-deployment deployment to kube-controller-manager
Command: ```bash kubectl set serviceaccount deployment web-app-deployment kube-controller-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 Syn...
Forward all traffic from port 9090 on all computer addresses to port 8080 in the frontend-pod pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/frontend-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...
Update the node 'edge-node-10' by adding a taint with key 'zone' and value 'us-west-1a' and effect 'PreferNoSchedule'
Command: ```bash kubectl taint nodes edge-node-10 zone=us-west-1a:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output fo...
Create a new ClusterIP service named 'frontend-service-clusterip' that maps the local port 5001 to the target port 8010
Command: ```bash kubectl create service clusterip frontend-service-clusterip --tcp=5001:8010 ``` 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...
Check if you have permission to list the "content-import-job" job in the "testing" namespace.
Command: ```bash kubectl auth can-i list jobs.batch/content-import-job -n testing ``` 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 URL...
Retrieve information about the following resources: replication controller 'web', service 'payment-gateway-rc', and pod 'log-aggregator-pod'
Command: ```bash kubectl get rc/web service/payment-gateway-rc pods/log-aggregator-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...
Listen on port 8081 on your local machine and forward the traffic to port 5432 inside the pod named "cdn-service-pod"
Command: ```bash kubectl port-forward pod/cdn-service-pod 8081:5432 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected au...
Add an expiration date annotation to a pod specified in the given JSON file.
Command: ```bash kubectl annotate -f preferences.json 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 in...
Set the service account of the deployment "user-management-deployment" to "metrics-server"
Command: ```bash kubectl set serviceaccount deployment user-management-deployment metrics-server ``` What it does: Update the service account of pod template resources. Possible resources (case insensitive) can be: replicationcontroller (rc), deployment (deploy), daemonset (ds), job, replicaset (rs), statefulset Synt...
Create a pod disruption budget named replica-set-pdb that selects all pods with the component=web label and requires a minimum of 9 of them to be available at all times.
Command: ```bash kubectl create poddisruptionbudget replica-set-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-available=N ...
Create a deployment named 'gateway' that runs the 'node' image and exposes port '8081'.
Command: ```bash kubectl create deployment gateway --image=node --port=8081 ``` 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: js...
Partially update the 'kube-master-9' node by applying a strategic merge patch with a JSON patch
Command: ```bash kubectl patch node kube-master-9 -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 F...
Create a cluster role named "view" with permissions to patch non-resource URLs, specifically /healthz.
Command: ```bash kubectl create clusterrole "view" --verb=patch --non-resource-url=/healthz ``` 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]` Helpful flags: "flag": "--output", "short"...
Create an ingress with multiple hosts and specify the pathType as Prefix.
Command: ```bash kubectl create ingress ingress1 --class=default \ --rule="testing.com/path*=svc:8083" \ --rule="bar.com/admin*=svc2:http" ``` 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",...
Create a cluster role named "admin_role" with ResourceName specified for watching configmaps with names "app-worker-1" and "cache-redis"
Command: ```bash kubectl create clusterrole admin_role --verb=watch --resource=configmaps --resource-name=app-worker-1 --resource-name=cache-redis ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|cl...
Execute the 'nginx' command in the 'media-stream-pod' pod and retrieve the output.
Command: ```bash kubectl exec media-stream-pod -- nginx ``` 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.ku...
Output the modified deployment in YAML without making any changes to the object on the server.
Command: ```bash kubectl set env deployment/api-server-deployment API_KEY=your-api-key -o yaml ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more pod...
Create a new config map named app-name-config and include specified keys and values from files on disk
Command: ```bash kubectl create configmap app-name-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 ...
Start a pod named 'hazelcast' using the 'confluentinc/cp-kafka' image, and expose port 9090 from the container
Command: ```bash kubectl run hazelcast --image=confluentinc/cp-kafka --port=9090 ``` 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 flag...
Listen on port 5000 locally and forward traffic to port 8888 in the backend-pod pod.
Command: ```bash kubectl port-forward pod/backend-pod 5000:8888 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automa...
Add a taint with the key 'workload' and the value 'testing-node-11:PreferNoSchedule' to all nodes having the label 'region=eu-west-2'
Command: ```bash kubectl taint node -l region=eu-west-2 workload=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": "", "us...
Forward traffic from local port 8081 to port 8088 in the pod "mypod" on all addresses.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/mypod 8081: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 sel...
Create a new pod named 'hazelcast' using the 'ethereum/client-go' image, and configure the container to expose port 8088.
Command: ```bash kubectl run hazelcast --image=ethereum/client-go --port=8088 ``` 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: ...
Set a custom TLS server name for the web-cluster cluster entry
Command: ```bash kubectl config set-cluster web-cluster --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-a...
Update the scaling policy of the pod specified in the "config.json" file to "auto-horizontal-scaling"
Command: ```bash kubectl annotate -f config.json scaling-policy=auto-horizontal-scaling ``` 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 a...
Create an ingress with a specific rule that directs requests to a service using TLS secret
Command: ```bash kubectl create ingress myapp-ingress --rule="testing.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": "", "usag...
Update the owner annotation in the "preferences.json" pod to 'alice smith'
Command: ```bash kubectl annotate -f preferences.json owner='alice smith' ``` 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 arb...
Create a cron job that runs the specified command at the defined schedule.
Command: ```bash kubectl create cronjob metrics-collection --image=mysql --schedule="*/1 * * * *" -- mysqld ``` What it does: Create a cron job with the specified name. Syntax: `kubectl create cronjob NAME --image=image --schedule='0/5 * * * ?' -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o"...
Embed the certificate authority data for the kube-cluster-2 cluster entry
Command: ```bash kubectl config set-cluster kube-cluster-2 --embed-certs --certificate-authority=~/.kube/app-cluster/kubernetes.ca.crt ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config se...
Create a cluster role named "reader" with access to the "services" resource and specific resource names "mail-server" and "machine-learning".
Command: ```bash kubectl create clusterrole reader --verb=connect --resource=services --resource-name=mail-server --resource-name=machine-learning ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|cl...
Create a deployment with a specific image and port
Command: ```bash kubectl create deployment api --image=mcr.microsoft.com/dotnet/core/runtime --port=3306 ``` 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...
Expose a replicated controller named "python" as a service on port 9091, connecting to containers on port 888800.
Command: ```bash kubectl expose rc python --port=9091 --target-port=888800 ``` 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 new secret named payment-gateway-secret with the specified keys
Command: ```bash kubectl create secret generic payment-gateway-secret --from-file=ssh-privatekey=path/to/id_rsa --from-file=ssh-publickey=path/to/id_rsa.pub ``` 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...
Embed the certificate authority data for the 'kube-cluster-2' cluster entry using the certificate authority file located at '~/.kube/sun-cluster/kubernetes.ca.crt'.
Command: ```bash kubectl config set-cluster kube-cluster-2 --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 se...
Create a new config map named db-config using specific file paths as keys instead of file basenames on disk.
Command: ```bash kubectl create configmap db-config --from-file=conf=/path/to/settings/file1.txt --from-file=data=/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 a config...
Create an ExternalName service named external-security-service with a target external name of dummy-website.io.
Command: ```bash kubectl create service externalname external-security-service --external-name dummy-website.io ``` What it does: Create an ExternalName service with the specified name. ExternalName service references to an external DNS address instead of only pods, which will allow application authors to reference se...
Add the annotation 'last-deployment' with the value '2023-03-15' to the pod named 'proxy'
Command: ```bash kubectl annotate pods proxy last-deployment=2023-03-15 ``` 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 arbit...
Create a copy of the analytics-pod, add a debug container, and change container images.
Command: ```bash kubectl debug analytics-pod -it --copy-to=debug-image-1 --image=debian --set-image=app=app:debug,app=app:debug ``` 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. P...
Create a service for the replication controller specified in "php-controller.yaml" file
Command: ```bash kubectl expose -f php-controller.yaml --port=8000 --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 sp...
Add a taint with key 'app' on nodes having label namespace=mynamespace
Command: ```bash kubectl taint node -l namespace=mynamespace app=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": "", "usa...
Forward local port 3000 to port 3000 of the pod named proxy-server-pod
Command: ```bash kubectl port-forward pod/proxy-server-pod 3000 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 a...
Add a taint with key 'hardware' on nodes having label team=devops and the taint value as 'backup-node-14:PreferNoSchedule'.
Command: ```bash kubectl taint node -l team=devops hardware=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": ...
Copy the local file /tmp/foo_dir to the remote pod named ingress-controller-pod-8 in the prometheus namespace, and place it at /tmp/bar_dir in the pod.
Command: ```bash kubectl cp /tmp/foo_dir prometheus/ingress-controller-pod-8:/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...
Add a taint with key 'dedicated' and no value to node 'worker-node-3'
Command: ```bash kubectl taint nodes worker-node-3 dedicated: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 o...
Copy the directory "/tmp/foo_dir" from the remote pod "prometheus/metrics-exporter-pod-10" to the local directory "/tmp/bar".
Command: ```bash kubectl cp prometheus/metrics-exporter-pod-10:/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, us...
create a pod named hazelcast using the golang image and expose port 9090
Command: ```bash kubectl run hazelcast --image=golang --port=9090 ``` 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...
Remove the 'dedicated' taint from the node named 'web-node-8'
Command: ```bash kubectl taint nodes web-node-8 dedicated- ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: json|yaml|...
Create a cluster role named "reader" with the ability to patch services and specific resources such as "dev-database" and "app-analytics".
Command: ```bash kubectl create clusterrole reader --verb=patch --resource=services --resource-name=dev-database --resource-name=app-analytics ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|client...
Set the service account of the deployment "load-balancer-deployment" to "tiller"
Command: ```bash kubectl set serviceaccount deployment load-balancer-deployment tiller ``` What it does: Update the service account of pod template resources. Possible resources (case insensitive) can be: replicationcontroller (rc), deployment (deploy), daemonset (ds), job, replicaset (rs), statefulset Syntax: `kubec...
Apply a taint to node 'testing-node-11' with the key 'workload', value 'high-priority' and effect 'NoSchedule'
Command: ```bash kubectl taint nodes testing-node-11 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": "Outpu...
Listen on local port 6379 and forward data to/from port 5432 in a pod selected by the mydeployment deployment
Command: ```bash kubectl port-forward deployment/mydeployment 6379 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 selecte...
Check if you have permission to list the job named "notification-sender-job" in the "cert-manager" namespace
Command: ```bash kubectl auth can-i list jobs.batch/notification-sender-job -n cert-manager ``` 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 p...
Copy file from a remote pod to a local directory
Command: ```bash kubectl cp kube-server/front-end-pod-12::/tmp/foo /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": "Container name. If omitted, use t...
Open a raw terminal and connect to a specific container within a pod.
Command: ```bash kubectl attach proxy-server-pod -c warp-drive -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...
Start streaming the logs of the "mycontainer" container in the "e-commerce-pod" pod.
Command: ```bash kubectl logs -f -c mycontainer e-commerce-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", "s...
Edit the configuration of the service named 'frontend-service'
Command: ```bash kubectl edit svc/frontend-service ``` What it does: Edit a resource from the default editor. The edit command allows you to directly edit any API resource you can retrieve via the command-line tools. It will open the editor defined by your KUBE_EDITOR, or EDITOR environment variables, or fall back to ...
Create an ingress called 'api-v2-ingress' that directs requests from site.com/example to svc1:8088 with a tls secret named "my-cert"
Command: ```bash kubectl create ingress api-v2-ingress --rule="site.com/example=svc1:8088,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usag...
Add a taint with key 'hardware' on nodes having label team=devops
Command: ```bash kubectl taint node -l team=devops hardware=edge-node-10:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "O...
Remove the label 'unhealthy' from the pod 'chat-app'
Command: ```bash kubectl label pods chat-app unhealthy- ``` 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": "I...
Execute the 'geth' command from the pod 'database-pod' with the container 'quantum-quark' and retrieve the output.
Command: ```bash kubectl exec database-pod -c quantum-quark -- geth ``` 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...
Create a new ExternalName service named 'external-authentication-service' with "--external-name demo-service.dev"
Command: ```bash kubectl create service externalname external-authentication-service --external-name demo-service.dev ``` 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 refere...
Listen on ports 5432 and 6000 locally, and forward data to/from ports 8081 and 6000 in the 'backend-pod' pod.
Command: ```bash kubectl port-forward pod/backend-pod 5432 8081 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automa...
Forward traffic from port 8081 on all addresses to port 8088 in the pod named "e-commerce-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/e-commerce-pod 8081: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 wi...
Forward local traffic from port 8888 to a pod selected by the deployment named "authentication-service-deployment" on port 8888
Command: ```bash kubectl port-forward deployment/authentication-service-deployment 8888 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, ...
View the logs of container proxy-service-deployment-1 in the deployment named chat-app-pod.
Command: ```bash kubectl logs deployment/proxy-service-deployment -c chat-app-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: "fla...