kubernetes yaml 配置文件詳解

deployment

定義 deployment 配置文件,命名為:nginx-deployment.yaml

apiVersion: apps/v1   # 1.9.0 之前的版本使用 apps/v1beta2,可通過(guò)命令 kubectl api-versions 查看
kind: Deployment    #指定創(chuàng)建資源的角色/類型
metadata:    #資源的元數(shù)據(jù)/屬性
  name: nginx-deployment    #資源的名字,在同一個(gè)namespace中必須唯一
spec:
  replicas: 2    #副本數(shù)量2
  selector:      #定義標(biāo)簽選擇器
    matchLabels:
      app: web-server
  template:      #這里Pod的定義
    metadata:
      labels:    #Pod的label
        app: web-server
    spec:        # 指定該資源的內(nèi)容  
      containers:  
      - name: nginx      #容器的名字  
        image: nginx:1.12.1  #容器的鏡像地址    
        ports:  
        - containerPort: 80  #容器對(duì)外的端口
pod

定義 pod 配置文件,命名為 redis-pod.yaml

apiVersion: v1
kind: Pod  
metadata:  
  name: pod-redis
  labels:
    name: redis
spec: 
  containers:
  - name: pod-redis
    image: docker.io/redis  
    ports:
    - containerPort: 80 #容器對(duì)外的端口
service

定義 service 配置文件,命名為 httpd-svc.yaml

apiVersion: v1  
kind: Service  # 指明資源類型是 service
metadata:  
  name: httpd-svc # service 的名字是 httpd-svc
  labels:  
    name: httpd-svc 
spec:  
  ports:  # 將 service 8080 端口映射到 pod 的 80 端口,使用 TCP 協(xié)議
  - port: 8080
    targetPort: 80  
    protocol: TCP  
  selector:  
    run: httpd # 指明哪些 label 的 pod 作為 service 的后端

參考:
https://www.cnblogs.com/bakari/p/10509484.html

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容