Last active
August 27, 2021 03:24
-
-
Save joshuaquek/bbb2a8e31663bff561aaf5de7d7d1cd3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Summary: Useful Kubectl commands for deploying & managing apps in a Kubernetes cluster (Minikube as example) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
## Deploy a simple dummy echo service | |
kubectl create deployment hello-minikube1 --image=k8s.gcr.io/echoserver:1.3 | |
## Expose the service via a NodePort and map the internal port 8080 to an external port, which is generated when the command is executed | |
kubectl expose deployment hello-minikube1 --type=NodePort --port 8080 | |
## Minikube does not support LoadBalancers, so this example ends here | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
## Deploy a simple dummy echo service | |
kubectl create deployment hello-minikube1 --image=k8s.gcr.io/echoserver:1.3 | |
## Expose the service via a NodePort and map the internal port 8080 to an external port, which is generated when the command is executed | |
kubectl expose deployment hello-minikube1 --type=NodePort --port 8080 | |
## Get the generated external port and echo it | |
export NODE_PORT=$(kubectl get services hello-minikube1 -o go-template='{{(index .spec.ports 0).nodePort}}') | |
echo NODE_PORT=$NODE_PORT | |
## Curl the exposed port | |
curl $(minikube ip):$NODE_PORT | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
export POD_NAME=$(kubectl get pods -o go-template --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}') | |
kubectl label pod $POD_NAME app=v1 | |
kubectl describe pods $POD_NAME | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
## Delete the pod | |
kubectl delete service -l run=hello-minikube1 | |
## Confirm that the pod is deleted | |
curl $(minikube ip):$NODE_PORT | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
## Scale up the number of instances to 4 replicasets within the Pod | |
kubectl scale deployments hello-minikube1 --replicas=4 | |
## Check that the ReplicaSets were scaled up to 4 | |
kubectl get deployments | |
kubectl get pods -o wide | |
## Note: A NodePort is able to load balance between the replicasets automatically | |
## Scale down the number of instances to 2 replicasets within the Pod | |
kubectl scale deployments hello-minikube1 --replicas=2 | |
## Check that the ReplicaSets were scaled down to 2 | |
kubectl get deployments | |
kubectl get pods -o wide | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
## Update image from version echoserver:1.3 to echoserver:1.4 | |
kubectl set image deployments hello-minikube1 hello-minikube1=k8s.gcr.io/echoserver:1.4 | |
## Check Rolling Update Status | |
kubectl rollout status deployments hello-minikube1 | |
## Performing a Rollback/Undo for a Rolling Update | |
kubectl rollout undo deployments/kubernetes-bootcamp | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment