【发布时间】:2022-10-06 15:23:03
【问题描述】:
我正在使用 Azure DevOps 将 .NET 3.1 应用程序部署到 AKS。如果只有配置更改并且代码中没有真正的更改,则在部署时,我们部署相同的映像,仅更改配置,但在执行此操作时,即使配置映射已更新但 pod 不理解有一个变化,仍然从以前的配置中读取。我必须手动删除 pod,然后 AKS 自动创建 pod 并选择最新的配置。
从这里https://medium.com/@fbeltrao/automatically-reload-configuration-changes-based-on-kubernetes-config-maps-in-a-net-d956f8c8399a 和这里https://github.com/dotnet/runtime/issues/36091 那里有一个问题。我已经使用符号链接遵循了解决方法https://github.com/dotnet/runtime/issues/36091#issuecomment-786931531,但它不适用于 .NET core 3.1 或 6.0
.ConfigureAppConfiguration(c => c.AddSymLinkJsonFile(\"config/appsettings.json\", optional: true, reloadOnChange: true));
namespace Microsoft.Extensions.Configuration
{
internal static class JsonSymlinkConfigurationExtensions
{
internal static void AddSymLinkJsonFile(this IConfigurationBuilder c, string relativePath, bool optional, bool reloadOnChange)
{
var fileInfo = c.GetFileProvider().GetFileInfo(relativePath);
if (TryGetSymLinkTarget(fileInfo.PhysicalPath, out string targetPath))
{
string targetDirectory = Path.GetDirectoryName(targetPath);
if (TryGetSymLinkTarget(targetDirectory, out string symlinkDirectory))
{
targetDirectory = symlinkDirectory;
}
c.AddJsonFile(new PhysicalFileProvider(targetDirectory), Path.GetFileName(targetPath), optional, reloadOnChange);
}
else
{
c.AddJsonFile(relativePath, optional, reloadOnChange);
}
}
private static bool TryGetSymLinkTarget(string path, out string target, int maximumSymlinkDepth = 32)
{
target = null;
int depth = 0;
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
var symbolicLinkInfo = new UnixSymbolicLinkInfo(path);
while (symbolicLinkInfo.Exists && symbolicLinkInfo.IsSymbolicLink)
{
target = symbolicLinkInfo.ContentsPath;
if (!Path.IsPathFullyQualified(target))
{
target = Path.GetFullPath(target, Path.GetDirectoryName(symbolicLinkInfo.FullName));
}
symbolicLinkInfo = new UnixSymbolicLinkInfo(target);
if (depth++ > maximumSymlinkDepth)
{
throw new InvalidOperationException(\"Exceeded maximum symlink depth\");
}
}
}
return target != null;
}
}
}
标签: asp.net-core kubernetes azure-aks asp.net-core-3.1 configmap