当前位置:网站首页>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
边栏推荐
- OC to swift conditional compilation, marking, macro, log, version detection, expiration prompt
- setcontext getcontext makecontext swapcontext
- Flink DataStream 类型系统 TypeInformation
- LeetCode149-直线上最多的点数-数学-哈希表
- async关键字
- 8.4 realization of recurrent neural network from zero
- 8.3 language model and data set
- 分享 20 个不容错过的 ES6 的技巧
- Set up an AI team in the game world and start the super parametric multi-agent "chaos fight"
- Select receives both normal data and out of band data
猜你喜欢

Thinkphp5 + data large screen display effect

Detailed comparison between asemi three-phase rectifier bridge and single-phase rectifier bridge

我的树莓派 Raspberry Pi Zero 2W 折腾笔记,记录一些遇到的问题和解决办法

asp. Net method of sending mail using mailmessage

For 22 years, you didn't know the file contained vulnerabilities?

1n5408-asemi rectifier diode

每日一题-LeetCode396-旋转函数-递推

8.4 realization of recurrent neural network from zero

What is the role of the full connection layer?

Leetcode165 compare version number double pointer string
随机推荐
The win10 taskbar notification area icon is missing
Epoll's et, lt working mode -- example program
Frame synchronization implementation
Advanced application of I / O multiplexing: Processing TCP and UDP services at the same time
Unity_ Code mode add binding button click event
Redis master-slave synchronization
One of the advanced applications of I / O reuse: non blocking connect -- implemented using select (or poll)
ffmpeg安装遇错:nasm/yasm not found or too old. Use --disable-x86asm for a crippled build.
我的树莓派 Raspberry Pi Zero 2W 折腾笔记,记录一些遇到的问题和解决办法
Analysis of common storage types and FTP active and passive modes
Llvm - generate addition
Three uses of kprobe
thinkphp5+数据大屏展示效果
Reptile exercises (1)
Swift protocol Association object resource name management multithreading GCD delay once
1n5408-asemi rectifier diode
Basic operation of circular queue (Experiment)
C language super complete learning route (collection allows you to avoid detours)
Llvm - generate if else and pH
牛客网数据库SQL实战详细剖析(26-30)