Created
April 9, 2019 05:59
-
-
Save ops-gaurav/2f26400d88698d6937faba175aacbaf6 to your computer and use it in GitHub Desktop.
Kubernetes notes
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
Kubernetes Deployments | |
- Minikube disto for kuberntes deployment (locally Linux Mac and Windows) (recommended for development and learning) use cloud for production | |
- Deployments are high level constructs that define an application | |
- Pods are instances of a container in a deployment | |
- Services are the endpoints that export ports to the outside world | |
Text Lecture: Minikube Setup | |
Commands | |
* Linux: | |
* | |
* curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl | |
* | |
* MacOS: | |
* | |
* curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/darwin/amd64/kubectl | |
* | |
* Windows: | |
* | |
* curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.8.0/bin/windows/amd64/kubectl.exe | |
* | |
* chmod +x ./kubectl | |
* sudo mv ./kubectl /usr/local/bin/kubectl | |
* kubectl version | |
* | |
* Linux: | |
* | |
* curl -Lo minikube https://storage.googleapis.com/minikube/releases/v0.23.0/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/ | |
* | |
* macOS: | |
* | |
* curl -Lo minikube https://storage.googleapis.com/minikube/releases/v0.23.0/minikube-darwin-amd64 && chmod +x | |
* minikube && sudo mv minikube /usr/local/bin/ | |
* minikube start | |
* kubectl run hello-minikube --image=gcr.io/google_containers/echoserver:1.4 --port=8080 | |
* kubectl expose deployment hello-minikube --type=NodePort | |
* kubectl get pod | |
* curl $(minikube service hello-minikube --url) | |
* kubectl delete deployment hello-minikube | |
* minikube stop | |
Trouble Shooting | |
Error 1 | |
* [root@larry ~]# minikube start | |
* Starting local Kubernetes v1.10.0 cluster... | |
* Starting VM... | |
* E0726 16:03:16.856132 3753 start.go:168] Error starting host: Error creating host: Error executing step: Running precreate checks. | |
* : This computer doesn't have VT-X/AMD-v enabled. Enabling it in the BIOS is mandatory. | |
* | |
* Retrying. | |
* E0726 16:03:16.856723 3753 start.go:174] Error starting host: Error creating host: Error executing step: Running precreate checks. | |
* : This computer doesn't have VT-X/AMD-v enabled. Enabling it in the BIOS is mandatory | |
Solution: | |
Run minikube start --vm-driver=none instead | |
Related Q&A: | |
https://www.udemy.com/kubernetes-from-a-devops-kubernetes-guru/learn/v4/questions/4793372 | |
Error 2 | |
* root@localhost ~]# minikube start | |
* Starting local Kubernetes v1.10.0 cluster... | |
* Starting VM... | |
* E0504 17:44:35.629203 9741 start.go:159] Error starting host: Error creating host: Error executing step: Running precreate checks. | |
* : VBoxManage not found. Make sure VirtualBox is installed and VBoxManage is in the path. | |
* Retrying. | |
* E0504 17:44:35.630354 9741 start.go:165] Error starting host: Error creating host: Error executing step: Running precreate checks. | |
* : VBoxManage not found. Make sure VirtualBox is installed and VBoxManage is in the path | |
Solution: | |
On Linux machines you do not need to use any VM Driver. | |
Run below command instead. | |
* ./minikube start --vm-driver=none | |
If you are not running Linux machines, Install VirtualBox on the VM. | |
Related Q&A: | |
https://www.udemy.com/kubernetes-from-a-devops-kubernetes-guru/learn/v4/questions/4207802 | |
https://www.udemy.com/kubernetes-from-a-devops-kubernetes-guru/learn/v4/questions/ | |
Kubelet is a supervisor for kubernetes processes -> manage nodes on on process | |
Kubeproxy -> handles network services like connecting app at port 80 is handled by kubeproxy | |
Cluster commands | |
1. kubectl run gateway --image=gcr.io/thesocialapp/gateway:latest --port=3000 | |
2. Kubectl get deployment | |
3. Kubectl get pods | |
4. Kubectl expose deployment gateway —type=“LoadBalancer” —port=5000 to expose the service | |
5. Kubectl get services gateway | |
6. Kubectl scale deployment gateway —replicas=4 | |
7. Kubectl get deployment | |
Getting clusters list and setting the default cluster for operation | |
- Creating a cluster | |
gcloud container clusters create [CLUSTER_NAME] | |
- Get the authentication credentials for the created cluster | |
gcloud container clusters get-credentials [CLUSTER_NAME] | |
Kubectl commands to run the Kubectl process (https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#run) | |
run NAME --image=image [--env="key=value"] [--port=port] [--replicas=replicas] [--dry-run=bool] [--overrides=inline-json] [--command] -- [COMMAND] [args...] | |
- Running the Kubectl process | |
kubectl run hello-server --image gcr.io/google-samples/hello-app:1.0 --port 8080 mention the port number that a process is exposing | |
- Exposing the deployment kubectl expose deployment hello-server --type LoadBalancer --port 80 --target-port 8080 | |
Here type is the deployment expose type. You can find more details about it here. (https://stackoverflow.com/a/41510604/2445898) | |
- Getting a specific cluster details kubectl get service hello-server | |
- Connecting with the pod shell kubectl exec -it [YOUR_POD_NAME] -- sh | |
- | |
gcloud config set container/cluster [CLUSTER_NAME] | |
Switching across clusters | |
1. Kubectl config view | |
2. Kubectl config current-context | |
3. Kubectl config use-context [cluster-name] | |
To see the pods logs | |
1. Kubectl get pods ——> will give the list of the pods running under the current-context | |
2. Kubectl logs [pod-name] ——> will give the console log of the requested pod. | |
gcloud container clusters get-credentials NAME [--internal-ip] [--region=REGION | --zone=ZONE, -z ZONE] [GCLOUD_WIDE_FLAG …] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment