前言
繼上一篇 w4560000 - Octopus Deploy K8S 專案 [1] - 地端 K8S 後
本篇設定部署 qc 環境到 GKE
GKE 環境建置
參考 w4560000 - GCP Kubernetes Engine 建置
設定 GKE QC 環境的 Octopus Deployment targets
參考 w4560000 - Octopus Deploy [5] Kubernetes cluster 地端機器設定 Deployment targets
GKE 上有提供叢集憑證 可以順便設定
先複製憑證出來
新增 Octopus Certificates
建立 Octopus Deployment target時 選擇 剛剛建立的 Octopus Certificates
建立後確認 HealthCheck 正常即可
建立 Ingress 用的固定靜態IP
gcloud compute addresses create web-ingress-ip --global
建立 Ingress 用的憑證
參考 w4560000 - GCP 建立 Google 自管的 SSL 憑證
新增 Octopus Variables
K8s.Web.Host[OctopusProject_Core_Sample] = octopuscoresampleqc.leozheng0512.com (qc環境)
設定 Runbook - Setup Kubernetes Ingress - Deploy Cloud Kubernetes Ingress
選擇 DEPLOY RAW KUBERNETES YAML
ingress 外部IP 為 web-ingress-ip
ingress 憑證 為 web-ingress-qc-cert
apiVersion: networking.gke.io/v1beta1
kind: FrontendConfig
metadata:
name: 'web-ingress-frontendconfig'
namespace: '#{K8s.Web.Namespace}'
spec:
redirectToHttps:
enabled: true
responseCodeName: MOVED_PERMANENTLY_DEFAULT
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: 'web-ingress'
annotations:
kubernetes.io/ingress.global-static-ip-name: 'web-ingress-ip'
ingress.gcp.kubernetes.io/pre-shared-cert: 'web-ingress-qc-cert'
networking.gke.io/v1beta1.FrontendConfig: 'web-ingress-frontendconfig'
namespace: '#{K8s.Web.Namespace}'
spec:
rules:
- host: '#{K8s.Web.Host[OctopusProject_Core_Sample]}'
http:
paths:
- path: /*
pathType: ImplementationSpecific
backend:
service:
name: 'octopusproject-core-sample'
port:
number: 80
設定部屬到 qc
測試部署 Ingress 至 qc
設定 Project Process - 新增 Deploy To Cloud Kubernetes Cluster
選擇 Deploy Kubernetes containers
設定 StepName、Target roles
設定 Deployment
# This YAML exposes the fields defined in the UI. It can be edited directly or have new YAML pasted in.
# Not all available Kubernetes properties are recognized by the form exposed in the UI, and unrecognized properties are ignored during import.
# If the required properties are not supported by this step, the 'Deploy raw Kubernetes YAML' step can be used to deploy YAML directly to Kubernetes, and supports all properties.
apiVersion: apps/v1
kind: Deployment
metadata:
name: '#{K8s.Web.ProjectSimpleName}'
labels:
app: '#{K8s.Web.ProjectSimpleName}'
namespace: '#{K8s.Web.Namespace}'
spec:
selector:
matchLabels:
octopusexport: OctopusExport
replicas: 1
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 1
maxSurge: 1
template:
metadata:
labels:
app: '#{K8s.Web.ProjectSimpleName}'
octopusexport: OctopusExport
spec:
containers:
- name: web-container
image: '#{K8s.Web.ImageRegistry}'
ports:
- name: http
containerPort: '#{K8s.Web.WebPort}'
protocol: TCP
env:
- name: ASPNETCORE_ENVIRONMENT
value: '#{Octopus.Environment.Name}'
livenessProbe:
httpGet:
host: ''
path: '#{K8s.Web.Core.HealthCheckPath}'
port: '#{K8s.Web.WebPort}'
scheme: HTTP
readinessProbe:
periodSeconds: 15
httpGet:
host: ''
path: '#{K8s.Web.Core.HealthCheckPath}'
port: '#{K8s.Web.WebPort}'
scheme: HTTP
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: cloud.google.com/gke-nodepool
operator: In
values:
- web-node-pool
設定 Service
# This YAML exposes the fields defined in the UI. It can be edited directly or have new YAML pasted in.
# Not all available Kubernetes properties are recognized by the form exposed in the UI, and unrecognized properties are ignored during import.
# If the required properties are not supported by this step, the 'Deploy raw Kubernetes YAML' step can be used to deploy YAML directly to Kubernetes, and supports all properties.
apiVersion: v1
kind: Service
metadata:
name: '#{K8s.Web.ProjectSimpleName}'
namespace: '#{K8s.Web.Namespace}'
spec:
type: ClusterIP
ports:
- name: http-port
port: 80
protocol: TCP
selector:
octopusexport: OctopusExport
設定部署到 qc
設定完成後 部屬到 qc
設定完成後 測試結果
到 gke 機器上確認服務
kubectl get all -n web
# 輸出
NAME READY STATUS RESTARTS AGE
pod/octopusproject-core-sample-5cfcb747db-hfx7j 1/1 Running 0 72s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/octopusproject-core-sample ClusterIP 10.68.7.78 <none> 80/TCP 12h
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/octopusproject-core-sample 1/1 1 1 12h
NAME DESIRED CURRENT READY AGE
replicaset.apps/octopusproject-core-sample-5cfcb747db 1 1 1 73s
確認 ingress
kubectl get ing -n web
# 輸出
NAME CLASS HOSTS ADDRESS PORTS AGE
web-ingress <none> octopuscoresampleqc.leozheng0512.com 34.111.12.117 80 25m
測試 API 功能
curl https://octopuscoresampleqc.leozheng0512.com/Home/GetEnv
# 輸出
"qc"
轉載請註明來源,若有任何錯誤或表達不清楚的地方,歡迎在下方評論區留言,也可以來信至 leozheng0621@gmail.com
如果文章對您有幫助,歡迎斗內(donate),請我喝杯咖啡