K8s核心资源对象-Pod(创建流程)
K8s核心资源对象-Pod(创建流程) 基于1.25 如何创建Pod容器通过kubelet 创建 Ref:https://github.com/kubernetes/kubernetes/blob/88e994f6bf8fc88114c5b733e09afea339bea66d/pkg/kubelet/kuberuntime/kuberuntime_manager.go#L668 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361...
K8s核心资源对象-Pod(Container)
K8s核心资源对象-Pod(Container) 基于1.25 Container相关字段 Ref:https://github.com/kubernetes/kubernetes/blob/88e994f6bf8fc88114c5b733e09afea339bea66d/pkg/apis/core/types.go#L2167 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475// Container represents a single container that is expected to be run on the host.type Container struct { // Required: This must be a DNS_LABEL. Each container in a pod must // have ...
K8s核心资源对象-Pod(PodSpec)
K8s核心资源对象-Pod(PodSpec) 基于1.25 什么是PodPod是K8s最小可部署的单元。一个Pod可以有多个容器 每一个Pod,预置了一个Pause容器,其命名空间、IPC、网络和存储资源被Pod中其他容器共享 Ref:https://github.com/kubernetes/api/blob/2be23f6c5a7184af9846ff458a11751765ea2bde/core/v1/types.go#L3721 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261...
K8s核心资源对象- 概述(元数据- metav1.ObjectMeta)
K8s核心资源对象- 概述(元数据- metav1.ObjectMeta) 基于1.25 K8s资源对象K8s中主要按照:工作负载(Workload)、发现和负载均衡(Discovery & LB)、配置和存储(Config & Storage) 下面介绍一下metav1.ObjectMeta的属性 NameName是资源对象的入门属性,但是资源对象不一定是客户端传入的Name PodName Ref:https://github.com/kubernetes/kubernetes/blob/88e994f6bf8fc88114c5b733e09afea339bea66d/pkg/kubelet/config/common.go#L52 1234// Generate a pod name that is unique among nodes by appending the nodeName.func generatePodName(name string, nodeName types.NodeName) string { return ...
容器环境-GOMAXPROCS参数设置
容器环境-GOMAXPROCS参数设置 GOMAXPROCS通过设定 GOMAXPROCS,用户可以调整调度器中 Processor(简称P)的数量。由于每个系统线程,必须要绑定 P ,P 才能把G交给 M 执行。所以 P 的数量会很大程度上影响 Go Runtime 的并发表现。GOMAXPROCS 在版本 1.5后的默认值是机器的 CPU 核数 (runtime.NumCPU) 设置GOMAXPROCS1234567891011121314package mainimport ( "fmt" "runtime")func main() { n := runtime.NumCPU() // 获取机器的CPU核心数 fmt.Printf("NumCPU: %d\n", n) if n > 0 { runtime.GOMAXPROCS(n) // 设置GOMAXPROCS为CPU核心数 }} 容器内运行输出的是宿主机的CPU...
Go-Options模式
Go-Options模式Options模式Options模式可以让具有多个可选参数的函数或者方法更整洁和好扩展,当一个函数具有五六个甚至十个以上的可选参数时使用这种模式的优势会体现的很明显 问题当我们发送一个Http请求,可能需要携带很多参数。比如: 1func HttpRequest(method string, url string, body []byte, headers map[string]string, timeout time.Duration) 有的时候又可能有些参数是不需要的,所以可能变成了: 1HttpRequest('GET', 'https://www.baidu.com', nil, nil, 2 * time.Second) 解决办法一:把配置全转换为结构体对象1234567type HttpClientConfig struct { timeout time.Duration headers map[string]string body []byte}func HttpR...
Prometheus源码:存储指标
Prometheus源码:存储指标 基于release-3.0 存储指标结构1234567891011121314151617181920212223242526272829// File Path: scrape/scrapetype scrapeCache struct { // 被缓存的批次数 iter uint64 // Current scrape iteration. // 上次成功时有多少序列和元数据条目。 // How many series and metadata entries there were at the last success. successfulCount int // Parsed string to an entry with information about the actual label set // and its storage reference. series map[string]*cacheEntry // Cache of dropped metric strings and their i...
Prometheus源码:指标采集
Prometheus源码:指标采集 基于release-3.0 指标采集的流程 构造ScrapeManager实例 加载配置 启动ScrapeManger实例 ScrapeManager负责维护scrapePool,并且管理scrape组件的生命周期。 ScrapeManager调用NewManager方法完成对ScrapeManager实例的创建: 1234567891011121314151617181920212223// FILE PATH:scrape/manager.gotype Manager struct { opts *Options // 系统日志记录 logger log.Logger // 指标存储器 append storage.Appendable graceShut chan struct{} offsetSeed uint64 // Global offsetSeed seed is used to spread scrape workl...
Prometheus源码:服务发现
Prometheus源码:服务发现服务发现的定义流程: scrape发现服务进行统一管理,Prometheus对所支持的发 现服务都抽象出Discoverer接口,各scrape发现服务都必须实现该接 口并用于服务发现 Discover接口定义了Run()接口: 1234567// FILE Path:prometheus/discovery/discoverytype Discoverer interface { // Run hands a channel to the discovery provider (Consul, DNS, etc.) through which // it can send updated target groups. It must return when the context is canceled. // It should not close the update channel on returning. Run(ctx context.Context, up chan<- []*target...
Prometheus源码:启动
Prometheus源码:启动 基于release-3.0 目录结构 cmd主程序入口 config 默认配置参数设置及配置文件解析 discovery 服务发现方式的实现,如 consul ,kubernetes ,dns 等 notifier 生成告警信息及告警信息发送 promql 目录为 规则计算的具体实现,根据载入的规则进行规则计算,并生成告警配置 prompb 目录定义了三种协议,远程存储协议、rpc通信协议和types协议 scrape 指标采集 relabel 目录实现了对指标维度(label)的重置处理,根据promtheus.yaml中配置文件中relabel_config配置项内容重置指标维度 retrieval 目录为Prometheus的数据采集模块,实现了对采集服务的调度和对指标数据的采集 rules 目录为Prometheus的规则管理模块,用于实现规则加载、计算调度和告警信息的回调; storage 目录为Prometheus的指标存储模块,又remote、tsdb存储俩种 tsdb 数据存储相关 web 目录是 Prometheus Web服务...