-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pods
206 lines (204 loc) · 13.4 KB
/
Pods
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
A pod in Kubernetes is the smallest and simplest unit of work that Kubernetes manages. You can think of it as a box that holds your application.
Key Points:
Runs Containers: A pod usually runs one or more containers (like Docker containers), which are the actual applications.
One Application per Pod: Typically, one pod runs one application or a specific part of an application.
Short-Lived: Pods aren't permanent. If a pod crashes or finishes its job, Kubernetes can automatically create a new one.
Assigned to a Node: Pods run on nodes (which are like servers), and Kubernetes ensures they run efficiently.
Networking: Each pod gets its own internal IP address, allowing it to communicate with other pods or the outside world.
1. kubectl config get-contexts
To determine which namespace is associated with your current Kubernetes context.
----------------------------------------------------------------------------------------------
root@ip-172-31-25-43:/home/ubuntu# kubectl config get-contexts
CURRENT NAME CLUSTER AUTHINFO NAMESPACE
* kubernetes-admin@kubernetes kubernetes kubernetes-admin my-namespace
-----------------------------------------------------------------------------------------------
2. kubectl get pods
Lists all the pods in the current namespace. If no namespace is specified, it defaults to the 'default' namespace.
------------------------------------------------------------------------------------------------
root@ip-172-31-25-43:/home/ubuntu# kubectl get pods
NAME READY STATUS RESTARTS AGE
my-pod 1/1 Running 2 (4h6m ago) 2d19h
------------------------------------------------------------------------------------------------
3. kubectl get pod -o wide
It provides detailed information about the pods in your current namespace, including which node they are running on and other extended details.
-------------------------------------------------------------------------------------------------
root@ip-172-31-25-43:/home/ubuntu# kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
my-pod 1/1 Running 2 (4h59m ago) 2d20h 10.44.0.2 ip-172-31-26-203 <none> <none>
-------------------------------------------------------------------------------------------------
4. kubectl get pods --namespace=<namespace>
Lists all the pods in a specific namespace.
Example: kubectl get pods --namespace=my-namespace
------------------------------------------------------------------------------------------------
root@ip-172-31-25-43:/home/ubuntu# kubectl get pods --namespace=my-namespace
NAME READY STATUS RESTARTS AGE
my-pod 1/1 Running 2 (4h28m ago) 2d19h
------------------------------------------------------------------------------------------------
5. kubectl get pods --all-namespaces
To list all pods across all namespaces
-------------------------------------------------------------------------------------------------
root@ip-172-31-25-43:/home/ubuntu# kubectl get pods --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE
default nginx-demo 1/1 Running 5 (4h47m ago) 12d
kube-system coredns-6f6b679f8f-fzqqx 1/1 Running 5 (4h47m ago) 12d
kube-system coredns-6f6b679f8f-kznll 1/1 Running 5 (4h47m ago) 12d
kube-system etcd-ip-172-31-25-43 1/1 Running 5 (4h47m ago) 12d
kube-system kube-apiserver-ip-172-31-25-43 1/1 Running 5 (4h47m ago) 12d
kube-system kube-controller-manager-ip-172-31-25-43 1/1 Running 5 (4h47m ago) 12d
kube-system kube-proxy-29v2d 1/1 Running 5 (4h47m ago) 12d
kube-system kube-proxy-9pszf 1/1 Running 5 (4h47m ago) 12d
kube-system kube-proxy-lrqpv 1/1 Running 5 (4h47m ago) 12d
kube-system kube-scheduler-ip-172-31-25-43 1/1 Running 5 (4h47m ago) 12d
kube-system metrics-server-587b667b55-774k9 1/1 Running 0 135m
kube-system weave-net-9gpqz 2/2 Running 11 (4h47m ago) 12d
kube-system weave-net-dxvcz 2/2 Running 11 (4h47m ago) 12d
kube-system weave-net-pjjtt 2/2 Running 11 (4h47m ago) 12d
my-namespace my-pod 1/1 Running 2 (4h47m ago) 2d20h
-------------------------------------------------------------------------------------------------
6. kubectl get pods --all-namespaces -o wide
To list all pods across all namespaces and see which node they are running on.
-------------------------------------------------------------------------------------------------
root@ip-172-31-25-43:/home/ubuntu# kubectl get pods --all-namespaces -o wide
NAMESPACE NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
default nginx-demo 1/1 Running 5 (4h39m ago) 12d 10.44.0.1 ip-172-31-26-203 <none> <none>
kube-system coredns-6f6b679f8f-fzqqx 1/1 Running 5 (4h39m ago) 12d 10.32.0.2 ip-172-31-25-43 <none> <none>
kube-system coredns-6f6b679f8f-kznll 1/1 Running 5 (4h39m ago) 12d 10.32.0.3 ip-172-31-25-43 <none> <none>
kube-system etcd-ip-172-31-25-43 1/1 Running 5 (4h39m ago) 12d 172.31.25.43 ip-172-31-25-43 <none> <none>
kube-system kube-apiserver-ip-172-31-25-43 1/1 Running 5 (4h39m ago) 12d 172.31.25.43 ip-172-31-25-43 <none> <none>
kube-system kube-controller-manager-ip-172-31-25-43 1/1 Running 5 (4h39m ago) 12d 172.31.25.43 ip-172-31-25-43 <none> <none>
kube-system kube-proxy-29v2d 1/1 Running 5 (4h39m ago) 12d 172.31.21.7 ip-172-31-21-7 <none> <none>
kube-system kube-proxy-9pszf 1/1 Running 5 (4h39m ago) 12d 172.31.25.43 ip-172-31-25-43 <none> <none>
kube-system kube-proxy-lrqpv 1/1 Running 5 (4h39m ago) 12d 172.31.26.203 ip-172-31-26-203 <none> <none>
kube-system kube-scheduler-ip-172-31-25-43 1/1 Running 5 (4h39m ago) 12d 172.31.25.43 ip-172-31-25-43 <none> <none>
kube-system metrics-server-587b667b55-774k9 1/1 Running 0 128m 10.44.0.3 ip-172-31-26-203 <none> <none>
kube-system weave-net-9gpqz 2/2 Running 11 (4h39m ago) 12d 172.31.25.43 ip-172-31-25-43 <none> <none>
kube-system weave-net-dxvcz 2/2 Running 11 (4h39m ago) 12d 172.31.21.7 ip-172-31-21-7 <none> <none>
kube-system weave-net-pjjtt 2/2 Running 11 (4h39m ago) 12d 172.31.26.203 ip-172-31-26-203 <none> <none>
my-namespace my-pod 1/1 Running 2 (4h39m ago) 2d20h 10.44.0.2 ip-172-31-26-203 <none> <none>
-----------------------------------------------------------------------------------------------
7. kubectl describe pod <pod-name>
Provides detailed information about a specific pod, including its events, status, and configurations.
Example: kubectl describe pod my-pod
-----------------------------------------------------------------------------------------------
root@ip-172-31-25-43:/home/ubuntu# kubectl describe pod my-pod
Name: my-pod
Namespace: my-namespace
Priority: 0
Service Account: default
Node: ip-172-31-26-203/172.31.26.203
Start Time: Mon, 16 Sep 2024 14:47:40 +0000
Labels: app=my-app
Annotations: <none>
Status: Running
IP: 10.44.0.2
IPs:
IP: 10.44.0.2
-----------------------------------------------------------------------------------------------
8. kubectl logs <pod-name>
Fetches logs from a specific pod, useful for debugging issues.
Example: kubectl logs my-pod
-----------------------------------------------------------------------------------------------
root@ip-172-31-25-43:/home/ubuntu# kubectl logs my-pod
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Sourcing /docker-entrypoint.d/15-local-resolvers.envsh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
2024/09/19 06:17:58 [notice] 1#1: using the "epoll" event method
2024/09/19 06:17:58 [notice] 1#1: nginx/1.27.1
2024/09/19 06:17:58 [notice] 1#1: built by gcc 12.2.0 (Debian 12.2.0-14)
2024/09/19 06:17:58 [notice] 1#1: OS: Linux 6.8.0-1015-aws
2024/09/19 06:17:58 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
2024/09/19 06:17:58 [notice] 1#1: start worker processes
2024/09/19 06:17:58 [notice] 1#1: start worker process 29
---------------------------------------------------------------------------------------------
9. kubectl exec <pod-name> -- <command>
Runs a command inside a running pod, similar to SSHing into a server.
Example: kubectl exec my-pod -- ls
--------------------------------------------------------------------------------------------
root@ip-172-31-25-43:/home/ubuntu# kubectl exec my-pod -- ls
bin
boot
dev
docker-entrypoint.d
docker-entrypoint.sh
etc
home
lib
lib64
media
mnt
opt
proc
root
run
sbin
srv
sys
tmp
usr
var
-----------------------------------------------------------------------------------------
10. Execute a command inside a running pod interactively:
kubectl exec <pod-name> -it -- <command>
Example: kubectl exec my-pod -it -- /bin/bash
-----------------------------------------------------------------------------------------
root@ip-172-31-25-43:/home/ubuntu# kubectl exec my-pod -it -- /bin/bash
root@my-pod:/# ls -lrth
total 64K
drwxr-xr-x 2 root root 4.0K Aug 14 16:10 home
drwxr-xr-x 2 root root 4.0K Aug 14 16:10 boot
drwxr-xr-x 1 root root 4.0K Sep 4 09:00 var
drwxr-xr-x 1 root root 4.0K Sep 4 09:00 usr
drwxrwxrwt 2 root root 4.0K Sep 4 09:00 tmp
drwxr-xr-x 2 root root 4.0K Sep 4 09:00 srv
lrwxrwxrwx 1 root root 8 Sep 4 09:00 sbin -> usr/sbin
drwxr-xr-x 2 root root 4.0K Sep 4 09:00 opt
drwxr-xr-x 2 root root 4.0K Sep 4 09:00 mnt
drwxr-xr-x 2 root root 4.0K Sep 4 09:00 media
lrwxrwxrwx 1 root root 9 Sep 4 09:00 lib64 -> usr/lib64
lrwxrwxrwx 1 root root 7 Sep 4 09:00 lib -> usr/lib
lrwxrwxrwx 1 root root 7 Sep 4 09:00 bin -> usr/bin
-rwxr-xr-x 1 root root 1.6K Sep 4 23:10 docker-entrypoint.sh
drwxr-xr-x 1 root root 4.0K Sep 4 23:11 docker-entrypoint.d
dr-xr-xr-x 13 root root 0 Sep 19 06:17 sys
dr-xr-xr-x 191 root root 0 Sep 19 06:17 proc
drwxr-xr-x 1 root root 4.0K Sep 19 06:17 etc
drwxr-xr-x 5 root root 360 Sep 19 06:17 dev
drwxr-xr-x 1 root root 4.0K Sep 19 06:17 run
drwx------ 1 root root 4.0K Sep 19 11:25 root
------------------------------------------------------------------------------------
11. kubectl top pod <pod-name>
Shows CPU and memory usage of a pod.
Example: kubectl top pod my-pod
------------------------------------------------------------------------------------
root@ip-172-31-25-43:/home/ubuntu# kubectl top pod my-pod
NAME CPU(cores) MEMORY(bytes)
my-pod 0m 4Mi
------------------------------------------------------------------------------------
12. kubectl get pods -w
Watch Pod Status in Real-Time
Continuously monitor pod status changes, such as pods starting, terminating, or moving between states.
-------------------------------------------------------------------------------------
root@ip-172-31-25-43:/home/ubuntu# kubectl get pods -w
NAME READY STATUS RESTARTS AGE
my-pod 1/1 Running 2 (4h33m ago) 2d20h
-------------------------------------------------------------------------------------
13. kubectl delete pod <pod-name>
Deletes a pod from the cluster. The pod will be restarted if it’s part of a deployment or replica set.
Example: kubectl delete pod my-pod
------------------------------------------------------------------------------------
root@ip-172-31-25-43:/home/ubuntu# kubectl get pods
NAME READY STATUS RESTARTS AGE
my-pod 1/1 Running 2 (5h9m ago) 2d20h
root@ip-172-31-25-43:/home/ubuntu#
root@ip-172-31-25-43:/home/ubuntu# kubectl delete pod my-pod
pod "my-pod" deleted
root@ip-172-31-25-43:/home/ubuntu#
root@ip-172-31-25-43:/home/ubuntu# kubectl get pods
No resources found in my-namespace namespace.
------------------------------------------------------------------------------------