k8s笔记——client-go与 Kubernetes APIServer 交互的客户端

文章目录

  • 四种Kubernetes APIServer 交互的客户端
    • RESTClient
    • clientSet
    • dynamicClient
    • DiscoveryClient
  • 创建、更新、查询、删除Deployment
  • 参考资料

四种Kubernetes APIServer 交互的客户端

Client-Go 共提供了 4 种与 Kubernetes APIServer 交互的客户端。分别是 RESTClient、DiscoveryClient、ClientSet、DynamicClient。

  • RESTClient:最基础的客户端,主要是对 HTTP 请求进行了封装,支持 Json 和 Protobuf 格式的数据。
  • DiscoveryClient:发现客户端,负责发现 APIServer 支持的资源组、资源版本和资源信息的。
  • ClientSet:负责操作 Kubernetes 内置的资源对象,例如:Pod、Service等。
  • DynamicClient:动态客户端,可以对任意的 Kubernetes 资源对象进行通用操作,包括 CRD。

RESTClient

package mainimport ("context""flag""fmt""path/filepath"_ "time"corev1 "k8s.io/api/core/v1""k8s.io/client-go/kubernetes/scheme""k8s.io/client-go/rest"_ "k8s.io/apimachinery/pkg/api/errors"_ "k8s.io/client-go/kubernetes""k8s.io/client-go/tools/clientcmd""k8s.io/client-go/util/homedir"
)func main() {var kubeconfig *stringif home := homedir.HomeDir(); home != "" {kubeconfig = flag.String("kubeconfig", filepath.Join(home, ".kube", "config"), "(optional) absolute path to the kubeconfig file")} else {kubeconfig = flag.String("kubeconfig", "", "absolute path to the kubeconfig file")}// 把用户传递的命令行参数解析为对应变量的值flag.Parse()// use the current context in kubeconfig   在kubeconfig中使用当前上下文config, err := clientcmd.BuildConfigFromFlags("", *kubeconfig)if err != nil {panic(err.Error())}// 使用 RESTClient 需要开发者自行设置资源 URL// pod 资源没有 group,在核心组,所以前缀是 apiconfig.APIPath = "api"// 设置 corev1 groupVersionconfig.GroupVersion = &corev1.SchemeGroupVersion// 设置解析器,用于用于解析 schemeconfig.NegotiatedSerializer = scheme.Codecs.WithoutConversion()// 初始化 RESTClientrestClient, err := rest.RESTClientFor(config)if err != nil {panic(err.Error())}// 调用结果用 podList 解析result := &corev1.PodList{}// 获取 kube-system 命名空间的 podnamespace := "kube-system"// 链式调用 RESTClient 方法获取,并将结果解析到 corev1.PodList{}err = restClient.Get().Namespace(namespace).Resource("pods").Do(context.TODO()).Into(result)if err != nil {panic(err.Error())}// 打印结果for _, pod := range result.Items {fmt.Printf("namespace: %s, pod: %s \n", pod.Namespace, pod.Name)//fmt.Printf(" Kind: %s, APIVersion: %s \n", pod.Kind, pod.APIVersion)}}

执行go build -o app .
输出

namespace: kube-system, pod: coredns-6554b8b87f-f8dq6 
namespace: kube-system, pod: coredns-6554b8b87f-qr4wn 
namespace: kube-system, pod: etcd-minikube 
namespace: kube-system, pod: kube-apiserver-minikube 
namespace: kube-system, pod: kube-controller-manager-minikube 
namespace: kube-system, pod: kube-proxy-tppnz 
namespace: kube-system, pod: kube-scheduler-minikube 
namespace: kube-system, pod: storage-provisioner 

clientSet

package mainimport ("context""flag""fmt""path/filepath"metav1 "k8s.io/apimachinery/pkg/apis/meta/v1""k8s.io/client-go/kubernetes""k8s.io/client-go/tools/clientcmd""k8s.io/client-go/util/homedir"
)func main() {var kubeconfig *stringif home := homedir.HomeDir(); home != "" {kubeconfig = flag.String("kubeconfig", filepath.Join(home, ".kube", "config"), "(optional) absolute path to the kubeconfig file")} else {kubeconfig = flag.String("kubeconfig", "", "absolute path to the kubeconfig file")}// 把用户传递的命令行参数解析为对应变量的值flag.Parse()// use the current context in kubeconfig   在kubeconfig中使用当前上下文config, err := clientcmd.BuildConfigFromFlags("", *kubeconfig)if err != nil {panic(err.Error())}// 获取 clientSetclientSet, err := kubernetes.NewForConfig(config)if err != nil {panic(err.Error())}namespace := "kube-system"// 链式调用 ClientSet 获取 pod 列表podList, err := clientSet.CoreV1().Pods(namespace).List(context.TODO(), metav1.ListOptions{})if err != nil {panic(err.Error())}for _, pod := range podList.Items {fmt.Printf("namespace: %s, pod: %s \n", pod.Namespace, pod.Name)}
}

dynamicClient

package mainimport ("context""flag""fmt""path/filepath"corev1 "k8s.io/api/core/v1"metav1 "k8s.io/apimachinery/pkg/apis/meta/v1""k8s.io/apimachinery/pkg/runtime""k8s.io/apimachinery/pkg/runtime/schema""k8s.io/client-go/dynamic""k8s.io/client-go/tools/clientcmd""k8s.io/client-go/util/homedir"
)func main() {var kubeconfig *stringif home := homedir.HomeDir(); home != "" {kubeconfig = flag.String("kubeconfig", filepath.Join(home, ".kube", "config"), "(optional) absolute path to the kubeconfig file")} else {kubeconfig = flag.String("kubeconfig", "", "absolute path to the kubeconfig file")}// 把用户传递的命令行参数解析为对应变量的值flag.Parse()// use the current context in kubeconfig   在kubeconfig中使用当前上下文config, err := clientcmd.BuildConfigFromFlags("", *kubeconfig)if err != nil {panic(err.Error())}// 初始化 DynamicClientdynamicClient, err := dynamic.NewForConfig(config)if err != nil {panic(err.Error())}// 提供 pod 的 gvr,因为是动态调用,dynamicClient 不知道需要操作哪个资源,所以需要自己提供gvr := schema.GroupVersionResource{Group:    "",Version:  "v1",Resource: "pods",}//链式调用 dynamicClient 获取数据result, err := dynamicClient.Resource(gvr).Namespace("kube-system").List(context.TODO(), metav1.ListOptions{})if err != nil {panic(err.Error())}podList := &corev1.PodList{}// 将结果解析到 podList scheme 中err = runtime.DefaultUnstructuredConverter.FromUnstructured(result.UnstructuredContent(), podList)for _, pod := range podList.Items {fmt.Printf("namespace: %s, pod: %s \n", pod.Namespace, pod.Name)fmt.Printf(" Kind: %s, APIVersion: %s \n", pod.Kind, pod.APIVersion)}
}

DiscoveryClient

package mainimport ("flag""fmt""path/filepath""k8s.io/apimachinery/pkg/runtime/schema""k8s.io/client-go/discovery""k8s.io/client-go/tools/clientcmd""k8s.io/client-go/util/homedir"
)func main() {var kubeconfig *stringif home := homedir.HomeDir(); home != "" {kubeconfig = flag.String("kubeconfig", filepath.Join(home, ".kube", "config"), "(optional) absolute path to the kubeconfig file")} else {kubeconfig = flag.String("kubeconfig", "", "absolute path to the kubeconfig file")}// 把用户传递的命令行参数解析为对应变量的值flag.Parse()// use the current context in kubeconfig   在kubeconfig中使用当前上下文config, err := clientcmd.BuildConfigFromFlags("", *kubeconfig)if err != nil {panic(err.Error())}// 初始化 DiscoveryClientdiscoveryClient, err := discovery.NewDiscoveryClientForConfig(config)if err != nil {panic(err.Error())}// 获取集群所有资源_, apiResourceList, err := discoveryClient.ServerGroupsAndResources()if err != nil {panic(err.Error())}for _, resources := range apiResourceList {gv, err := schema.ParseGroupVersion(resources.GroupVersion)if err != nil {panic(err.Error())}for _, resource := range resources.APIResources {fmt.Printf("group: %s, version: %s, resource: %s \n", gv.Group, gv.Version, resource.Name)}}
}

输出

group: authentication.k8s.io, version: v1, resource: selfsubjectreviews 
group: authentication.k8s.io, version: v1, resource: tokenreviews 
group: authorization.k8s.io, version: v1, resource: localsubjectaccessreviews 
group: authorization.k8s.io, version: v1, resource: selfsubjectaccessreviews 
group: authorization.k8s.io, version: v1, resource: selfsubjectrulesreviews 
group: authorization.k8s.io, version: v1, resource: subjectaccessreviews 
group: storage.k8s.io, version: v1, resource: csidrivers 
group: storage.k8s.io, version: v1, resource: csinodes 
group: storage.k8s.io, version: v1, resource: csistoragecapacities 
group: storage.k8s.io, version: v1, resource: storageclasses 
group: storage.k8s.io, version: v1, resource: volumeattachments 
group: storage.k8s.io, version: v1, resource: volumeattachments/status 
group: admissionregistration.k8s.io, version: v1, resource: mutatingwebhookconfigurations 
group: admissionregistration.k8s.io, version: v1, resource: validatingwebhookconfigurations 
group: flowcontrol.apiserver.k8s.io, version: v1beta3, resource: flowschemas 
group: flowcontrol.apiserver.k8s.io, version: v1beta3, resource: flowschemas/status 
group: flowcontrol.apiserver.k8s.io, version: v1beta3, resource: prioritylevelconfigurations 
group: flowcontrol.apiserver.k8s.io, version: v1beta3, resource: prioritylevelconfigurations/status 
group: apiregistration.k8s.io, version: v1, resource: apiservices 
group: apiregistration.k8s.io, version: v1, resource: apiservices/status 
group: apps, version: v1, resource: controllerrevisions 
group: apps, version: v1, resource: daemonsets 
group: apps, version: v1, resource: daemonsets/status 
group: apps, version: v1, resource: deployments 
group: apps, version: v1, resource: deployments/scale 
group: apps, version: v1, resource: deployments/status 
group: apps, version: v1, resource: replicasets 
group: apps, version: v1, resource: replicasets/scale 
group: apps, version: v1, resource: replicasets/status 
group: apps, version: v1, resource: statefulsets 
group: apps, version: v1, resource: statefulsets/scale 
group: apps, version: v1, resource: statefulsets/status 
group: , version: v1, resource: bindings 
group: , version: v1, resource: componentstatuses 
group: , version: v1, resource: configmaps 
group: , version: v1, resource: endpoints 
group: , version: v1, resource: events 
group: , version: v1, resource: limitranges 
group: , version: v1, resource: namespaces 
group: , version: v1, resource: namespaces/finalize 
group: , version: v1, resource: namespaces/status 
group: , version: v1, resource: nodes 
group: , version: v1, resource: nodes/proxy 
group: , version: v1, resource: nodes/status 
group: , version: v1, resource: persistentvolumeclaims 
group: , version: v1, resource: persistentvolumeclaims/status 
group: , version: v1, resource: persistentvolumes 
group: , version: v1, resource: persistentvolumes/status 
group: , version: v1, resource: pods 
group: , version: v1, resource: pods/attach 
group: , version: v1, resource: pods/binding 
group: , version: v1, resource: pods/ephemeralcontainers 
group: , version: v1, resource: pods/eviction 
group: , version: v1, resource: pods/exec 
group: , version: v1, resource: pods/log 
group: , version: v1, resource: pods/portforward 
group: , version: v1, resource: pods/proxy 
group: , version: v1, resource: pods/status 
group: , version: v1, resource: podtemplates 
group: , version: v1, resource: replicationcontrollers 
group: , version: v1, resource: replicationcontrollers/scale 
group: , version: v1, resource: replicationcontrollers/status 
group: , version: v1, resource: resourcequotas 
group: , version: v1, resource: resourcequotas/status 
group: , version: v1, resource: secrets 
group: , version: v1, resource: serviceaccounts 
group: , version: v1, resource: serviceaccounts/token 
group: , version: v1, resource: services 
group: , version: v1, resource: services/proxy 
group: , version: v1, resource: services/status 
group: networking.k8s.io, version: v1, resource: ingressclasses 
group: networking.k8s.io, version: v1, resource: ingresses 
group: networking.k8s.io, version: v1, resource: ingresses/status 
group: networking.k8s.io, version: v1, resource: networkpolicies 
group: certificates.k8s.io, version: v1, resource: certificatesigningrequests 
group: certificates.k8s.io, version: v1, resource: certificatesigningrequests/approval 
group: certificates.k8s.io, version: v1, resource: certificatesigningrequests/status 
group: coordination.k8s.io, version: v1, resource: leases 
group: events.k8s.io, version: v1, resource: events 
group: batch, version: v1, resource: cronjobs 
group: batch, version: v1, resource: cronjobs/status 
group: batch, version: v1, resource: jobs 
group: batch, version: v1, resource: jobs/status 
group: scheduling.k8s.io, version: v1, resource: priorityclasses 
group: autoscaling, version: v1, resource: horizontalpodautoscalers 
group: autoscaling, version: v1, resource: horizontalpodautoscalers/status 
group: flowcontrol.apiserver.k8s.io, version: v1beta2, resource: flowschemas 
group: flowcontrol.apiserver.k8s.io, version: v1beta2, resource: flowschemas/status 
group: flowcontrol.apiserver.k8s.io, version: v1beta2, resource: prioritylevelconfigurations 
group: flowcontrol.apiserver.k8s.io, version: v1beta2, resource: prioritylevelconfigurations/status 
group: discovery.k8s.io, version: v1, resource: endpointslices 
group: apiextensions.k8s.io, version: v1, resource: customresourcedefinitions 
group: apiextensions.k8s.io, version: v1, resource: customresourcedefinitions/status 
group: policy, version: v1, resource: poddisruptionbudgets 
group: policy, version: v1, resource: poddisruptionbudgets/status 
group: autoscaling, version: v2, resource: horizontalpodautoscalers 
group: autoscaling, version: v2, resource: horizontalpodautoscalers/status 
group: rbac.authorization.k8s.io, version: v1, resource: clusterrolebindings 
group: rbac.authorization.k8s.io, version: v1, resource: clusterroles 
group: rbac.authorization.k8s.io, version: v1, resource: rolebindings 
group: rbac.authorization.k8s.io, version: v1, resource: roles 
group: node.k8s.io, version: v1, resource: runtimeclasses

创建、更新、查询、删除Deployment

使用client-go,实现一个deployment的创建、更新和删除操作。代码依据官方的例子修改而来

package mainimport ("bufio""context""flag""fmt"appsv1 "k8s.io/api/apps/v1"corev1 "k8s.io/api/core/v1"v1 "k8s.io/apimachinery/pkg/apis/meta/v1""k8s.io/client-go/kubernetes"appsresv1 "k8s.io/client-go/kubernetes/typed/apps/v1""k8s.io/client-go/tools/clientcmd""k8s.io/client-go/util/homedir""k8s.io/client-go/util/retry""k8s.io/klog/v2""os""path/filepath"
)func main() {// 1、创建配置文件var kubeconfig *stringif home := homedir.HomeDir(); home != "" {kubeconfig = flag.String("kubeconfig", filepath.Join(home, ".kube", "config"), "(optional) absolute path to the kubeconfig file")} else {kubeconfig = flag.String("kubeconfig", "", "absolute path to the kubeconfig file")}// 把用户传递的命令行参数解析为对应变量的值flag.Parse()// 在kubeconfig中使用当前上下文config, err := clientcmd.BuildConfigFromFlags("", *kubeconfig)if err != nil {panic(err.Error())}// 2、创建clientsetclientset, err := kubernetes.NewForConfig(config)if err != nil {panic(err)}deployClient := clientset.AppsV1().Deployments(corev1.NamespaceDefault)// 3、创建deploymentCreateDeploy(deployClient)prompt()// 4、更新deploymentUpdateDeploy(deployClient)prompt()// 5、查询deploymentListDeploy(deployClient)prompt()// 6、删除deploymentDeleteDeploy(deployClient)
}func CreateDeploy(client appsresv1.DeploymentInterface) {klog.Info("CreateDeploy...........")replicas := int32(2)deploy := appsv1.Deployment{TypeMeta: v1.TypeMeta{Kind:       "Deployment",APIVersion: "apps/v1",},ObjectMeta: v1.ObjectMeta{Name:      "deploy-nginx-demo",Namespace: corev1.NamespaceDefault,},Spec: appsv1.DeploymentSpec{Replicas: &replicas,Selector: &v1.LabelSelector{MatchLabels: map[string]string{"app": "nginx",},},Template: corev1.PodTemplateSpec{ObjectMeta: v1.ObjectMeta{Name: "nginx",Labels: map[string]string{"app": "nginx",},},Spec: corev1.PodSpec{Containers: []corev1.Container{{Name:  "web",Image: "nginx:1.12",Ports: []corev1.ContainerPort{{Protocol:      corev1.ProtocolTCP,ContainerPort: 80,},},},},},},},}dep, err := client.Create(context.Background(), &deploy, v1.CreateOptions{})if err != nil {klog.Errorf("create deployment error:%v", err)return}klog.Infof("create deployment success, name:%s", dep.Name)
}func UpdateDeploy(client appsresv1.DeploymentInterface) {klog.Info("UpdateDeploy...........")// 当有多个客户端对同一个资源进行操作时,可能会发生错误。使用RetryOnConflict来重试,重试相关参数由DefaultRetry来提供err := retry.RetryOnConflict(retry.DefaultRetry, func() error {// 查询要更新的deploydeploy, err := client.Get(context.Background(), "deploy-nginx-demo", v1.GetOptions{})if err != nil {klog.Errorf("can't get deployment, err:%v", err)return nil}// 修改参数后进行更新replicas := int32(1)deploy.Spec.Replicas = &replicasdeploy.Spec.Template.Spec.Containers[0].Image = "nginx:1.13"_, err = client.Update(context.Background(), deploy, v1.UpdateOptions{})if err != nil {klog.Errorf("update deployment error, err:%v", err)}return err})if err != nil {klog.Errorf("update deployment error, err:%v", err)} else {klog.Infof("update deployment success")}}func ListDeploy(client appsresv1.DeploymentInterface) {klog.Info("ListDeploy...........")deplist, err := client.List(context.Background(), v1.ListOptions{})if err != nil {klog.Errorf("list deployment error, err:%v", err)return}for _, dep := range deplist.Items {klog.Infof("deploy name:%s, replicas:%d, container image:%s", dep.Name, *dep.Spec.Replicas, dep.Spec.Template.Spec.Containers[0].Image)}
}func DeleteDeploy(client appsresv1.DeploymentInterface) {klog.Info("DeleteDeploy...........")// 删除策略deletePolicy := v1.DeletePropagationForegrounderr := client.Delete(context.Background(), "deploy-nginx-demo", v1.DeleteOptions{PropagationPolicy: &deletePolicy})if err != nil {klog.Errorf("delete deployment error, err:%v", err)} else {klog.Info("delete deployment success")}
}func prompt() {fmt.Printf("-> Press Return key to continue.")scanner := bufio.NewScanner(os.Stdin)for scanner.Scan() {break}if err := scanner.Err(); err != nil {panic(err)}fmt.Println()
}

参考资料

k8s类型定义2之基础设施TypeMeta与ObjectMeta
k8s编程operator——(2) client-go中的informer
Client-go 客户端
k8s编程operator——(1) client-go基础部分

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/diannao/18501.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

LeetCode精华75题(持续更新)

LeetCode刷题笔记 数组/字符串 交替合并字符串 题目: 给你两个字符串 word1 和 word2 。请你从 word1 开始,通过交替添加字母来合并字符串。如果一个字符串比另一个字符串长,就将多出来的字母追加到合并后字符串的末尾。 返回 合并后的字符…

【iOS】UI学习(一)

UI学习(一) UILabelUIButtonUIButton事件 UIViewUIView对象的隐藏UIView的层级关系 UIWindowUIViewController定时器与视图对象 UISwitch UILabel UILabel是一种可以显示在屏幕上,显示文字的一种UI。 下面使用代码来演示UILabel的功能&#…

AI学习指南数学工具篇-Python中的凸优化库

AI学习指南数学工具篇-Python中的凸优化库 在人工智能和机器学习领域,凸优化是一个非常重要的数学工具。它可以帮助我们解决各种问题,包括线性规划、二次规划、半定规划等。而在Python中,有一个非常优秀的凸优化库,即CVXPY。本文…

做好开源快速开发平台研发创新 助力行业高效发展!

随着信息化时代的到来,科技的力量无处不在。为了提高办公效率,很多大中型企业倾向于使用更为先进的软件平台来助力企业降本增效。在众多助力神器之中,开源快速开发平台低代码技术平台深得广大新老客户朋友的喜爱,它与生俱来的优势…

结合PyTest和Selenium进行网页自动化测试的例子

一个结合PyTest和Selenium进行网页自动化测试的示例。 这个测试用例模拟了一个简单的用户登录过程,并包含了对登录后页面状态的断言。我们将使用Selenium的WebDriver来控制浏览器,并使用PyTest来进行断言。 import pytest from selenium import webdri…

vue2+echarts地图下钻+地图遮盖物散点

一、下载工具 npm i echarts echarts-gl axios -S -S是生产依赖默认是-S不写也可以 -D是开发依赖 二、引入工具 import * as echarts from "echarts"; import "echarts-gl"; import axios from "axios"; 三、HTML部分代码 <div class&…

微信小程序路由跳转

1. wx.navigateTo 作用&#xff1a;保留当前页面&#xff0c;跳转到应用内的某个页面。特点&#xff1a;跳转后目标页面的生命周期函数 onLoad 和 onShow 会被触发。使用场景&#xff1a;一般用于跳转到应用内的其他页面&#xff0c;保留当前页面的状态&#xff0c;例如从文章…

Java数据类型

一、每种数据都定义了 明确的数据类型&#xff0c;在内存中分配了不同大小的 内存空间(字节)。 二、Java数据类型分为两种&#xff1a; 基本数据类型&#xff1a; 数值型&#xff1a; 整数类型&#xff0c;存放整数(byte[1] , short[2] , int[4] , long[8]) 浮点类型&#xff0…

UE5 读取本地图片并转换为base64字符串

调试网址&#xff1a;在线图像转Base64 - 码工具 (matools.com) 注意要加&#xff08;data:image/png;base64,&#xff09; FString UBasicFuncLib::LoadImageToBase64(const FString& ImagePath) {TArray<uint8> ImageData;// Step 1: 读取图片文件到字节数组if (!…

【蓝桥杯】第十四届蓝桥杯大赛软件赛国赛C/C++ 大学 B 组

答题结果页 - 蓝桥云课 (lanqiao.cn) 0子2023 - 蓝桥云课 (lanqiao.cn)&#xff08;暴力枚举 #include<bits/stdc.h> using lllong long; using ullunsigned long long; #define fir first #define sec second //#define int llconst int N1e510; const int mod1e97;int…

C++标准模板(STL)- C 内存管理库 - 分配内存 (std::malloc)

C 内存管理库 分配内存 std::malloc 定义于头文件 <cstdlib> void* malloc( std::size_t size ); 分配 size 字节的未初始化存储。 若分配成功&#xff0c;则返回指向分配的适合对任何标量类型对齐的内存块中&#xff0c;最低&#xff08;首&#xff09;字节的指针…

HT46R002 贴片 SOP8 经济型AD型OTP MCU单片机芯片

HT46R002在智能家居中的具体应用案例可以包括以下几个方面&#xff1a; 1. 智能照明控制&#xff1a;可以用于控制LED灯的亮度和色温&#xff0c;甚至可以通过手机APP远程控制开关和调节灯光效果。 2. 环境监测&#xff1a;用于监测室内温度、湿度、空气质量等&#xff0c;当检…

PostgreSQL和GaussDB对比

PostgreSQL和GaussDB对比 GaussDB 是华为推出的一款基于 PostgreSQL 的企业级数据库产品&#xff0c;通过对 PostgreSQL 进行一系列优化和扩展&#xff0c;使其更加适应企业应用的需求。以下是 PostgreSQL 和 GaussDB 两者之间的对比&#xff0c;从多个方面进行分析&#xff0…

httpJVM

目录 HTTPS如何保证安全 1&#xff09;引入非对称加密 2&#xff09;引入非对称加密 3.中间人攻击 4.解决中间人攻击 JVM 1.JVM内存划分 2.JVM类加载过程 八股内容 3.JVM中的垃圾回收机制 释放垃圾的策略 1.标记-清除 2.复制算法 3.标记-整理 分代回收 HTTPS如何…

GB-T 43696-2024 网络安全技术 零信任参考体系架构

GB-T 43696-2024 网络安全技术 零信任参考体系架构 编写背景 随着网络环境的日益复杂&#xff0c;传统的网络安全策略已经难以满足现代企业的需求。为了应对不断变化的安全威胁&#xff0c;零信任安全模型应运而生。GB-T 43696-2024《网络安全技术 零信任参考体系架构》是中国…

Android Graphics图形栈SurfaceFlinger之间各种Layer以及对应Buffer之间的关系

Android Graphics图形栈SurfaceFlinger之间各种Layer以及对应Buffer之间的关系 SurfaceFlinger layer之间的对应关系

MyBatis学习笔记(周五前学完)

MyBatis-Plus是一个MyBatis的增强工具。在MyBatis的基础上只做增强不做改变&#xff0c;为简化开发、提高效率而生。 通过MyBatis-Plus来进行数据插入时&#xff0c;它默认会 使用雪花算法来生成id&#xff0c;长度比较长 增删改的返回值都是统一的&#xff0c;影响的只有行数。…

给pdf加水印,python实现

from PyPDF2 import PdfReader, PdfWriterdef add_watermark(pdf_file_in, pdf_file_mark, pdf_file_out):"""把水印添加到pdf中"""pdf_output PdfWriter()input_stream open(pdf_file_in, rb)pdf_input PdfReader(input_stream, strictFalse…

基于魔搭开源推理引擎 DashInfer实现CPU服务器大模型推理--理论篇

前言 在人工智能技术飞速发展的今天&#xff0c;如何高效地在CPU上运行大规模的预训练语言模型&#xff08;LLM&#xff09;成为了加速生成式AI应用广泛落地的核心问题。阿里巴巴达摩院模型开源社区ModelScope近期推出了一款名为DashInfer的推理引擎&#xff0c;旨在解决这一挑…

机器学习补充学习

1、Adaboost算法 Adaboost算法是一种集成学习方法&#xff0c;通过结合多个弱学习器来构建一个强大的预测模型。核心思想&#xff1a;如果一个简单的分类器在训练数据上犯错误&#xff0c;那么它在测试数据上也可能犯错误。 Adaboost通过迭代地训练一系列的分类器&#xff0c…