1. 程式人生 > >ASP.NET Core微服務 on K8S(Jessetalk)(第一章:詳解基本物件及服務發現)(持續更新)

ASP.NET Core微服務 on K8S(Jessetalk)(第一章:詳解基本物件及服務發現)(持續更新)

課程連結:http://video.jessetalk.cn/course/explore

良心課程,大家一起來學習哈!

任務1:課程介紹

任務2:Labels and Selectors

所有資源物件(包括Pod, Service, Namespace, Volume)都可以打 Label,定義標籤

Selectors:=, !=, in, not in, and 關係

Kubernetes Labels 和 Selectors

#deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: k8s-demo
  namespace: netcore
  labels:
    name: k8s-demo
spec:
  replicas: 2 #2個例項
  selector: #該selector用於匹配Pod,對應15行的labels
    matchLabels:
      name: k8s-demo
  template:
    metadata:
      labels:
        name: k8s-demo #給Pod打標籤
    spec:
      containers:
      - name: k8s-demo
        image:  jessetalk/k8s-demo
        ports:
        - containerPort: 80
        imagePullPolicy: Always

---

kind: Service
apiVersion: v1
metadata:
  name: k8s-demo
  namespace: netcore
spec:
  type: NodePort
  ports:
    - port: 80
      targetPort: 80
  selector: #該selector用於選擇Deployment的Pod,對應15行的labels
    name: k8s-demo #用Selectors來將Service繫結到Pod
#kubectl label selectors 查詢(使用 kubectl 來針對 apiserver ,並且使用Equality-based的條件)
$ kubectl get pods -l environment=production,tier=frontend

任務3: Pod(容器組)的資料無狀態與生命週期

永續性:無狀態(資料沒有儲存)

名詞解釋 Pods

為何如此設計?

  • 高可用,當發生一些刪除或者維護的過程時,Pod會自動的在他們被終止之前建立新的替代
  • 解偶控制器和服務,後段管理器僅僅監控Pod
  • 排程和管理的易用性

Pod phase

Kubernetes Pod 生命週期

  • 掛起(Pending):Pod 已被 Kubernetes 系統接受,但有一個或者多個容器映象尚未建立。等待時間包括排程 Pod 的時間和通過網路下載映象的時間,這可能需要花點時間。
  • 執行中(Running):該 Pod 已經繫結到了一個節點上,Pod 中所有的容器都已被建立。至少有一個容器正在執行,或者正處於啟動或重啟狀態。
  • 成功(Succeeded):Pod 中的所有容器都被成功終止,並且不會再重啟。
  • 失敗(Failed):Pod 中的所有容器都已終止了,並且至少有一個容器是因為失敗終止。也就是說,容器以非0狀態退出或者被系統終止。
  • 未知(Unknown):因為某些原因無法取得 Pod 的狀態,通常是因為與 Pod 所在主機通訊失敗。

Pod conditions(history)

Pod Lifecycle

The type field is a string with the following possible values:

  • PodScheduled: the Pod has been scheduled to a node;
  • Ready: the Pod is able to serve requests and should be added to the load balancing pools of all matching Services;
  • Initialized: all init containers have started successfully;
  • Unschedulable: the scheduler cannot schedule the Pod right now, for example due to lacking of resources or other constraints;
  • ContainersReady: all containers in the Pod are ready.
#檢視pod
kubectl describe pod -l name-k8s-demo -n netcore

知識共享許可協議

本作品採用知識共享署名-非商業性使用-相同方式共享 4.0 國際許可協議進行許可。

歡迎轉載、使用、重新發布,但務必保留文章署名 鄭子銘 (包含連結: http://www.cnblogs.com/MingsonZheng/ ),不得用於商業目的,基於本文修改後的作品務必以相同的許可釋出。

如有任何疑問,請與我聯絡 ([email protected]) 。