做微服務研發工程師的一年來的總結

紫色飛豬發表於2022-07-06

前述

18年的那個留校夏天,極其偶然接觸到了《Docker+Kubernetes》,由純運維的發展方向轉到了雲原生的發展方向。19年5月以《linux helmsman platform》獲得IT創新大賽二等獎,其實質是圍繞雲原生的邊側服務整合部署。20年5月以《基於Kubernetes的舵手叢集系統的設計與實現》獲的河南省優秀畢業論文,其實質是在《linux helmsman platform》的基礎上進行補丁而成。20年6月初在創業型公司做唯一的雲原生運維,那是段足以影響一生的經歷:https://www.cnblogs.com/zisefeizhu/p/14601287.html
21年6月底極其偶然的機會(面的kubernetes運維崗,入職了微服務研發工程師崗)來到這家公司以微服務研發工程師的角色實質開啟純研發歷程,至今已一年有餘。在專案空閒期回憶這一年的路程,承上啟下。

一年來做的專案

這一年來重點圍繞以下專案展開:

1)、 獨立開發xxx專案的混合雲容器模組:運用go+gin+gorm+mysql+client-go+kubernetes技術棧,實現對kubernetes叢集的建立/匯入、節點的管理、名稱空間的管理、工作負載的管理、配置中心的管理、...、憑證的管理、映象倉庫的適配(harbor/acr/ccr/aws)、叢集的適配(tke/ack/aws/自建叢集)、等功能。總的來說此專案主要是api的對接,並不具備複雜的技術棧,在實際開發中最大的收穫是:1、根據需求實現業務的開發考量 2、對各廠商的欄位封裝 3、開發中遇到問題的實際處理(1、返回錯誤資訊 2、列表類介面的錯誤處理 3、資料庫欄位的設計 4、api介面的設計 5、適配層的轉換 6、面向錯誤的開發)。期間思考了下圖

  • ps:上圖只是個人對容器平臺的構想,實際專案中並沒有用此構思,所以談不上涉密問題。
func Init(g *gin.Engine) {
	// 跨域
	g.Use(Cors())
	// 定義輸出日誌格式
	g.Use(middleware.LoggerToFile())
	g.Any("/", v1.Hello)
	g.GET("/health", v1.Health)
	api := g.Group("/container/api")
	clusterRouters(api)
	nodeRouters(api)
	nsRouters(api)
	workloadRouters(api)
	podRouters(api)
	pluginRouters(api)
	registryRouters(api)
	credentialRouters(api)
	configRouters(api)
	csiRouters(api)
	g.GET("/swagger/*any", gs.WrapHandler(swaggerFiles.Handler))
}

2)、根據開發devops同事的需求,獨自設計與實現(運用helm+kubernetes技術棧)jenkins叢集+外掛的一鍵部署。總體來說此專案並不複雜,更多的是考驗helm的書寫與合理的利用kubernetes的特性。實際構思圖如下:

# Default values for jenkins.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.
# By zisefeizhu
# Time 2021年 8月26日 星期四 10時45分56秒 CST

# namespaceOverride jenkins部署到的名稱空間
namespaceOverride: devops

securityContext:
  enabled: true
  privileged: true
  runAsUser: 0
# replicaCount 副本數
replicaCount: 1

# image 映象資訊
image:
  repository: registry.cn-shenzhen.aliyuncs.com/zisefeizhu/annet
  pullPolicy: IfNotPresent
  # Overrides the image tag whose default is the chart appVersion.
  tag: "jenkinsci-blueocean-v0.1.1"
  baseImageTag: "jenkins-plugins-v0.1.4"

# dockerRegistry Concentrated verification of consciousness
dockerRegistry:
  enabled: true
  secretName: jenkins
  user: xxxx
  password: xxxxxx


# containerPorts jenkins pod 埠
containers:
  ports:
  - containerPort: 8080
    name: web
    protocol: TCP
  - containerPort: 50000
    name: agent
    protocol: TCP

nameOverride: ""
fullnameOverride: ""

serviceAccount:
  # Specifies whether a service account should be created
  create: true
  # Annotations to add to the service account
  annotations: {}
  # The name of the service account to use.
  # If not set and create is true, a name is generated using the fullname template
  name: ""

# service 型別和埠資訊
service:
  ports:
  - name: web
    port: 8080
    targetPort: web
    nodePort: 31031
  - name: agent
    port: 50000
    targetPort: agent
  type: NodePort
#  port: 31031   #埠

# pvc的access型別
pvc:
  enabled: true
  scName: xxxx
  accessModes: ReadWriteMany
  storage: xxx

ingress:
  enabled: false
  className: ""
  annotations: {}
    # kubernetes.io/ingress.class: nginx
    # kubernetes.io/tls-acme: "true"
  hosts:
    - host: chart-example.local
      paths:
        - path: /
          pathType: ImplementationSpecific
  tls: []
  #  - secretName: chart-example-tls
  #    hosts:
  #      - chart-example.local

# resources limit range obtained from pressure measurement
resources:
  enabled: falase
  limits:
    cpu: 1
    memory: 1Gi
  requests:
    cpu: 200m
    memory: 512Mi

# startupProbe 存活性探針
startupProbe:
  enabled: false
  probe:
    failureThreshold: 3
    httpGet:
      path: /login
      port: 8080
      scheme: HTTP
    initialDelaySeconds: 30
    periodSeconds: 10
    successThreshold: 1
    timeoutSeconds: 1

# livenessProbe 存活性探針
livenessProbe:
  enabled: false
  probe:
    failureThreshold: 3
    httpGet:
      path: /login
      port: 8080
      scheme: HTTP
    initialDelaySeconds: 30
    periodSeconds: 10
    successThreshold: 1
    timeoutSeconds: 5

# readinessProbe 就緒性探針
readinessProbe:
  enabled: false
  probe:
    failureThreshold: 3
    httpGet:
      path: /login
      port: 8080
      scheme: HTTP
    initialDelaySeconds: 30
    periodSeconds: 10
    successThreshold: 1
    timeoutSeconds: 5

autoscaling:
  enabled: true
  minReplicas: 1
  maxReplicas: 10
  targetCPUUtilizationPercentage: 80
  targetMemoryUtilizationPercentage: 80

3)、根據架構師構思(16年工作經驗),獨自驗證/輸出文件,運用:logstash+ceph+operator技術棧。實現es叢集之間的全量/增量/全量+增量同步遷移、持久化佇列/死信等功能。此專案具有一定複雜度。在實際開發中需要1、對logstash有一定程度的運用(需要對涉及到的功能點進行一一驗證實踐)、2、對operator有一定的掌握(特別是對spec和status的深度理解)。3、對k8s有較深度的掌握,理解涉及到的核心資源的運用。

  • 架構圖及原始碼涉密。

4)、近期為了加深operator的理解,寫了workload-operator,實現對deployments/statefulsets/daemonsets/cronjobs/jobs/services 功能的封裝。本專案為個人專案,難點在對個控制器的理解與status的處理。

func (r *WorkloadReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
	_ = r.Logger.WithValues("workloads", req.NamespacedName)
	forget := reconcile.Result{}
	requeue := ctrl.Result{
		RequeueAfter: time.Second * 2,
	}
	instance := &workloadsv1alpha1.Workload{}
	if err := r.Get(ctx, req.NamespacedName, instance); err != nil {
		return forget, client.IgnoreNotFound(err)
	}

	// 進入矯正
	if instance.Status.Phase != workloadsv1alpha1.RunningPhase {
		// 這裡料想複雜
		// todo 再優化
		err := r.workloadCorrectionProcessor(&instance)
		if err != nil {
			return requeue, err
		}
	}
	
	// 優先 svc 處理邏輯
	svcStatus, err := r.svc(ctx, instance)
	if err != nil {
		er := r.workloadPhase(ctx, instance, workloadsv1alpha1.FailedPhase)
		if er != nil {
			return requeue, er
		}
		return requeue, err
	}

	// 工作負載 處理邏輯
	dgStatus, err := r.deploymentGroup(ctx, instance, req)
	if err != nil {
		er := r.workloadPhase(ctx, instance, workloadsv1alpha1.FailedPhase)
		if er != nil {
			return ctrl.Result{}, er
		}
		return requeue, err
	}

	// wk 的 status 更新處理
	err  := r.workloadStatus(ctx, instance, dgStatus, svcStatus)
	if err != nil {
		return requeue, err
	}

	return forget, nil
}

operator 的書寫邏輯 圍繞以下四點即可:

觀察:通過監控Kubernetes資源物件變化的事件來獲取當前物件狀態,只需要注入EventHandler讓client-go 將變化的事件物件資訊放入WorkQueue中

分析:確定當前狀態和期望狀態的不同,由Worker完成.

執行:執行能夠驅動物件當前狀態變化的操作,由Worker完成.

更新:更新物件的當前狀態,由Worker完成.

5)、最近在看同事的xxx專案的devops模組,有所感悟:1、開發對需求的實現能力外,其實也應該對要實現的功能有一定的理解。2、對於中介軟體的掌握(比如Jenkins 的pipeline的書寫)。

6)、這一年還幫助同事處理運維問題,幫助同學處理運維問題,也接過外快處理運維相關的問題,也基本每週都抽時間看看雲原生相關的知識。偏向開發是必然要的,運維也是規劃的重點,需要有意多接觸。

綜上,其實在過去的一年的開發嚴格意義還是圍繞雲原生在進行,也符合對職業生涯的規劃:運維 --> 雲原生運維 --> 容器開發(運維開發) --> sre(偏向開發的運維崗) -->

一年來的收穫

這一年來收穫很多,依如20年的運維工作一樣,對職業產生深遠影響:

1、查詢資料由csdn/部落格園 --> github/官網

2、研發能力由面向百度 --> 面向google/pkg

3、由遇到問題就請教同事 --> 和同事探討/自我處理

4、由在一家初創企業 --> 一家還算適中的公司

展望下一年

在接下來的一年,重點實現以下幾點:

1、鞏固已掌握的

2、具備獨立解決問題的能力

3、不斷降低bug率 ,做到需求即理解、理解即實現、實現即交付。

4、對服務治理、微服務、資料庫中介軟體、serverless 、演算法 展開攻關

5、跳槽 ,再入江湖,出道下山、世界這麼大

特別感謝

以如20年的貴人,阿里雲MVP 如今入職位元組的石老大一樣,在過去的一年,遇到了我飛飛哥哥,不斷騷擾與學習他的長處,嘿嘿嘿。

未來一年,依然堅信,懂雲原生的go開發 是屬於當下及未來一個時期的所需。凡是過往、皆為序章。

相關文章