当前位置:网站首页>kubernetes资源对象介绍及常用命令
kubernetes资源对象介绍及常用命令
2022-06-28 17:24:00 【傻啦猫@[email protected]】
命名空间
在kubernetes中,命名空间被用来隔离资源。比如配置字典,内部路由等,每个命名空间只能使用其下的。
查看命名空间
kubectl get ns
ns是namespace的缩写。
创建命名空间
创建一个hello的命名空间。
命令行方式
kubectl create ns hello
yaml方式,hello.yaml
apiVersion: v1
kind: Namespace
metadata:
name: hello
kubectl apply -f hello.yaml
删除命名空间
命令行方式
kubectl delete ns hello
yaml方式
kubectl delete -f hello.yaml
这里需要说明的是系统默认的命名空间无法删除。包括default。并且删除命名空间会将该空间下部署的所有资源连带删除,谨慎操作。
Pod
pod是运行中的一组容器,是kubernetes中应用的最小单位。
查看pod
kubectl get pod -A
此命令默认情况下是查看所有的pod。如果我们想看指定命名空间下的pod,可以使用kubectl get pod -n 空间名称,不加参数,查看默认名称空间。
创建pod
创建一个名称为mynginx的pod,使用的镜像为nginx。
命令行方式
kubectl run mynginx --image=nginx
[[email protected] ~]# kubectl get pod [mynginx]
NAME READY STATUS RESTARTS AGE
mynginx 1/1 Running 0 80s
[[email protected] ~]#
说明:NAME表示pod名称。READY表示就绪的容器数量以及总容器数量。STATUS表示状态。RESTARTS表示重启次数。AGE表示创建时长。
yaml方式,nginx.yaml
apiVersion: v1
kind: Pod
metadata:
name: mynginx
namespace: default
spec:
containers:
- image: nginx
name: mynginx
打印详细描述信息
[[email protected] ~]# kubectl describe pod [mynginx]
......
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 4m54s default-scheduler Successfully assigned default/mynginx to k8s-worker2
Normal Pulling 4m53s kubelet Pulling image "nginx"
Normal Pulled 3m49s kubelet Successfully pulled image "nginx" in 1m4.144467081s
Normal Created 3m48s kubelet Created container mynginx
Normal Started 3m48s kubelet Started container mynginx
[[email protected] ~]#
主要看事件部分。包括被分配的节点信息等。我们发现在k8s-worker2节点创建了pod,所以通过docker ps | grep mynginx查看的时候只有在worker2节点才可看到。
打印详细日志信息
[[email protected] ~]# kubectl logs [mynginx]
...
2022/06/27 15:18:45 [notice] 1#1: start worker process 32
2022/06/27 15:18:45 [notice] 1#1: start worker process 33
[[email protected] ~]#
查看pod被分配的ip
[[email protected] ~]# kubectl get pod -owide [mynginx]
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
mynginx 1/1 Running 0 4m6s 192.168.126.8 k8s-worker2 <none> <none>
[[email protected] ~]#
集群中的任意一个机器以及任意的应用都能通过Pod分配的ip来访问这个Pod,curl 192.168.126.8:[80]。
进入pod容器内部
[[email protected] ~]# kubectl exec -it [mynginx] -c [mynginx] -- /bin/bash
[email protected]:/# ls
bin dev docker-entrypoint.sh home lib64 mnt proc run srv tmp var
boot docker-entrypoint.d etc lib media opt root sbin sys usr
[email protected]:/#
注意,如果是多容器的pod,我们可以加上参数-c 容器名称即可进入指定的容器内。
删除pod
kubectl delete pod [mynginx]
kubectl delete -f nginx.yml
重点说明:pod是kubernetes中应用的最小单位。在同一个pod内的容器可以直接使用127.0.0.1:端口的方式访问,但是要注意,端口不能重复。
本文由 mdnice 多平台发布
版权声明
本文为[傻啦猫@[email protected]]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_45842494/article/details/125494187
边栏推荐
- rsync 远程同步(日落尤其温柔的人间皆是浪漫)
- Does the dataworks SQL script support if else judgment of statement blocks
- Logback log output format
- Spruce network deepflow helps 5g core network and telecom cloud build observability
- How to back up a WordPress database
- Why insert is configured with'select last_ INSERT_ What if id() 'returns 0?
- 6 - Dictionary
- oracle cdc 但是使用的服务名没有sid 该怎么配置呢?
- 阿里云服务器里装的mysql是8版本的,是因为dataworks的mysql驱动版本不支持吗?现在提
- 麻醉不止“打一针”那么简单,无痛、安全、舒适为患者首选
猜你喜欢

Squid proxy server application (I came from afar to make an appointment with you)

为什么 insert 配置 'SELECT LAST_INSERT_ID()' 返回个0呢?

2022危险化学品生产单位安全生产管理人员复习题及答案

TDengine&nbsp;×英特尔 边缘洞见软件包 加速传统行业的数字化转型

"Jay bear" plummeted by 96.6%. Why is NFT with star goods cold?

Time effective simulation platform based on dataworks | acquisition technology

全网最全360无死角编写软件测试用例模板【建议收藏】

NoSQL之Redis配置与优化(你不在南京的日子我替你吹了秦淮河的晚风)
![[World Ocean Day] tcapulusdb calls on you to protect marine biodiversity together](/img/82/2357f9d195cfbb38c4052790804a6f.png)
[World Ocean Day] tcapulusdb calls on you to protect marine biodiversity together

2022 practice questions and mock examination of Shandong Province safety officer C certificate examination
随机推荐
Apache setting timeout parameter
NoSQL之Redis配置与优化(你不在南京的日子我替你吹了秦淮河的晚风)
9个优秀的占位图服务
IDC: Alibaba cloud ranks first in the market share of China's data governance platform in 2021
Tacacs+ server deployment
NoSQL redis configuration and optimization (I blew the night breeze of Qinhuai River for you when you were not in Nanjing)
Introduction, type selection comparison and architecture design of common distributed file storage
Batch modify specified character file name bat script
WSUS client access server exception error -0x8024401f "suggestions collection"
Exploration and practice of reinforcement learning in yellow page merchants' intelligent chat assistant
Talk about my understanding of image tearing, vertical synchronization, freesync and g-sync
CSDN博客专家
ICML 2022 | transferable imitation learning method based on decoupling gradient optimization
Redis持久化(少年一貫快馬揚帆,道阻且長不轉彎)
The fourth largest operator cannot be a "catfish"
通达信能开户炒股吗?安全吗?
How to make your WordPress website more secure
终于辞职了,全职ue了
Xiaoxin black apple sound card ID injection
nuc980心跳灯