iT邦幫忙

2023 iThome 鐵人賽

DAY 12
0
Cloud Native

擱淺中掙扎系列 第 12

<DAY12>Kubernetes X Deployment的yaml

  • 分享至 

  • xImage
  •  

Deployment他會創建多個副本,已達成負載平衡,滾動更新等。
而這段YAML文件,簡單講就是透過給Pod一個web標籤,讓matchLabels能去抓到pod,穰後讓他做4份出來。

apiVersion: apps/v1 指定了要使用的Kubernetes API的版本。
selector:做選擇
metadata:用來擺放描述性資料的地方
spec:描述模板
env:環境變數
最下面的Service,Service允許你將應用程式的網路連線從外部或內部路由到一組Pod中的一個或多個。
nodeport:service port
這個很重要,你要有nodeport才有辦法對外。

web.yaml
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: web-deployment
spec:
  replicas: 4
  selector:
    matchLabels:
      app: web
  template:
    metadata:      
      labels:   
        app: web
    spec:
      containers:  
        - name: web
          image: test/v1-demo
          ports:
            - containerPort: 3000
          env:
            - name: PORT    
              value: "3000"   
            - name: hostname  
              value: "0.0.0.0"
          command:  
            - "bash"
            - "-c"
            - >
              curl -d @/usr/src/app/mqtttest.json -H 'Content-Type: application/json' -X POST http://connect:8083/connectors &&
              curl -d @/usr/src/app/mqtttest2.json -H 'Content-Type: application/json' -X POST http://connect:8083/connectors &&
              sleep 5 &&
              node /usr/src/app/index.js
---
apiVersion: v1
kind: Service 
metadata:
  name: web
spec:
  selector:
    app: web
  ports:
    - protocol: TCP
      port: 3000   
      nodePort: 3000

補完


上一篇
<DAY11>Kubernetes X 自動擴展
下一篇
<DAY13>MQTT X Kafka Connect 的配置文件
系列文
擱淺中掙扎29
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 則留言

1
VP
iT邦新手 1 級 ‧ 2023-10-04 03:04:07

(期待本篇

我要留言

立即登入留言