prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Delete a cluster named cluster-beta from the kubectl configuration.
Command: ```bash kubectl config delete-cluster cluster-beta ``` What it does: Delete the specified cluster from the kubeconfig. Syntax: `kubectl config delete-cluster NAME`
Create an ingress configuration called 'default-ingress' that will route requests from testing.com/input to service svc1:8081
Command: ```bash kubectl create ingress default-ingress --rule="testing.com/input=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": "", "us...
Set environment variables in a deployment using the values from a config map, with a specific prefix.
Command: ```bash kubectl set env --from=configmap/ui-config --prefix=MYSQL_ 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 definiti...
Listen on port 9090 on your local machine and forward data to port 8888 in the 'mypod' pod.
Command: ```bash kubectl port-forward pod/mypod 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 will be selected automaticall...
Set cpu and memory limits for the jenkins container in a deployment
Command: ```bash kubectl set resources deployment jenkins -c=nginx --limits=cpu=50m,memory=512Mi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requested, but may burst up t...
Wait until the pod "mypod" has the status condition of type "Ready".
Command: ```bash kubectl wait --for=condition=Ready pod/mypod ``` What it does: Experimental: Wait for a specific condition on one or many resources. The command takes multiple resources and waits until the specified condition is seen in the Status field of every given resource. Alternatively, the command can wait for...
Create a cron job named "database-maintenance" that runs the command "java -jar /usr/share/jenkins/jenkins.war" every minute.
Command: ```bash kubectl create cronjob database-maintenance --image=jenkins --schedule="*/1 * * * *" -- java -jar /usr/share/jenkins/jenkins.war ``` What it does: Create a cron job with the specified name. Syntax: `kubectl create cronjob NAME --image=image --schedule='0/5 * * * ?' -- [COMMAND] [args...]` Helpful fl...
Create a copy of the media-stream-pod and change all container images to postgres
Command: ```bash kubectl debug media-stream-pod --copy-to=dgb-img --set-image=*=postgres ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used by default if no resou...
Copy the file /tmp/foo from the remote pod 'kubeapps/auth-service-pod-11' to the local directory /tmp/bar.
Command: ```bash kubectl cp kubeapps/auth-service-pod-11:/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 kube...
Copy the local file /tmp/foo to the remote pod logging/file-server-pod-14 in the /tmp/bar_dir directory.
Command: ```bash kubectl cp :/tmp/foo logging/file-server-pod-14:/tmp/bar_dir ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the ku...
Set up the on-prem-cluster cluster entry with embedded certificate authority data
Command: ```bash kubectl config set-cluster on-prem-cluster --embed-certs --certificate-authority=~/.kube/e2e/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-clust...
Set the cluster field in the 'my-context' context to 'cluster-beta'
Command: ```bash kubectl config set contexts.edge-context.cluster cluster-beta ``` 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 wan...
Port forward all traffic on port 8080 to port 8000 in the 'analytics-pod' pod. Listen on all addresses (0.0.0.0)
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/analytics-pod 8080:8000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod wil...
Create an ingress with a rule that directs requests to a specific domain and path to a service, and use a TLS secret for encryption.
Command: ```bash kubectl create ingress service-ingress --rule="site.com/input=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": "", "usage...
Delete a cluster named "staging-cluster"
Command: ```bash kubectl config delete-cluster staging-cluster ``` What it does: Delete the specified cluster from the kubeconfig. Syntax: `kubectl config delete-cluster NAME`
Create a job called "deployment-rollout-job" using the "node" image. The job will run the command "node --version"
Command: ```bash kubectl create job deployment-rollout-job --image=node -- node --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": "Out...
Create a copy of the 'payment-gateway-pod' pod and change all container images to 'python' in the newly created 'debug-image-web' pod.
Command: ```bash kubectl debug payment-gateway-pod --copy-to=debug-image-web --set-image=*=python ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used by default if...
Forward traffic from port 8080 on localhost and IP 10.19.21.23 to port 8080 in the pod named "cdn-service-pod"
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/cdn-service-pod 8080: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 cri...
Check if you have permission to list the job named "report-generation-job" in the "monitoring" namespace
Command: ```bash kubectl auth can-i list jobs.batch/report-generation-job -n monitoring ``` 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 parti...
Change the service account of the deployment "user-management-deployment" to "flux"
Command: ```bash kubectl set serviceaccount deployment user-management-deployment flux ``` 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...
Create a new config map named 'kube-system-config' with the specified keys and file paths for the 'conf' and 'data' keys
Command: ```bash kubectl create configmap kube-system-config --from-file=conf=/path/to/settings/file1.txt --from-file=data=/path/to/data/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...
Add a taint with key 'special' and no value to the node 'db-node-7'
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: jso...
Forward local port 6379 to port 3000 in the pod named proxy-server-pod for data communication
Command: ```bash kubectl port-forward pod/proxy-server-pod 6379 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...
Create a service for a replicated CentOS deployment that serves on port 9092 and connects to the containers on port 818100.
Command: ```bash kubectl expose rc centos --port=9092 --target-port=818100 ``` 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 /var/run/secrets/kubernetes.io/serviceaccount/ directory from the remote pod named web-app-pod-1 in the namespace istio-system to the local /etc/kubernetes directory.
Command: ```bash kubectl cp istio-system/web-app-pod-1:/var/run/secrets/kubernetes.io/serviceaccount/ /etc/kubernetes ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage":...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=LOG_LEVEL --from=configmap/ui-config deployment/mydeployment ``` 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 mo...
Create a deployment named my-dep using the nginx image, and expose port 5001.
Command: ```bash kubectl create deployment my-dep --image=nginx --port=5001 ``` 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...
Forward traffic from a random port on your local machine to port 5000 in the pod named security-service-pod.
Command: ```bash kubectl port-forward pod/security-service-pod :5000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected a...
Create a copy of the backend-pod and change all container images to "node". Name the copy "my-debugger".
Command: ```bash kubectl debug backend-pod --copy-to=my-debugger --set-image=*=node ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used by default if no resource i...
Create a service for the replicated alpine pods, serving on port 9091 and connecting to the containers on port 808900.
Command: ```bash kubectl expose rc alpine --port=9091 --target-port=808900 ``` 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....
Listen on port 8081 on your local machine and forward all traffic to the targetPort of the service named "https" in a pod selected by the service named "api-service".
Command: ```bash kubectl port-forward service/api-service 8081:https ``` 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...
Create a service for the replicated 'ubuntu' using the replica set, which serves on port 5432 and connects to the containers on port 808100.
Command: ```bash kubectl expose rs ubuntu --port=5432 --target-port=808100 ``` 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....
Forward local traffic to a specific pod port
Command: ```bash kubectl port-forward pod/cdn-service-pod :8000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automa...
create a cron job named "email-notifications" using the alpine image
Command: ```bash kubectl create cronjob email-notifications --image=alpine --schedule="*/1 * * * *" -- apk add curl ``` 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", "shor...
Update pod 'database' by adding a label with key 'component' and value 'web'
Command: ```bash kubectl label pods database component=web ``` 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":...
Update the pod identified by the type and name specified in the "settings.json" file by adding the annotation 'deployment-script' with the value 'https://example.com/deploy.sh'
Command: ```bash kubectl annotate -f settings.json deployment-script='https://example.com/deploy.sh' ``` 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 ...
Create a copy of the api-service-pod and add a debug container with the debian image
Command: ```bash kubectl debug api-service-pod -it --copy-to=debug-image-api --image=debian --set-image=scheduler=my-scheduler:1.0,worker=my-custom-worker:1.2.3 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects i...
Create a new secret named aws-credentials-secret from an env file
Command: ```bash kubectl create secret generic aws-credentials-secret --from-env-file=path/to/configurations.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...
Create a deployment named monitoring using the confluentinc/cp-kafka image and expose port 9091.
Command: ```bash kubectl create deployment monitoring --image=confluentinc/cp-kafka --port=9091 ``` 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": "Outpu...
Retrieve the snapshot logs from container "auth-service-pod-1" in the deployment "proxy-service-deployment".
Command: ```bash kubectl logs deployment/proxy-service-deployment -c auth-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]` Helpful flags: ...
Update the image of all containers in the daemonset "development" to "ubuntu:20.04"
Command: ```bash kubectl set image daemonset development *=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: ...
Import specific keys from a config map into a deployment's environment variables.
Command: ```bash kubectl set env --keys=my-example-key --from=configmap/app-config deployment/backend-microservice-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable...
Copy the service account file from a remote pod to the local /etc/kubernetes directory.
Command: ```bash kubectl cp istio-system/monitoring-agent-pod-6:/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": "",...
Display the replication controller with the name 'web', the service with the name 'web-app-rc', and the pod with the name 'media-stream-pod'
Command: ```bash kubectl get rc/web service/web-app-rc pods/media-stream-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 namespace...
Update the 'proxy' pod with the annotation 'git-repo' and set its value to 'https://github.com/example/my-app'.
Command: ```bash kubectl annotate pods proxy 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 labels...
Copy the directory '/tmp/foo_dir' from the remote pod 'velero/logging-agent-pod-7' to the local directory '/etc/kubernetes'
Command: ```bash kubectl cp velero/logging-agent-pod-7:/tmp/foo_dir /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 ...
Add a label to the pod named 'payment' with the label 'env' and the value 'staging'
Command: ```bash kubectl label pods payment env=staging ``` 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...
Create a new config map named app-settings and populate it with the specified keys and corresponding file contents.
Command: ```bash kubectl create configmap app-settings --from-file=properties=/path/to/profiles/file1.txt --from-file=key1=/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 creati...
Create a copy of the "monitoring-pod" with a debug container, using the "debian" image
Command: ```bash kubectl debug monitoring-pod -it --copy-to=dgb-img --image=debian --set-image=web=nginx:latest,cache=redis:alpine ``` 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...
Set the service account of the 'backend-microservice-deployment' deployment to 'prometheus'.
Command: ```bash kubectl set serviceaccount deployment backend-microservice-deployment prometheus ``` 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...
Begin streaming the logs of the "code-explorer" container in the "media-stream-pod" pod.
Command: ```bash kubectl logs -f -c code-explorer media-stream-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"...
Forward traffic from port 5000 on your local machine to port 8081 in the cdn-service-pod pod
Command: ```bash kubectl port-forward pod/cdn-service-pod 5000:8081 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected au...
Create a pod disruption budget named logging-pdb that will select all pods with the project=my-project label and ensure that at least one of them is available at any point in time.
Command: ```bash kubectl create poddisruptionbudget logging-pdb --selector=project=my-project --min-available=1 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-available=N...
Copy the local file ~/.config/kube to the remote pod 'file-server-pod-14' in the container 'task-processor' under the directory /etc/kubernetes.
Command: ```bash kubectl cp ~/.config/kube file-server-pod-14:/etc/kubernetes -c task-processor ``` 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 o...
Add a taint with key 'datacenter' on nodes having the label service=auth and set the taint value to prod-node-5:PreferNoSchedule
Command: ```bash kubectl taint node -l service=auth datacenter=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": ...
Add a taint to a specific node
Command: ```bash kubectl taint nodes k8s-node-1 zone: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: json|...
Forward port 5432 on your local machine to port 8081 in the backend-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...
Show the difference between the current state of resources and the resources specified in pod.json file.
Command: ```bash kubectl diff -f pod.json ``` What it does: Diff configurations specified by file name or stdin between the current online configuration, and the configuration as it would be if applied. The output is always YAML. KUBECTL_EXTERNAL_DIFF environment variable can be used to select your own diff command. U...
Set the cluster field of the local-context context to prod-cluster.
Command: ```bash kubectl config set contexts.local-context.cluster prod-cluster ``` What it does: Set an individual value in a kubeconfig file. PROPERTY_NAME is a dot delimited name where each token represents either an attribute name or a map key. Map keys may not contain dots. PROPERTY_VALUE is the new value you wa...
Create a new NodePort service named web-app-nodeport that maps port 8443 on the cluster nodes to port 8082 on the pods.
Command: ```bash kubectl create service nodeport web-app-nodeport --tcp=8443:8082 ``` 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": "",...
Listen on all addresses at port 5000 and forward the traffic to the pod with the name 'e-commerce-pod' at port 9090.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/e-commerce-pod 5000:9090 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod wi...
Set the resource request and limits for all containers in a Python deployment
Command: ```bash kubectl set resources deployment python --limits=cpu=200m,memory=512Mi --requests=cpu=10,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 requeste...
Create a role named "default_role" with the ability to delete pods and specific resource names such as "payment-processor" and "prod-api-gateway".
Command: ```bash kubectl create role default_role --verb=delete --resource=pods --resource-name=payment-processor --resource-name=prod-api-gateway ``` What it does: Create a role with single rule. Syntax: `kubectl create role NAME --verb=verb --resource=resource.group/subresource [--resource-name=resourcename] [--dry...
Create an ingress named 'myapp-ingress' that routes requests to website.com/bar to a service named 'svc1' on port 8443, with the TLS secret 'my-cert'.
Command: ```bash kubectl create ingress myapp-ingress --rule="website.com/bar=svc1:8443,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"...
Begin streaming the logs of the "warp-drive" container in the "auth-service-pod" pod
Command: ```bash kubectl logs -f -c warp-drive auth-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", "...
Update the annotation 'custom-label' of the pod 'analytics' with the value 'my-custom-value'
Command: ```bash kubectl annotate pods analytics custom-label=my-custom-value ``` 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...
Scale the replica set named 'webapp-replicaset' to 7 replicas.
Command: ```bash kubectl scale --replicas=7 rs/webapp-replicaset ``` What it does: Set a new size for a deployment, replica set, replication controller, or stateful set. Scale also allows users to specify one or more preconditions for the scale action. If --current-replicas or --resource-version is specified, it is va...
Attach to a specific container in a pod and start a session with it
Command: ```bash kubectl attach mypod -c nebula-navigator ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use t...
Embed the certificate authority data for the cluster entry 'prod-cluster' by running the command 'kubectl config set-cluster prod-cluster --embed-certs --certificate-authority=~/.kube/cluster-gamma/kubernetes.ca.crt'
Command: ```bash kubectl config set-cluster prod-cluster --embed-certs --certificate-authority=~/.kube/cluster-gamma/kubernetes.ca.crt ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config se...
Create a service based on the specifications in the "hazelcast-controller.yaml" file, listening on port 8082 and connecting to the containers on port 543200.
Command: ```bash kubectl expose -f hazelcast-controller.yaml --port=8082 --target-port=543200 ``` 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 ...
Create a pod named "nginx" with the image "wordpress"
Command: ```bash kubectl run nginx --image=wordpress ``` 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": "--filename", "sh...
Partially update a node by applying a strategic merge patch in JSON format
Command: ```bash kubectl patch node monitoring-node-15 -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-f...
Get the phase value of the email-service-pod pod
Command: ```bash kubectl get -o template pod/email-service-pod --template={{.status.phase}} ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource ty...
Create a new config map named log-config with specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap log-config --from-file=properties=/path/to/configurations/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 creat...
import the 'SECRET_KEY' key from the 'ui-config' config map to the 'user-management-deployment' deployment
Command: ```bash kubectl set env --keys=SECRET_KEY --from=configmap/ui-config deployment/user-management-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 definitio...
Forward local traffic on ports 8088 and 6000 to a pod selected by the 'web-app-deployment' deployment, forwarding data to/from ports 8080 and 6000.
Command: ```bash kubectl port-forward deployment/web-app-deployment 8088 8080 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be s...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=smtp_server --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 defini...
Retrieve the snapshot logs from a specific container within a deployment
Command: ```bash kubectl logs deployment/email-server-deployment -c web-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: "flag"...
Forward traffic from port 8888 on all addresses to port 8088 inside the pod named 'api-service-pod'
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/api-service-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 w...
Create a new secret named payment-gateway-secret with keys for each file in folder bar.
Command: ```bash kubectl create secret generic payment-gateway-secret --from-file=path/to/properties ``` 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...
Listen on port 5432 on all addresses, forwarding to port 3000 in the 'proxy-server-pod' pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/proxy-server-pod 5432:3000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod ...
Retrieve the snapshot logs from container api-server-deployment-1 in the web-app-pod deployment.
Command: ```bash kubectl logs deployment/api-server-deployment -c web-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: "flag": ...
Create a job to run a command
Command: ```bash kubectl create job log-processing-job --image=ethereum/client-go -- geth attach ``` 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...
Import environment variables prefixed with MYSQL_ from the config map "app-config" into the deployment "api-server-deployment"
Command: ```bash kubectl set env --from=configmap/app-config --prefix=MYSQL_ 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 ...
Set the custom TLS server name "prod-cluster" for the web-cluster cluster entry.
Command: ```bash kubectl config set-cluster web-cluster --tls-server-name=prod-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-...
Rename a context in your kubeconfig file
Command: ```bash kubectl config rename-context cloud-context admin-context ``` What it does: Renames a context from the kubeconfig file. CONTEXT_NAME is the context name that you want to change. NEW_NAME is the new name you want to set. Note: If the context being renamed is the 'current-context', this field will also ...
Start a python pod with the container exposing port 8083.
Command: ```bash kubectl run hazelcast --image=python --port=8083 ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args...]` Helpful flags: "flag": "--f...
Create a new configmap named app-config-dev using the specified files as values for the keys
Command: ```bash kubectl create configmap app-config-dev --from-file=settings=/path/to/settings/file1.txt --from-file=key2=/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 cr...
Execute the 'jenkins-plugin-cli' command in the 'api-service-pod' and fetch the output.
Command: ```bash kubectl exec api-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 th...
Expose a service for the replicated centos, serving on port 5001 and connecting to the containers on port 300000.
Command: ```bash kubectl expose rc centos --port=5001 --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....
Add a taint to the node 'db-node-7' with the key 'cpu-type' and no value
Command: ```bash kubectl taint nodes db-node-7 cpu-type: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...
Restart the 'namespace-1' deployment
Command: ```bash kubectl rollout restart deployment/namespace-1 ``` What it does: Restart a resource. Resource rollout will be restarted. Syntax: `kubectl rollout restart RESOURCE` Helpful flags: "flag": "--filename", "short": "-f", "default": "[]", "usage": "Filename, directory, or URL to files identifying the reso...
Create a deployment named 'cache' using the 'ethereum/client-go' image
Command: ```bash kubectl create deployment cache --image=ethereum/client-go ``` 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...
Set the CPU and memory limits for the PHP container in the deployment named "php" to 100m and 256Mi respectively.
Command: ```bash kubectl set resources deployment php -c=nginx --limits=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 requested, but may burst up to i...
Create a new config map named 'monitoring-config' using the specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap monitoring-config --from-file=conf=/path/to/options/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...
Forward traffic from port 9090 on localhost and IP 10.19.21.23 to port 5000 in the pod named "frontend-pod"
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/frontend-pod 9090: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 criter...
Create an ingress rule that directs requests from testing.com/input to svc1:3000 with tls secret "my-cert"
Command: ```bash kubectl create ingress private-api-ingress --rule="testing.com/input=svc1:3000,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 a new ExternalName service named 'external-logging-service' with the external name 'blog-test.blog'
Command: ```bash kubectl create service externalname external-logging-service --external-name blog-test.blog ``` 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 servi...
Import environment variables from a config map with a specific prefix for a deployment.
Command: ```bash kubectl set env --from=configmap/global-config --prefix=MYSQL_ deployment/web-app-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in ...
Create a new ClusterIP service named 'backend-service-clusterip', which maps the port 8083 on the service to port 8083 on the backend pods.
Command: ```bash kubectl create service clusterip backend-service-clusterip --tcp=8083:8083 ``` 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"...