Chuyển tới nội dung chính

Điều chỉnh cấu hình CoreDNS trong Kubernetes

Managed - FPT Kubernetes Engine (M-FKE) dùng CoreDNS để resolve domain cho cluster. Vì FPT quản lý CoreDNS nên bạn không thể sửa trực tiếp Corefile — thay vào đó dùng ConfigMap coredns-custom.

ghi chú

Sau khi apply bất kỳ thay đổi coredns-custom nào dưới đây, xóa 2 Pod CoreDNS trong kube-system để reload cấu hình.

Rewrite DNS​

Cấu hình rewrite DNS bằng cách thêm ConfigMap sau trong namespace kube-system:

apiVersion: v1
kind: ConfigMap
metadata:
name: coredns-custom
namespace: kube-system
data:
test.server: |
.com:8053 {
log
errors
rewrite stop {
name regex (.*)\..com {1}.default.svc.cluster.local
answer name (.*)\.default\.svc\.cluster\.local {1}..com
}
forward . /etc/resolv.conf # you can redirect this to a specific DNS server such as 10.0.0.10, but that server must be able to resolve the rewritten domain name
}

Custom forward server​

Để gửi request resolve tới 1 DNS server cụ thể:

apiVersion: v1
kind: ConfigMap
metadata:
name: coredns-custom
namespace: kube-system
data:
test.server: | # you may select any name here, but it must end with the .server file extension
.com:8053 {
forward foo.com 1.1.1.1
forward . 2.2.2.2
}

1.1.1.1 và 2.2.2.2 là các DNS server bạn định nghĩa. forward . 2.2.2.2 gửi request resolve cho domain *.com tới 2.2.2.2.

Custom domain​

Không có ConfigMap coredns-custom, M-FKE không resolve được domain chỉ hợp lệ trong nội bộ cluster (ví dụ puglife.local, không phải domain public). Cấu hình như sau:

apiVersion: v1
kind: ConfigMap
metadata:
name: coredns-custom
namespace: kube-system
data:
puglife.server: | # you may select any name here, but it must end with the .server file extension
puglife.local:8053 {
errors
cache 30
forward . 192.11.0.1 # this is my test/dev DNS server
}

Stub domain​

Cấu hình stub domain như sau — cập nhật custom domain và địa chỉ IP theo đúng hạ tầng của bạn:

apiVersion: v1
kind: ConfigMap
metadata:
name: coredns-custom
namespace: kube-system
data:
test.server: | # you may select any name here, but it must end with the .server file extension
abc.com:8053 {
errors
cache 30
forward . 1.2.3.4
}
my.cluster.local:8053 {
errors
cache 30
forward . 2.3.4.5
}

Hosts plugin​

Thêm bản ghi DNS tùy chỉnh bằng plugin hosts:

apiVersion: v1
kind: ConfigMap
metadata:
name: coredns-custom # this is the name of the configmap you can overwrite with your changes
namespace: kube-system
data:
test.override: | # you may select any name here, but it must end with the .override file extension
hosts {
10.0.0.1 example1.org
10.0.0.2 example2.org
10.0.0.3 example3.org
fallthrough
}

Xem thêm​