
# CoreDNS配置一致性检查异常处理
#### 检查项内容
检查当前CoreDNS关键配置Corefile是否同Helm Release记录存在差异，差异的部分可能在插件升级时被覆盖，**影响集群内部域名解析**。
#### 解决方案
您可在明确差异配置后，单独升级CoreDNS插件。
1. 配置Kubectl命令，具体请参见[通过kubectl连接集群](https://support.huaweicloud.com/usermanual-cce/cce_10_0107.html)。
2. 获取当前生效的Corefile。
   
   ```
   kubectl get cm -nkube-system coredns -o jsonpath='{.data.Corefile}' > corefile_now.txt
   cat corefile_now.txt
   ```
   
   
3. 获取Helm Release记录中的Corefile。
   
   ```
   latest_release=`kubectl get secret -nkube-system -l owner=helm -l name=cceaddon-coredns --sort-by=.metadata.creationTimestamp | awk 'END{print $1}'`
   kubectl get secret -nkube-system $latest_release -o jsonpath='{.data.release}' | base64 -d | base64 -d | gzip -d | python -m json.tool | python -c "
   from __future__ import print_function
   import json,sys,re,yaml;
   manifests = json.load(sys.stdin)['manifest']
   files = re.split('(?:^|\s*\n)---\s*',manifests)
   for file in files:
       if 'coredns/templates/configmap.yaml' in file and 'Corefile' in file:
         corefile = yaml.safe_load(file)['data']['Corefile']
         print(corefile,end='')
         exit(0);
   print('error')
   exit(1);
   " > corefile_record.txt
   cat corefile_record.txt
   ```
   
   
4. 对比[2]和[3]的输出差异。
   
   ```
   diff corefile_now.txt corefile_record.txt -y;
   ```
   图1查看输出差异   
   ![](https://support.huaweicloud.com/usermanual-cce/zh-cn_image_0000001522398532.png "点击放大")
   
   
5. 返回CCE控制台，单击集群名称进入集群控制台，前往"插件中心"，选择CoreDNS插件单击"升级"。 
   若要保留差异部分配置，您可采用以下方法之一：
   - （推荐）将"parameterSyncStrategy"参数配置为"inherit"，差异配置将自动继承，由系统自动解析、识别与继承差异参数。
     ![](https://support.huaweicloud.com/usermanual-cce/public_sys-resources/caution_3.0-zh-cn.png)
     设置自动参数继承策略（parameterSyncStrategy=inherit）时，"存根域设置"将被清空并合并到"扩展参数配置"中，渲染后效果与原"存根域设置"一致，您可以在"扩展参数配置" 中查看集群的存根域设置。
     
   
   - 将"parameterSyncStrategy"参数配置为"force"，您需手动填写差异配置，详情请参考[CoreDNS域名解析](https://support.huaweicloud.com/usermanual-cce/cce_10_0129.html)。
    
   
   
6. 单击"确定"，等待插件升级完毕，检查CoreDNS各实例均可用，且Corefile符合预期。 
   ```
   kubectl get cm -nkube-system coredns -o jsonpath='{.data.Corefile}'
   ```
   
   
7. 编辑CoreDNS插件配置的"parameterSyncStrategy"参数，重置为"ensureConsistent"，继续开启配置一致性校验。 
   同时建议您后续通过CCE插件管理的参数配置功能修改Corefile配置，避免产生差异。
   
   
 
