当前位置 :首页 >> 社会

pod(一):Kubernetes(k8s)建立pod的两种方式

2023-04-16   来源 : 社会

un nginx ;还有image=nginx # Start a hazelcast pod and let the container expose port 5701. kubectl run hazelcast ;还有image=hazelcast/hazelcast ;还有port=5701 ......Usage: kubectl run NAME ;还有image=image [;还有env="key=value"] [;还有port=port] [;还有dry-run=server|client] [;还有overrides=inline-json][;还有command] ;还有 [COMMAND] [args...] [options]Use "kubectl options" for a list of global command-line options (applies to all commands).

首再行拉取我们需要的快照,再行在worker终端拉取nginx快照

[root@k8scloude2 ~]# docker pull nginx[root@k8scloude3 ~]# docker pull nginx4.2.1 创始人最简单的pod

常用nginx快照创始人一个pod

#nginx为pod英文名字 ;还有image=nginx说明常用Nginx快照[root@k8scloude1 pod]# kubectl run nginx ;还有image=nginxpod/nginx created

发送给pod,STATUS为Running就说明pod创始人获得成功

[root@k8scloude1 pod]# kubectl get podNAME READY STATUS RESTARTS AGEnginx 0/1 ContainerCreating 0 6s[root@k8scloude1 pod]# kubectl get podNAME READY STATUS RESTARTS AGEnginx 1/1 Running 0 54s

删除pod

[root@k8scloude1 pod]# kubectl delete pod nginxpod "nginx" deleted4.2.2 创始人pod,均须快照订阅策略性

常用nginx快照创始人一个pod,快照的订阅策略性为IfNotPresent本地不能才订阅快照

快照的订阅策略性:Always:每次都订阅最新的快照;Never:只常用本地快照,从不订阅,IfNotPresent:本地不能才订阅快照 默认差值为:Always

#nginx为pod英文名字 ;还有image=nginx说明常用Nginx快照 ;还有image-pull-policy=IfNotPresent说明快照订阅策略性为IfNotPresent本地不能才订阅快照[root@k8scloude1 pod]# kubectl run nginx ;还有image=nginx ;还有image-pull-policy=IfNotPresentpod/nginx created[root@k8scloude1 pod]# kubectl get podNAME READY STATUS RESTARTS AGEnginx 1/1 Running 0 5s#删除pod[root@k8scloude1 pod]# kubectl delete pod nginxpod "nginx" deleted

提醒:kubectl delete pod nginx但会有点较慢,特了;还有force 禁止删除pod,删除pod但会快很多

[root@k8scloude1 pod]# kubectl delete pod nginx ;还有forcewarning: Immediate deletion does not wait for confirmation that the running resource has been terminated. The resource may continue to run on the cluster indefinitely.pod "nginx" force deleted4.2.3 创始人pod,均须环境污染字符和ID

发送给podID的设法

[root@k8scloude1 ~]# kubectl run ;还有help | grep labels # Start a hazelcast pod and set labels "app=hazelcast" and "env=prod" in the container. kubectl run hazelcast ;还有image=hazelcast/hazelcast ;还有labels="app=hazelcast,env=prod" -l, ;还有labels='': Comma separated labels to apply to the pod(s). Will override previous values.

创始人pod,均须环境污染字符和ID

#nginx为pod英文名字 ;还有image=nginx说明常用Nginx快照 ;还有image-pull-policy=IfNotPresent说明快照订阅策略性为IfNotPresent本地不能才订阅快照 ;还有env:所设字符xx=1,yy=2 ;还有labels所设ID,给pod打上“xx=1,yy=2”的ID[root@k8scloude1 pod]# kubectl run nginx ;还有image=nginx ;还有image-pull-policy=IfNotPresent ;还有env "xx=1" ;还有env "yy=2" ;还有labels="xx=1,yy=2"pod/nginx created#发送给pod[root@k8scloude1 pod]# kubectl get pod -o wideNAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATESnginx 1/1 Running 0 20s 10.244.112.136 k8scloude2

转至到pod那时候,可以看到字符xx,yy

[root@k8scloude1 pod]# kubectl exec -it nginx ;还有 bashroot@nginx:/# echo $xx1root@nginx:/# echo $yy2root@nginx:/# exitexit

发送给pod的ID,;还有show-labels值推测ID

[root@k8scloude1 pod]# kubectl get pod -o wide ;还有show-labelsNAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES LABELSnginx 1/1 Running 0 4m59s 10.244.112.136 k8scloude2 xx=1,yy=24.3 常用yaml元原始数据的方式为创始人pod4.3.1 yaml元原始数据阐述

YAML是"YAML Ain’t a Markup Language"(YAML不是一种标示语言)的运算符直译。YAML的意即其实是:“Yet Another Markup Language”(仍是一种标示语言)。主要强调这种语言是以原始数据为里心,而不是以标示语言为集中精力,例如像xml语言就但会常用大量的标示。

YAML是一个可读性高,易于忽略,用来暗示原始数据表单的XML。它的语法和其他高级语言相近,并且可以简单暗示清单(字符)、散表列出,标量等原始数据形态。它常用错位符号较宽和大量相反外观的特点,特别简便用来暗示或编辑文件系统、各种配置元原始数据等。YAML的配置元原始数据后缀为 .yaml。

yaml元原始数据也就是说语法:YAML常用可打印的Unicode字节,可常用UTF-8或UTF-16。文件系统采用共价键差值对的形式,即 共价键名称: 差值,提醒特殊符号右边要有空格。每个清单(字符)核心人物以单行说明,能用短杠+错位(- )接续。或常用转义([]),能用逗号+错位(, )连在一起核心人物。每个散表列出的核心人物用特殊符号+错位(: )连在一起共价键差值和主旨。或常用大括号({ }),能用逗号+错位(, )连在一起。字节串差值一般不常用字句,必要时可常用,常用比如说说明字节串时,但会转义字节串里的特殊字节(例如)。常用单字句时不能转义字节串里的特殊字节。大小写敏感常用较宽说明层级彼此间,较宽不准许常用tab,只准许空格,因为确实在多种不同系统下tab总长度不一样较宽的空格数可以至多,只要相同层级的类型左偏移即可在单独元原始数据里,可用整年三个连字号(;还有-)区分多个元原始数据。还有特性性的整年三个点号(…)用来说明元原始数据开头。'#'说明原文,可以经常出现在动身里的任何一段距离,单行原文在常用逗号及特殊符号时,右边都不能接一个错位字节,所以可以在字节串或数差值里自由特入分隔符号(例如:5,280或)而不需要常用字句。

接过那时候常用yaml元原始数据的方式为创始人pod

4.3.2 常用yaml元原始数据的方式为创始人pod

;还有dry-run 模拟调试,并不能真的创始人一个pod , ;还有dry-run=client输入个人信息少 ,;还有dry-run=server输入个人信息多, -o yaml以yaml元原始数据的XML输入

;还有dry-run=server输入个人信息如下:主旨很多

#nginx为pod英文名字 ;还有image=nginx说明常用Nginx快照 ;还有image-pull-policy=IfNotPresent说明快照订阅策略性为IfNotPresent本地不能才订阅快照[root@k8scloude1 pod]# kubectl run nginx ;还有image=nginx ;还有image-pull-policy=IfNotPresent ;还有dry-run=server -o yamlapiVersion: v1kind: Podmetadata: creationTimestamp: "2022-01-12T07:51:11Z" labels: run: nginx name: nginx namespace: pod uid: afa40310-3efd-4d9f-8337-8e1db955c6f7spec: containers: - image: nginx imagePullPolicy: IfNotPresent name: nginx resources: {} terminationMessagePath: /dev/termination-log terminationMessagePolicy: File volumeMounts: - mountPath: /var/run/secrets/kubernetes.io/serviceaccount name: kube-api-access-w56gz readOnly: true dnsPolicy: ClusterFirst enableServiceLinks: true preemptionPolicy: PreemptLowerPriority priority: 0 restartPolicy: Always schedulerName: default-scheduler securityContext: {} serviceAccount: default serviceAccountName: default terminationGracePeriodSeconds: 30 tolerations: - effect: NoExecute key: node.kubernetes.io/not-ready operator: Exists tolerationSeconds: 300 - effect: NoExecute key: node.kubernetes.io/unreachable operator: Exists tolerationSeconds: 300 volumes: - name: kube-api-access-w56gz projected: defaultMode: 420 sources: - serviceAccountToken: expirationSeconds: 3607 path: token - configMap: items: - key: ca.crt path: ca.crt name: kube-root-ca.crt - downwardAPI: items: - fieldRef: apiVersion: v1 fieldPath: metadata.namespace path: namespacestatus: phase: Pending qosClass: BestEffort

;还有dry-run=client输入个人信息如下:输入主旨恰到好处

[root@k8scloude1 pod]# kubectl run nginx ;还有image=nginx ;还有image-pull-policy=IfNotPresent ;还有dry-run=client -o yamlapiVersion: v1kind: Podmetadata: creationTimestamp: null labels: run: nginx name: nginxspec: containers: - image: nginx imagePullPolicy: IfNotPresent name: nginx resources: {} dnsPolicy: ClusterFirst restartPolicy: Alwaysstatus: {}

分解成创始人pod的yaml元原始数据

[root@k8scloude1 pod]# kubectl run nginx ;还有image=nginx ;还有image-pull-policy=IfNotPresent ;还有dry-run=client -o yaml>nginx.yaml

yaml元原始数据那时候有很多字符,可以常用kubectl explain发送给yaml元原始数据每个字符的含义

# kubectl explain pods发送给一级字符有哪些,每个的含义[root@k8scloude1 ~]# kubectl explain podsKIND: PodVERSION: v1DESCRIPTION: Pod is a collection of containers that can run on a host. This resource is created by clients and scheduled onto hosts.FIELDS: apiVersion APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: #resources kind Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: #types-kinds metadata Standard object's metadata. More info: #metadata spec Specification of the desired behavior of the pod. More info: #spec-and-status status Most recently observed status of the pod. This data may not be up to date. Populated by the system. Read-only. More info: #spec-and-status

发送给一级字符下相关联了哪些字符,对某个字符不了解,再行常用kubectl explain发送给

[root@k8scloude1 ~]# kubectl explain pod.spec[root@k8scloude1 ~]# kubectl explain pods.spec.containers[root@k8scloude1 ~]# kubectl explain pods.spec.containers.ports

液体containers那时候也可以自表述字符,表述字符的时候:字符的差值如果是数字,需要特“”

[root@k8scloude1 pod]# vim nginx.yaml #kind: Pod说明森林资源特性为Pod labels均须podID metadata一个大的name均须pod英文名字 containers一个大全部都是液体的表述 #image均须快照英文名字 imagePullPolicy均须快照订阅策略性 containers一个大的name均须液体名#resources均须液体森林资源(CPU,内存等) env均须液体那时候的环境污染字符 dnsPolicy均须DNS策略性#restartPolicy液体重启策略性[root@k8scloude1 pod]# cat nginx.yaml apiVersion: v1kind: Podmetadata: creationTimestamp: null labels: run: nginx name: nginxspec: containers: - image: nginx imagePullPolicy: IfNotPresent name: nginx resources: {} env: - name: xx value: "12" - name: yy value: "21" - name: zz value: hello dnsPolicy: ClusterFirst restartPolicy: Alwaysstatus: {}

kubectl apply -f 广泛应用配置元原始数据,创始人pod

[root@k8scloude1 pod]# kubectl apply -f nginx.yaml pod/nginx created[root@k8scloude1 pod]# kubectl get podsNAME READY STATUS RESTARTS AGEnginx 1/1 Running 0 26s

删除pod

[root@k8scloude1 pod]# kubectl delete -f nginx.yaml pod "nginx" deleted[root@k8scloude1 pod]# kubectl get podsNo resources found in pod namespace.

表述一个pod指明液体的调制解调器,containerPort: 80 只是告知外界nginx这个pod常用80调制解调器,无论如何要修改调制解调器需要修改快照

[root@k8scloude1 pod]# vim nginx.yaml #kind: Pod说明森林资源特性为Pod labels均须podID metadata一个大的name均须pod英文名字 containers一个大全部都是液体的表述 #image均须快照英文名字 imagePullPolicy均须快照订阅策略性 containers一个大的name均须液体名#resources均须液体森林资源(CPU,内存等) env均须液体那时候的环境污染字符 dnsPolicy均须DNS策略性#restartPolicy液体重启策略性 ports均须液体调制解调器[root@k8scloude1 pod]# cat nginx.yaml apiVersion: v1kind: Podmetadata: creationTimestamp: null labels: run: nginx name: nginxspec: containers: - image: nginx imagePullPolicy: IfNotPresent name: nginx resources: {} ports: - name: http containerPort: 80 protocol: TCP env: - name: xx value: "12" - name: yy value: "21" - name: zz value: hello dnsPolicy: ClusterFirst restartPolicy: Alwaysstatus: {}

创始人pod

[root@k8scloude1 pod]# kubectl apply -f nginx.yaml pod/nginx created[root@k8scloude1 pod]# kubectl get podsNAME READY STATUS RESTARTS AGEnginx 1/1 Running 0 3s

禁止删除pod

[root@k8scloude1 pod]# kubectl delete pod nginx ;还有force warning: Immediate deletion does not wait for confirmation that the running resource has been terminated. The resource may continue to run on the cluster indefinitely.pod "nginx" force deleted4.3.3 yaml元原始数据那时候的词条和表列出

再行分解成一个yaml元原始数据

[root@k8scloude1 pod]# kubectl run nginx ;还有image=nginx ;还有image-pull-policy=IfNotPresent ;还有dry-run=client -o yamlapiVersion: v1kind: Podmetadata: creationTimestamp: null labels: run: nginx name: nginxspec: containers: - image: nginx imagePullPolicy: IfNotPresent name: nginx resources: {} dnsPolicy: ClusterFirst restartPolicy: Alwaysstatus: {}

我们提醒到,有的字符左边有- ,有的不能- ,不能-的是词条,词条那时候不用有段落字符,有-的是表列出,表列出那时候的每个都可都是一个匿名词条,在表列出里,都可的第一个字符要特-

例如:当pod那时候有多个液体的时候,containers可以表述多个,每个液体是一个都可,每个液体的第一个字符就特-apiVersion: v1kind: Podmetadata: creationTimestamp: null labels: run: nginx name: nginxspec: containers: - image: nginx imagePullPolicy: IfNotPresent name: nginx resources: {} - image: nginx imagePullPolicy: IfNotPresent name: nginx resources: {} - image: nginx imagePullPolicy: IfNotPresent name: nginx resources: {} dnsPolicy: ClusterFirst restartPolicy: Alwaysstatus: {}4.3.4 发送给多种不同特性的apiVersion

多种不同的Kubernetes森林资源特性,apiVersion是不一样的,Pod的apiVersion为v1

kubectl api-versions 发送给所有的apiVersion

[root@k8scloude1 ~]# kubectl api-versions admissionregistration.k8s.io/v1admissionregistration.k8s.io/v1beta1apiextensions.k8s.io/v1apiextensions.k8s.io/v1beta1apiregistration.k8s.io/v1apiregistration.k8s.io/v1beta1apps/v1authentication.k8s.io/v1authentication.k8s.io/v1beta1authorization.k8s.io/v1authorization.k8s.io/v1beta1autoscaling/v1autoscaling/v2beta1autoscaling/v2beta2batch/v1batch/v1beta1certificates.k8s.io/v1certificates.k8s.io/v1beta1coordination.k8s.io/v1coordination.k8s.io/v1beta1crd.projectcalico.org/v1discovery.k8s.io/v1discovery.k8s.io/v1beta1events.k8s.io/v1events.k8s.io/v1beta1extensions/v1beta1flowcontrol.apiserver.k8s.io/v1beta1metrics.k8s.io/v1beta1networking.k8s.io/v1networking.k8s.io/v1beta1node.k8s.io/v1node.k8s.io/v1beta1policy/v1policy/v1beta1rbac.authorization.k8s.io/v1rbac.authorization.k8s.io/v1beta1scheduling.k8s.io/v1scheduling.k8s.io/v1beta1storage.k8s.io/v1storage.k8s.io/v1beta1v14.3.5 常用同一个yaml元原始数据创始人多个pod

分解成yaml元原始数据

[root@k8scloude1 pod]# kubectl run pod1 ;还有image=nginx ;还有image-pull-policy=IfNotPresent ;还有dry-run=client -o yaml>pod1.yaml

常用同一个yaml元原始数据创始人2个pod

[root@k8scloude1 pod]# sed 's/pod1/pod2/' pod1.yaml apiVersion: v1kind: Podmetadata: creationTimestamp: null labels: run: pod2 name: pod2spec: containers: - image: nginx imagePullPolicy: IfNotPresent name: pod2 resources: {} dnsPolicy: ClusterFirst restartPolicy: Alwaysstatus: {}[root@k8scloude1 pod]# sed 's/pod1/pod2/' pod1.yaml | kubectl apply -f -pod/pod2 created[root@k8scloude1 pod]# sed 's/pod1/pod3/' pod1.yaml | kubectl apply -f -pod/pod3 created[root@k8scloude1 pod]# kubectl get podsNAME READY STATUS RESTARTS AGEpod2 1/1 Running 0 30spod3 1/1 Running 0 9s[root@k8scloude1 pod]# lspod1.yaml。

石家庄男科医院哪家看的好
常州男科医院哪家专业
广州肿瘤医院哪个比较好
成都治疗甲状腺有几家医院
脚扭伤了应该吃什么药
从2999元滑落至1328元,40W快充+麒麟980+鸿蒙系统

摩托罗拉在2021年11年末贩售了一款较为低价的4G手机,这款手机就是摩托罗拉nova8 SE 4G,8GB+128GB版发表价是2099元,换装的还是玉710AIntel,转用6400万分辨率...

友情链接