当前位置:网站首页>〖Kubernetes指南④〗Pod快速入门
〖Kubernetes指南④〗Pod快速入门
2022-06-12 23:05:00 【步尔斯特】
Pod是kubernetes集群进行管理的最小单元,程序要运行必须部署在容器中,而容器必须存在于Pod中。
Pod可以认为是容器的封装,一个Pod中可以存在一个或者多个容器。

kubernetes在集群启动之后,集群中的各个组件也都是以Pod方式运行的。可以通过下面命令查看:
[[email protected] ~]# kubectl get pod -n kube-system
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system coredns-6955765f44-68g6v 1/1 Running 0 2d1h
kube-system coredns-6955765f44-cs5r8 1/1 Running 0 2d1h
kube-system etcd-master 1/1 Running 0 2d1h
kube-system kube-apiserver-master 1/1 Running 0 2d1h
kube-system kube-controller-manager-master 1/1 Running 0 2d1h
kube-system kube-flannel-ds-amd64-47r25 1/1 Running 0 2d1h
kube-system kube-flannel-ds-amd64-ls5lh 1/1 Running 0 2d1h
kube-system kube-proxy-685tk 1/1 Running 0 2d1h
kube-system kube-proxy-87spt 1/1 Running 0 2d1h
kube-system kube-scheduler-master 1/1 Running 0 2d1h
创建并运行
kubernetes没有提供单独运行Pod的命令,都是通过Pod控制器来实现的
# 命令格式: kubectl run (pod控制器名称) [参数]
# --image 指定Pod的镜像
# --port 指定端口
# --namespace 指定namespace
[[email protected] ~]# kubectl run nginx --image=nginx:latest --port=80 --namespace dev
deployment.apps/nginx created
查看pod信息
# 查看Pod基本信息
[[email protected] ~]# kubectl get pods -n dev
NAME READY STATUS RESTARTS AGE
nginx 1/1 Running 0 43s
# 查看Pod的详细信息
[[email protected] ~]# kubectl describe pod nginx -n dev
Name: nginx
Namespace: dev
Priority: 0
Node: node1/192.168.5.4
Start Time: Wed, 08 May 2021 09:29:24 +0800
Labels: pod-template-hash=5ff7956ff6
run=nginx
Annotations: <none>
Status: Running
IP: 10.244.1.23
IPs:
IP: 10.244.1.23
Controlled By: ReplicaSet/nginx
Containers:
nginx:
Container ID: docker://4c62b8c0648d2512380f4ffa5da2c99d16e05634979973449c98e9b829f6253c
Image: nginx:latest
Image ID: docker-pullable://[email protected]:485b610fefec7ff6c463ced9623314a04ed67e3945b9c08d7e53a47f6d108dc7
Port: 80/TCP
Host Port: 0/TCP
State: Running
Started: Wed, 08 May 2021 09:30:01 +0800
Ready: True
Restart Count: 0
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-hwvvw (ro)
Conditions:
Type Status
Initialized True
Ready True
ContainersReady True
PodScheduled True
Volumes:
default-token-hwvvw:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-hwvvw
Optional: false
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute for 300s
node.kubernetes.io/unreachable:NoExecute for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled <unknown> default-scheduler Successfully assigned dev/nginx-5ff7956ff6-fg2db to node1
Normal Pulling 4m11s kubelet, node1 Pulling image "nginx:latest"
Normal Pulled 3m36s kubelet, node1 Successfully pulled image "nginx:latest"
Normal Created 3m36s kubelet, node1 Created container nginx
Normal Started 3m36s kubelet, node1 Started container nginx
访问Pod
# 获取podIP
[[email protected] ~]# kubectl get pods -n dev -o wide
NAME READY STATUS RESTARTS AGE IP NODE ...
nginx 1/1 Running 0 190s 10.244.1.23 node1 ...
#访问POD
[[email protected] ~]# curl http://10.244.1.23:80
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
</head>
<body>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
删除指定Pod
# 删除指定Pod
[[email protected] ~]# kubectl delete pod nginx -n dev
pod "nginx" deleted
# 此时,显示删除Pod成功,但是再查询,发现又新产生了一个
[[email protected] ~]# kubectl get pods -n dev
NAME READY STATUS RESTARTS AGE
nginx 1/1 Running 0 21s
# 这是因为当前Pod是由Pod控制器创建的,控制器会监控Pod状况,一旦发现Pod死亡,会立即重建
# 此时要想删除Pod,必须删除Pod控制器
# 先来查询一下当前namespace下的Pod控制器
[[email protected] ~]# kubectl get deploy -n dev
NAME READY UP-TO-DATE AVAILABLE AGE
nginx 1/1 1 1 9m7s
# 接下来,删除此PodPod控制器
[[email protected] ~]# kubectl delete deploy nginx -n dev
deployment.apps "nginx" deleted
# 稍等片刻,再查询Pod,发现Pod被删除了
[[email protected] ~]# kubectl get pods -n dev
No resources found in dev namespace.
配置操作
创建一个pod-nginx.yaml,内容如下:
apiVersion: v1
kind: Pod
metadata:
name: nginx
namespace: dev
spec:
containers:
- image: nginx:latest
name: pod
ports:
- name: nginx-port
containerPort: 80
protocol: TCP
然后就可以执行对应的创建和删除命令了:
创建:kubectl create -f pod-nginx.yaml
删除:kubectl delete -f pod-nginx.yaml
《核心技术系列专栏汇总》
需要 大厂面试题、简历模版、电子书、学习资料 等关注【公众号】回复「 1024 」即可。
边栏推荐
- ShardingSphere-proxy-5.0.0部署之分表实现(一)
- InfoQ 极客传媒 15 周年庆征文|简述构建微服务架构的四大挑战
- LeetCode 890 查找和替换模式[map] HERODING的LeetCode之路
- 【LeetCode】102. 二叉树的层序遍历
- Analysis report on production and marketing demand and investment forecast of China's Melamine Industry from 2022 to 2028
- [leetcode] the k-largest element in the array
- Research Report on market supply and demand and strategy of China's digital camera lens industry
- 数字藏品的发展趋势!
- JS fighting on...
- lua 条件语句
猜你喜欢

Heilongjiang Branch and Liaoning Branch of PostgreSQL Chinese community have been established!

ASP. Net core Middleware

Inventory of CV neural network models from 2021 to 2022

Qrcodejs2 QR code generation JS

Mysql concat_ WS, concat function use
![LeetCode 890 查找和替换模式[map] HERODING的LeetCode之路](/img/a2/186439a6d50339ca7f299a46633345.png)
LeetCode 890 查找和替换模式[map] HERODING的LeetCode之路

MYSQL 行转列、列转行、多列转一行、一行转多列

Mysql case when then函数使用

iShot

80 lines of code to realize simple rxjs
随机推荐
Leetcode1601: the maximum number of building change requests that can be reached (difficult)
Deep learning neural network: implementation method of convolution [direct method (no loss of precision), GEMM (matrix multiplication, no loss of precision), FFT (Fourier transform, loss of precision)
【LeetCode】209. Minimum length subarray
C language: how to give an alias to a global variable?
Lua loop statement
China's new generation information technology industry "14th five year plan" special planning and innovation strategic direction report 2022 ~ 2028
Function introduction and common terms of ZABBIX
China's alternative sports equipment market trend report, technology dynamic innovation and market forecast
深度学习-神经网络:卷积的实现方法【直接法(精度没损失)、GEMM(矩阵乘法,精度没损失)、FFT(傅里叶变换,精度有损失)、Winograd(精度有损失)】
Gradient accumulation in pytorch [during the experiment, due to the limitation of GPU video memory, the batch\u size can no longer be increased. To solve this problem, the gradient accumulation method
Design a MySQL table for message queue to store message data
【LeetCode】53. Maximum subarray and
80 lines of code to realize simple rxjs
Common rendering pipeline grooming
vim利用右下4键
设计消息队列存储消息数据的 MySQL 表格
Heilongjiang Branch and Liaoning Branch of PostgreSQL Chinese community have been established!
Anti aliasing / anti aliasing Technology
Analysis report on business model innovation path and operation status of China's app store industry from 2022 to 2028
Research Report on market supply and demand and strategy of China's digital camera lens industry