当前位置:网站首页>Kubernetes详解(九)——资源配置清单创建Pod实战
Kubernetes详解(九)——资源配置清单创建Pod实战
2022-04-23 15:07:00 【永远是少年啊】
今天继续给大家介绍Linux运维相关知识,本文主要内容是通过资源配置清单方式创建Pod实战。
一、资源配置清单编写
在上文Kubernetes详解(八)——Kubernetes资源配置清单中,我们介绍了Kubernetes资源配置清单的常用字段,今天,我们就来使用资源配置清单,来实际生成一个Pod对象,从而展现Kubernetes资源配置清单的作用。
首先,我们创建一个资源配置清单文件pod-demo-test.yaml,并写入如下内容:
apiVersion: v1
kind: Pod
metadata:
name: pod-demo-test
namespace: default
labels:
label1: mypod1
label2: mypod2
spec:
containers:
- name: container
image: ikubernetes/myapp:v1
- name: busybox
image: busybox
command:
- "/bin/bash"
- "-c"
- "sleep 7200"
在该资源清单中,我们定义了一个Pod对象,前面的内容基本上都是固定的,并且已经在Kubernetes详解(八)——Kubernetes资源配置清单一文中介绍过了。后面spec字段下,我们主要是有containers的字段,该字段定义了该Pod资源内的容器,name字段定义了容器的名称;image字段定义了容器的镜像;command字段定义了容器运行后执行的命令。可以看出,在该Pod资源对象中,我们定义了两个容器,一个是myapp,一个是busybox。
该资源对象配置完成后,如下所示:
二、资源配置清单创建Pod
在该资源清单完成后,我们就可以根据该资源清单来创建一个Pod的资源对象。
执行命令:
kubectl create -f pod-demo.test.yaml
即可使得Kubernetes按照我们的资源清单的配置来创建一个Pod对象。在上述命令中,-f参数指定一个文件,后面紧跟文件名。
注意:我们这里使用的是YAML的格式,YAML的格式对空格和缩进非常严格,因此我们要尤为注意!
该命令执行结果如下:
该命令执行完毕后,我们可以查看一下该Pod对象,执行命令:
kubectl describe pods pod-demo-test
该命令执行结果如下:
三、镜像和Pod中的Command关系说明
最后,我们来讲以下镜像和Pod中的Command命令的关系。
在该资源配置清单中,我们在镜像下配置了command命令,而其实在Pod资源清单下,我们也可以配置CMD(类似Command)。并且在镜像和Pod中我们还可以配置args变量(镜像中是ENTRYPOINT)。镜像下和Pod中的Command命令以及args参数配置关系如下:
1、如果Pod中没有配置Command和args,则使用镜像中的CMD和ENTRYPOINT
2、如果Pod中设置了Command,但是没有args,则使用Pod中的Command,忽略镜像中的CMD和ENTRYPOINT
3、如果Pod中只设置了args,则args将作为参数给镜像中的ENTRYPOINT使用。
4、如果Pod和镜像中同时设置了Command和args,那么镜像中的CMD和ENTRYPINT将会被忽略,Pod中的Command和args则会被使用。
原创不易,转载请说明出处:https://blog.csdn.net/weixin_40228200
版权声明
本文为[永远是少年啊]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_40228200/article/details/124285821
边栏推荐
- Lotus DB design and Implementation - 1 Basic Concepts
- LeetCode151-颠倒字符串中的单词-字符串-模拟
- Introduction to distributed transaction Seata
- eolink 如何助力遠程辦公
- Nacos程序连接MySQL8.0+ NullPointerException
- Basic operation of circular queue (Experiment)
- Modify the default listening IP of firebase emulators
- Five data types of redis
- C language super complete learning route (collection allows you to avoid detours)
- My raspberry PI zero 2W tossing notes record some problems encountered and solutions
猜你喜欢
8.4 realization of recurrent neural network from zero
How does eolink help telecommuting
Set onedrive or Google drive as a drawing bed in upic for free
For 22 years, you didn't know the file contained vulnerabilities?
LeetCode153-寻找旋转排序数组中的最小值-数组-二分查找
Thinkphp5 + data large screen display effect
我的树莓派 Raspberry Pi Zero 2W 折腾笔记,记录一些遇到的问题和解决办法
Mds55-16-asemi rectifier module mds55-16
Detailed comparison between asemi three-phase rectifier bridge and single-phase rectifier bridge
Explain TCP's three handshakes in detail
随机推荐
Share 20 tips for ES6 that should not be missed
Explanation and example application of the principle of logistic regression in machine learning
Provided by Chengdu control panel design_ It's detailed_ Introduction to the definition, compilation and quotation of single chip microcomputer program header file
SSH connects to the remote host through the springboard machine
免费在upic中设置OneDrive或Google Drive作为图床
如何设计一个良好的API接口?
Design of digital temperature monitoring and alarm system based on DS18B20 single chip microcomputer [LCD1602 display + Proteus simulation + C program + paper + key setting, etc.]
1n5408-asemi rectifier diode
setcontext getcontext makecontext swapcontext
分布式事务Seata介绍
What is the role of the full connection layer?
SQLSERVER事物与锁的问题
Programming philosophy - automatic loading, dependency injection and control inversion
js——實現點擊複制功能
Modify the default listening IP of firebase emulators
Vscode Chinese plug-in doesn't work. Problem solving
Do (local scope), initializer, memory conflict, swift pointer, inout, unsafepointer, unsafebitcast, success
Analysis of common storage types and FTP active and passive modes
tcp_ Diag kernel related implementation 1 call hierarchy
OC to swift conditional compilation, marking, macro, log, version detection, expiration prompt