-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKubernetes.txt
More file actions
188 lines (119 loc) · 4.96 KB
/
Kubernetes.txt
File metadata and controls
188 lines (119 loc) · 4.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
@@@@@@@@@@@@@@@@@@@ KUBERNETES (UDEMY) @@@@@@@@@@@@@@@@@@@@@@
Commands
kubectl --namespace=acp-system scale deployment acp-upgrade --replicas=0
$ kubectl get nodes
$ kubectl get events
$ kubectl config get-contexts
$ kubectl config use-context <context-name>
$ kubectl run <deployment-name> --image=<image-location> --port=<port-num>
$ kubectl expose deployment <deployment-name> --type=NodePort
$ kubectl explain
Kubernetes Structure:
1) 'kubectl' is entry to Kubernetes cluster
2) Controller Manager controls cluster-level functions
3) Scheduler talks to nodes to allocate resources
4) nodes then host pods
5) kube-proxy runs on each node and controls the network on nodes
6) pods then have groups of docker containers in them
7) docker containers share the same logical volume
Definitions:
POD: A group of coordinating containers. It's the smallest unit the Scheduler
understands. The containers within the pod share some context and interact,
directly or indirectly, with each other.
NODES: Closely associated with machines no network
SERVICES:
KUBE-PROXY: Manages network access on a node. Controls access to services on
the node. It also does load balancing.
SCHEDULER: Which Nodes have available resources and runs Pods on them.
CONTROLLER MANAGER: controls all other cluster level functions
KUBECTL: Talks to REST endpoint (Scheduler/Controller Mgr) to make it do
things
=============== KUBERNETES 101 ==============
- Kubernetes have 2 _types_ of nodes: HEAD Node and WORKER Nodes
- What's in a HEAD node?
-----------
* API Server: Exposes APIs
* Scheduler: Decides where to schedule pods, on which m/c etc
* Controller Manager: Makes sure state of cluster in right shape
* Etcd: Storage. It's possible etcd is outside the cluster
* Sometimes:
- kubelet: agent running on HEAD. Managed by systemd
- docker
- kubelet config is in /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
- Manifest files will be (usually) in: /etc/kubernetes/manifests/
* bunch of YAML files in this directory
- What's in WORKER node? Lots of them.
-----------
* kubelet: agent running on all WORKER nodes. It talks to API server on
HEAD and local docker containers to manage them
* kube-proxy: manages IP tables in that node
* docker
POD:
- Lowest unit of computing maintained by kubectl
Installing Kubernetes (3 techniques)
----
- First install kubectl (brew install kubectl on MacOS)
- minikube
- GKE (Google Kubernetes Engine)
- kubeadm
COMMANDS
--------
$ systemctl status kubelet # gives status of kubernetes on that node
$ minikube start
$ minikube status
$ kubectl version
$ kubectl get nodes
$ kubectl get pods
$ kubectl delete pod <pod-name>
$ kubectl -v=9 [command] // very verbose. Underlying call is 'curl'
$ kubectl api-version // gives all api GROUPS in the cluster
$ kubectl label pods <pod-name> [key=value] // key: value will sit in metadata
// of the pod
$ kubectl get pods label <pod-name> // returns all labels of the pod
$ kubectl get rs // gets replicasets
$ kubectl scale rs <replicaset-name> --replicas=<number>
kubectl get deployments
kubectl get deployment <my-dep>
kubectl get nodes
kubectl get pods --all-namespaces
// debug command if pod fails to get deployed
kubectl describe pod <pod-name>
//
kubectl describe deployment <pod-name/deployment-name>
// deploy an image
kubectl run <depl-name> --image=<image-location>
// get top level status of pods
kubectl get pods
// more info about a pod
kubectl describe pod <pod-name>
kubectl logs <pod-name>
// if a pod is restarted, previous logs can still be seen as
kubectl logs <pod-name> --previous
kubectl create configmap <name> --from-file=<directory or file>
kubectl describe configmap <name>
kubectl get deployments
kubectl get deployment <name> -o yaml
kubectl get configmaps
kubectl get configmap <name> -o yaml
kubectl scale deploy <deployment-name> --replicas=<number>
[1] https://kubernetes.io/docs/reference/kubectl/cheatsheet/
[1] Safari Books Online: Kubernetes Fundamentals - Sebastien Goasguen
[2] kubernetes.io
[3] cncf.io
[4] github.io/kubernetes-incubator
Resources:
[1] O'Reilly Kubernetes Bootcamp: Get up to speed with Docker and Kubernetes -
Zed Shaw
@@@@@@@@@@@@@@@@@@@ KUBERNETES CHEAT SHEET @@@@@@@@@@@@@@@@@@
Kubectl Autocomplete
BASH
source <(kubectl completion bash) # set up autocomplete in bash into the current shell, bash-completion package should be installed first.
echo "source <(kubectl completion bash)" >> ~/.bashrc # add autocomplete permanently to your bash shell.
Shorthand alias for kubectl
alias k=kubectl
complete -o default -F __start_kubectl
ZSH
source <(kubectl completion zsh) # set up autocomplete in zsh into the current shell
echo '[[ $commands[kubectl] ]] && source <(kubectl completion zsh)' >> ~/.zshrc # add autocomplete permanently to your zsh shell
Resource:
https://kubernetes.io/docs/reference/kubectl/cheatsheet/