小编San*_*́́́的帖子

如何在 Kubernetes 的 pod 中限制 .net core 应用程序的内存大小?

我有一个 kubernetes 集群,每个节点上有 16Gb RAM

以及一个典型的 dotnet core webapi 应用程序

我尝试像这样配置限制:

apiVersion: v1
kind: LimitRange
metadata:
  name: mem-limit-range
spec:
  limits:
  - default:
      memory: 512Mi
    defaultRequest:
      memory: 256Mi
    type: Container
Run Code Online (Sandbox Code Playgroud)

但我的应用程序相信可以使用 16Gb

因为cat /proc/meminfo | head -n 1返回MemTotal: 16635172 kB(或者可能来自 cgroups,我不确定)

所以..可能是限制不起作用?

不!K8s 在达到内存限制时成功杀死了我的 pod

.net core 有有趣的 GC 模式,更多细节在这里。这是一个很好的模式,但看起来它对 k8s 不起作用,因为应用程序获取了错误的内存信息。无限的 Pod 可以获得所有主机内存。但有限制——他们会死。

现在我看到两种方法:

  1. 使用 GC 工作站
  2. 使用限制和k8s 就绪探针:处理程序将在每次迭代时检查当前内存,如果当前使用的内存接近 80%,则调用 GC.Collect()(我将通过 env 变量传递限制)

如何在 Kubernetes 的 pod 中限制 .net core 应用程序的内存大小?

如何在 …

asp.net-web-api kubernetes .net-core asp.net-core

6
推荐指数
2
解决办法
6435
查看次数

无法解析参数 'Microsoft.AspNetCore.Mvc.ApiExplorer.IApiDescriptionGroupCollectionProvider apiDescriptionsProvider

我们使用 swagger 来探索 api,有一次我们关闭了 razor。

这导致了招摇的问题

原始错误:

An unhandled exception occurred while processing the request.
DependencyResolutionException: None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder' 
  on type 'Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator' can be invoked with the available services and parameters:
Cannot resolve parameter 'Microsoft.AspNetCore.Mvc.ApiExplorer.IApiDescriptionGroupCollectionProvider apiDescriptionsProvider' 
  of constructor 'Void .ctor(Microsoft.AspNetCore.Mvc.ApiExplorer.IApiDescriptionGroupCollectionProvider, Swashbuckle.AspNetCore.SwaggerGen.ISchemaRegistryFactory, Microsoft.Extensions.Options.IOptions`1[Swashbuckle.AspNetCore.SwaggerGen.SwaggerGeneratorOptions])'.
Cannot resolve parameter 'Microsoft.AspNetCore.Mvc.ApiExplorer.IApiDescriptionGroupCollectionProvider apiDescriptionsProvider' 
of constructor 'Void .ctor(Microsoft.AspNetCore.Mvc.ApiExplorer.IApiDescriptionGroupCollectionProvider, Swashbuckle.AspNetCore.SwaggerGen.ISchemaRegistryFactory, Swashbuckle.AspNetCore.SwaggerGen.SwaggerGeneratorOptions)'.
Autofac.Core.Activators.Reflection.ReflectionActivator.GetValidConstructorBindings(IComponentContext context, IEnumerable<Parameter> parameters)
Run Code Online (Sandbox Code Playgroud)

c# swagger .net-core asp.net-core

3
推荐指数
1
解决办法
1893
查看次数