一、K8s編排yaml文件
1.1 如何通過Yaml文件創建deployment自動關聯NodePort服務呢?
a. 命令行方式關聯
參考資料:K8S拉取Django項目創建pod
文章中通過命令行方式關聯,還需要手動修改svc參數
b. yaml文件編排方式
apiVersion: apps/v1 kind: Deployment metadata: creationTimestamp: null labels: app: abc name: abc namespace: abc spec: replicas: 3 selector: matchLabels: app: iam strategy: {} template: metadata: creationTimestamp: null labels: app: abc spec: containers: - image: registry.xxx.com/xxx/xxxx:1260cd6 name: abc imagePullPolicy: Always resources: {} ports: - containerPort: 9991 name: abcsvc protocol: TCP --- apiVersion: v1 kind: Service metadata: labels: app: abc name: abcsvc namespace: abc spec: ports: - port: 30333 nodePort: 30333 protocol: TCP targetPort: 9991 selector: app: abc type: NodePort
參數說明:
kind: Deployment
- - containerPort:容器內的服務端口
- name: abcsvc svc服務的名字
# kubectl get svc -n abc NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE abc NodePort 10.10.7.99 <none> 30333:30333/TCP 9m15s #
kind: Service
- - port: 30333 容器暴露的端口(理解可能不對)
- nodePort: 30333 節點服務器上暴露的端口
- targetPort: 9991 目標容器服務的端口
c. 創建deployment並關聯svc
# kubectl apply -f abc.deployment.yaml