prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Import the specific keys DATABASE_URL from the app-secrets config map into the scheduler-app-deployment deployment.
Command: ```bash kubectl set env --keys=DATABASE_URL --from=configmap/app-secrets 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 definit...
Return the snapshot logs from all containers in pods that are defined by the label "app=web-app".
Command: ```bash kubectl logs -l app=web-app --all-containers=true ``` 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 streaming the logs of the nano-bot container in the email-service-pod pod.
Command: ```bash kubectl logs -f -c nano-bot email-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", "s...
Apply a taint with the key 'zone' on nodes that have the label 'owner' set to 'john-doe', and set the value to 'prod-node-5:PreferNoSchedule'
Command: ```bash kubectl taint node -l owner=john-doe zone=prod-node-5: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...
Start a mongo pod with the name 'nginx' and using the 'mongo' image
Command: ```bash kubectl run nginx --image=mongo --overrides='{ "apiVersion": "legacy-1.0.0", "spec": { ... } }' ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [C...
Set environment variables in a deployment from specific keys in a config map.
Command: ```bash kubectl set env --keys=max_connections --from=configmap/app-secrets deployment/proxy-service-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defi...
Add a taint with the key 'cpu-type' and value 'gpu-node-12:PreferNoSchedule' on all nodes that have the label 'version=v1.0.0'
Command: ```bash kubectl taint node -l version=v1.0.0 cpu-type=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": ...
Update the label of the pod 'payment' to 'backend' with the key 'role'.
Command: ```bash kubectl label pods payment role=backend ``` What it does: Update the labels on a resource. Syntax: `kubectl label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]` Helpful flags: "flag": "--all-namespaces", "short": "-A", "default": "false", "usage": "...
Add the taint with key 'disktype' and value 'node-1:PreferNoSchedule' on the nodes that have the label 'component=proxy'.
Command: ```bash kubectl taint node -l component=proxy disktype=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": "Out...
Forward port 3000 on your local machine to port 8000 in the pod named "chat-app-pod"
Command: ```bash kubectl port-forward pod/chat-app-pod 3000:8000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected autom...
Execute the 'java -jar /usr/share/jenkins/jenkins.war' command in the code-explorer container of the proxy-service-pod pod
Command: ```bash kubectl exec proxy-service-pod -c code-explorer -- java -jar /usr/share/jenkins/jenkins.war ``` 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": "", "us...
Create a service for the 'nginx' replication controller, which serves on port 80 and connects to the containers on port 8000
Command: ```bash kubectl expose rc nginx --port=80 --target-port=300000 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port. A ...
Set the cluster field of the staging-context to on-prem-cluster
Command: ```bash kubectl config set contexts.staging-context.cluster on-prem-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 y...
Disable certificate checking for the dev cluster entry by running the command "kubectl config set-cluster cloud-cluster --insecure-skip-tls-verify=true"
Command: ```bash kubectl config set-cluster cloud-cluster --insecure-skip-tls-verify=true ``` 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...
Delete the context for the specified cluster
Command: ```bash kubectl config delete-context service-account-context ``` What it does: Delete the specified context from the kubeconfig. Syntax: `kubectl config delete-context NAME`
Forward local port 5432 to port 8080 in the frontend-pod, in order to listen and forward data between those ports.
Command: ```bash kubectl port-forward pod/frontend-pod 5432 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 autom...
Forward local port 6379 to port 6379 in the backend-pod
Command: ```bash kubectl port-forward pod/backend-pod 6379:6379 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automa...
Create a new deployment named 'loadbalancer' using the 'redis' image and expose port 8181.
Command: ```bash kubectl create deployment loadbalancer --image=redis --port=8181 ``` 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 ...
Add a taint with the key 'cpu-type' on nodes having the label 'customer=acme-corp' with the value 'worker-node-3:PreferNoSchedule'
Command: ```bash kubectl taint node -l customer=acme-corp cpu-type=worker-node-3:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "us...
Attach to the 'astro-container' in the 'cdn-service-pod' pod and get the output
Command: ```bash kubectl attach cdn-service-pod -c astro-container ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitt...
List the specified resources by their types and names
Command: ```bash kubectl get rc/web service/analytics-rc pods/proxy-server-pod ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespa...
Import the 'debug_mode' key from the 'configmap/app-config-prod' and apply it to the 'deployment/authentication-service-deployment'.
Command: ```bash kubectl set env --keys=debug_mode --from=configmap/app-config-prod deployment/authentication-service-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment varia...
Create a new secret named app-config-secret using the values from the configs.env file
Command: ```bash kubectl create secret generic app-config-secret --from-env-file=path/to/configs.env ``` What it does: Create a secret based on a file, directory, or specified literal value. A single secret may package one or more key/value pairs. When creating a secret based on a file, the key will default to the bas...
Edit the job 'notification-sender-job' in JSON format using the v1 API format
Command: ```bash kubectl edit job.v1.batch/notification-sender-job -o json ``` 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 var...
Add a taint with key 'workload' on nodes having label service=auth
Command: ```bash kubectl taint node -l service=auth workload=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": "O...
Add a taint with key 'app' and value 'dev-node-4:PreferNoSchedule' on nodes having label 'zone=us-east-1'
Command: ```bash kubectl taint node -l zone=us-east-1 app=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": "Outpu...
Import specific keys from a config map to a deployment's environment variables.
Command: ```bash kubectl set env --keys=REDIS_HOST --from=configmap/namespace-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 defi...
Set the service account of deployment "analytics-platform-deployment" to "my-service-account"
Command: ```bash kubectl set serviceaccount deployment analytics-platform-deployment my-service-account ``` 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), statefulse...
Partially update the 'node-1' node by specifying the patch as a YAML file with the following content:
Command: ```bash kubectl patch node node-1 -p $'spec:\n someField: newValue' ``` 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]` Helpful flags...
Expose a replica set as a service, serving on port 8089 and connecting to the containers on port 909100
Command: ```bash kubectl expose rs alpine --port=8089 --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 specified port....
Apply a taint with key 'zone' and value 'storage-node-13:PreferNoSchedule' on all nodes labeled with 'zone=us-east-1'
Command: ```bash kubectl taint node -l zone=us-east-1 zone=storage-node-13:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": ...
Execute the 'bash' command in the 'nebula-navigator' container from the 'log-aggregator-pod' pod and print the output.
Command: ```bash kubectl exec log-aggregator-pod -c nebula-navigator -- bash ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitte...
Set the custom TLS server name to "cluster-beta" for the galaxy-cluster cluster entry in the kubectl configuration.
Command: ```bash kubectl config set-cluster galaxy-cluster --tls-server-name=cluster-beta ``` 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...
Copy the file "/tmp/foo" from the remote pod "message-broker-pod-15" to the local directory "/tmp/bar".
Command: ```bash kubectl cp kubeapps/message-broker-pod-15::/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 the ku...
Set the custom TLS server name to "kube-cluster-2" for the "kube-cluster-1" cluster entry in the kubeconfig file.
Command: ```bash kubectl config set-cluster kube-cluster-1 --tls-server-name=kube-cluster-2 ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certifi...
Create a pod disruption budget named replica-set-pdb that will select all pods with the owner=team-1 label and require a minimum of four of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget replica-set-pdb --selector=owner=team-1 --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 [...
Create a service for the 'hazelcast' deployment, which serves on port 5432 and connects to the containers on port 844300
Command: ```bash kubectl expose deployment hazelcast --port=5432 --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 spec...
Create a new ClusterIP service named ldap-service-clusterip and expose port 8181 of the service to port 9091 of the pods
Command: ```bash kubectl create service clusterip ldap-service-clusterip --tcp=8181:9091 ``` 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", "...
Create a cron job named "system-health-check" in the default namespace, running an Ubuntu Docker image every minute
Command: ```bash kubectl create cronjob system-health-check --image=ubuntu --schedule="*/1 * * * *" -- docker run -d ubuntu sleep 3600 ``` 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"...
Get the output from running the 'bash' command in the 'nano-bot' container from the 'web-app-pod' pod.
Command: ```bash kubectl exec web-app-pod -c nano-bot -- bash ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kube...
Update the annotation 'app-version' of the 'security' pod to '2.5.1', overwriting any existing value
Command: ```bash kubectl annotate --overwrite pods security 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 inclu...
Import the 'max_connections' key from the 'kube-system-config' ConfigMap and set it as an environment variable for the 'frontend-deployment' deployment.
Command: ```bash kubectl set env --keys=max_connections --from=configmap/kube-system-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 de...
Execute the 'geth version' command inside the pod named chat-app-pod and display the output
Command: ```bash kubectl exec chat-app-pod -- geth version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubectl...
Forward traffic from your local machine's port 6379 to port 8000 in the cdn-service-pod pod.
Command: ```bash kubectl port-forward pod/cdn-service-pod 6379:8000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected au...
Embed certificate authority data for the sun-cluster cluster entry
Command: ```bash kubectl config set-cluster sun-cluster --embed-certs --certificate-authority=~/.kube/cluster-beta/kubernetes.ca.crt ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-...
Create a deployment named 'mattermost' using the 'golang' image and expose port 5432.
Command: ```bash kubectl create deployment mattermost --image=golang --port=5432 ``` 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 o...
List deployments using the "beta-apps" API group and output the results in JSON format.
Command: ```bash kubectl get deployments.alpha-2.0.beta-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 wi...
Import environment variables from a config map with a specified prefix
Command: ```bash kubectl set env --from=configmap/env-vars --prefix=MYSQL_ deployment/cache-cluster-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in...
Set the cluster field in the specified context to the specified cluster name.
Command: ```bash kubectl config set contexts.service-account-context.cluster dev-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 val...
Create a new pod named "hazelcast" using the php image and expose port 5000 in the container.
Command: ```bash kubectl run hazelcast --image=php --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": "--file...
Create a service called hazelcast that exposes the replicated hazelcast using a replica set
Command: ```bash kubectl expose rs hazelcast --port=9090 --target-port=8000 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port...
Copy the ~/.config/kube directory from the remote pod named 'load-balancer-pod-9' to the /etc/kubernetes directory locally.
Command: ```bash kubectl cp kube-node-lease/load-balancer-pod-9:~/.config/kube /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 om...
Access the raw terminal of a specific pod and execute commands interactively
Command: ```bash kubectl exec media-stream-pod -c stardust-shuttle -i -t -- bash -il ``` 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. I...
Add a taint with key 'dedicated' on nodes having label component=proxy
Command: ```bash kubectl taint node -l component=proxy dedicated=prod-node-5:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage"...
Create a new config map named log-config using specified files and keys
Command: ```bash kubectl create configmap log-config --from-file=properties=/path/to/data/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 conf...
Forward local port 5432 to port 8080 in the pod 'log-aggregator-pod' for listening.
Command: ```bash kubectl port-forward pod/log-aggregator-pod 5432: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...
Set the custom TLS server name to use for validation for the 'kube-cluster-2' cluster entry as 'dev-cluster'
Command: ```bash kubectl config set-cluster kube-cluster-2 --tls-server-name=dev-cluster ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certificat...
Add a taint with key 'hardware' and value 'testing-node-11:PreferNoSchedule' on nodes having the label 'myLabel'
Command: ```bash kubectl taint node -l myLabel hardware=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": "", "usage": "Ou...
Start a mongo pod named nginx with the specified image, but override the spec with a partial set of values parsed from JSON
Command: ```bash kubectl run nginx --image=mongo --overrides='{ "apiVersion": "v3.0.0", "spec": { ... } }' ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND...
import the SMTP_SERVER key from the env-vars config map into the deployment/notification-handler-deployment deployment
Command: ```bash kubectl set env --keys=SMTP_SERVER --from=configmap/env-vars 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...
Retrieve the snapshot logs from the container "security-service-pod-1" of the deployment "backend-microservice-deployment".
Command: ```bash kubectl logs deployment/backend-microservice-deployment -c security-service-pod-1 ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Help...
Auto scale the replication controller "api" with a target CPU utilization of 81%, allowing the number of pods to range from 1 to 6.
Command: ```bash kubectl autoscale rc api --max=6 --cpu-percent=81 ``` 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...
Expose the nginx deployment as a service on port 8082, with the containers listening on port 808400
Command: ```bash kubectl expose deployment nginx --port=8082 --target-port=808400 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specifie...
Execute the 'composer --version' command in the quantum-quark container from the pod named gateway-pod.
Command: ```bash kubectl exec gateway-pod -c quantum-quark -- composer --version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If om...
Create a deployment named 'monitoring' that runs the 'golang' image and exposes port '9092'.
Command: ```bash kubectl create deployment monitoring --image=golang --port=9092 ``` What it does: Create a deployment with the specified name. Syntax: `kubectl create deployment NAME --image=image -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One o...
Create a deployment named "api" with the "confluentinc/cp-kafka" image, and expose port 8083
Command: ```bash kubectl create deployment api --image=confluentinc/cp-kafka --port=8083 ``` 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 forma...
Create a new service account named fluentd
Command: ```bash kubectl create serviceaccount fluentd ``` What it does: Create a service account with the specified name. Syntax: `kubectl create serviceaccount NAME [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: json|yaml|name|go-te...
Define new exec auth plugin args for the "security-user" entry by executing the command "kubectl config set-credentials security-user --exec-arg=arg1 --exec-arg=arg2".
Command: ```bash kubectl config set-credentials security-user --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 to...
Forward local port 8000 to port 3000 in the pod named "cdn-service-pod"
Command: ```bash kubectl port-forward pod/cdn-service-pod 8000: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 au...
Update the pod named 'chat-app' with the annotation 'release-notes' and set its value to 'https://example.com/release-notes/v2.5.1', replacing any existing value
Command: ```bash kubectl annotate --overwrite pods chat-app release-notes='https://example.com/release-notes/v2.5.1' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs tha...
Create a new secret called "gcp-service-account-secret" using an environment file
Command: ```bash kubectl create secret generic gcp-service-account-secret --from-env-file=path/to/parameters.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 defaul...
Forward traffic from local ports 8088 and 6000 to ports 5000 and 6000 respectively, on a pod selected by the deployment named "api-server-deployment".
Command: ```bash kubectl port-forward deployment/api-server-deployment 8088 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...
Start a jenkins pod with custom spec values provided in a JSON format
Command: ```bash kubectl run nginx --image=jenkins --overrides='{ "apiVersion": "v1.1.0", "spec": { ... } }' ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMA...
Forward local port 5000 to port 8080 in the analytics-platform-deployment pod
Command: ```bash kubectl port-forward deployment/analytics-platform-deployment 5000 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 po...
Forward traffic from port 8888 on all addresses to port 8088 in the frontend-pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/frontend-pod 8888: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...
Create a new ClusterIP service named 'database-service-clusterip' that maps port 5001 on the service to port 8088 on the target
Command: ```bash kubectl create service clusterip database-service-clusterip --tcp=5001:8088 ``` 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...
Set specific keys from a config map to the environment variables of a deployment
Command: ```bash kubectl set env --keys=DEBUG_MODE --from=configmap/app-config-prod 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 ...
Open the 'loadbalancer-service' service in the 'sublime' editor
Command: ```bash KUBE_EDITOR="sublime" kubectl edit svc/loadbalancer-service ``` What it does: Edit a resource from the default editor. The edit command allows you to directly edit any API resource you can retrieve via the command-line tools. It will open the editor defined by your KUBE_EDITOR, or EDITOR environment v...
Create a pod disruption budget named notification-service-pdb that selects pods with the release=1.0.0 label and requires at least four of them to be available at any point in time
Command: ```bash kubectl create poddisruptionbudget notification-service-pdb --selector=release=1.0.0 --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-ava...
Partially update the 'prod-node-5' node by specifying the patch as a YAML file, with the new value of 'replicas' set to 3.
Command: ```bash kubectl patch node prod-node-5 -p $'spec:\n replicas: 3' ``` 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]` Helpful flags: "...
Embed certificate authority data for the on-prem-cluster cluster entry
Command: ```bash kubectl config set-cluster on-prem-cluster --embed-certs --certificate-authority=~/.kube/data-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 ...
List resources from a directory with a kustomization file
Command: ```bash kubectl get -k settings/ ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you will only see results in your...
Forward local port 5432 to port 3000 in the pod named "mypod"
Command: ```bash kubectl port-forward pod/mypod 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 will be selected automaticall...
Copy a file from a remote pod to a local directory
Command: ```bash kubectl cp ingress-nginx/admin-dashboard-pod-16:/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...
Start a pod named 'hazelcast' using the 'ethereum/client-go' image, and expose port 8181.
Command: ```bash kubectl run hazelcast --image=ethereum/client-go --port=8181 ``` 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: ...
Copy the file /tmp/foo from the pod metrics-exporter-pod-10 in the openfaas namespace and save it as /tmp/bar on the local machine.
Command: ```bash kubectl cp openfaas/metrics-exporter-pod-10:/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 the k...
Create a new config map named 'app-settings' using the specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap app-settings --from-file=conf=/path/to/configs/file1.txt --from-file=data=/path/to/properties/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 co...
Import the environment variables from the log-config config map into the load-balancer-deployment deployment, with a prefix of MYSQL_.
Command: ```bash kubectl set env --from=configmap/log-config --prefix=MYSQL_ 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 definitions ...
Create a deployment named jenkins-x using the jenkins image.
Command: ```bash kubectl create deployment jenkins-x --image=jenkins ``` 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: json|yaml...
Forward traffic from port 9090 on your local machine to port 8080 in the security-service-pod pod
Command: ```bash kubectl port-forward pod/security-service-pod 9090:8080 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be select...
Set the cluster field in the user-b-context context to edge-cluster
Command: ```bash kubectl config set contexts.user-b-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 value you w...
Add a taint with the key 'disktype' on nodes having the label environment=production
Command: ```bash kubectl taint node -l environment=production disktype=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": ""...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=API_KEY --from=configmap/namespace-config deployment/proxy-service-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definit...
Create a single ingress called 'public-ingress' that directs requests to foo.com/example to svc1:5432 with a tls secret named "my-cert"
Command: ```bash kubectl create ingress public-ingress --rule="foo.com/example=svc1:5432,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage...
Create a NodePort service named "e-commerce-nodeport" that forwards traffic from port 8082 on all cluster nodes to port 5001 on the corresponding Pod.
Command: ```bash kubectl create service nodeport e-commerce-nodeport --tcp=8082:5001 ``` What it does: Create a NodePort service with the specified name. Syntax: `kubectl create service nodeport NAME [--tcp=port:targetPort] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "default": ...
Scale the deployment named mysql to its current size, which is 3
Command: ```bash kubectl scale --current-replicas=3 --replicas=3 deployment/mysql ``` 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 sp...
Create an ingress called 'api-ingress' that directs requests from site.com/input to the service named 'svc1' on port 9092
Command: ```bash kubectl create ingress api-ingress --rule="site.com/input=svc1:9092,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "...
Copy a file named "foo" from a remote pod to your local machine, saving it as "bar" in the "/tmp" directory.
Command: ```bash kubectl cp prometheus/worker-pod-4:/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 the kubectl.k...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=api_key --from=configmap/env-vars 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 one or...
Execute the 'jenkins-plugin-cli' command inside the 'proxy-service-pod' pod, and retrieve the output from the first container
Command: ```bash kubectl exec proxy-service-pod -- jenkins-plugin-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, use ...