【问题标题】:configmap changes not picked up while deploying same image version in AKS(.NET)在 AKS(.NET) 中部署相同的映像版本时未获取 configmap 更改
【发布时间】: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


    【解决方案1】:

    我看不到 github 链接中提到的任何示例。即使在升级到 .NET6 之后,我也面临着这个问题。所以我已经解决了它的kubernetes方式。我添加了重新启动命令后部署。所以当 pod 回来时,它会带有新的配置。

    kubectl rollout restart deployment ***service-deployment --namespace=${{ parameters.kubernetesNS }}
    

    【讨论】:

      猜你喜欢
      • 2021-06-13
      • 1970-01-01
      • 1970-01-01
      • 2018-03-24
      • 1970-01-01
      • 1970-01-01
      • 2020-03-25
      • 1970-01-01
      • 2023-03-21
      相关资源
      最近更新 更多