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.yamlapiVersion: apps/v1kind: Deploymentmetadata: name: k8s-demo namespace: netcore labels: name: k8s-demospec: 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: ServiceapiVersion: v1metadata: name: k8s-demo namespace: netcorespec: 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.
#查看podkubectl describe pod -l name-k8s-demo -n netcore

ASP.NET Core微服务 on K8S(Jessetalk)(第一章:详解基本对象及服务发现)(持续更新)

本作品采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议进行许可。

欢迎转载、使用、重新发布,但务必保留文章署名 郑子铭 (包含链接: http://www.cnblogs.com/MingsonZheng/ ),不得用于商业目的,基于本文修改后的作品务必以相同的许可发布。

如有任何疑问,请与我联系 (504025730@qq.com) 。

相关文章