Skip to content

Commit 5c81676

Browse files
committed
fix(provider): improve network policy for kube-dns access
1 parent 420f8ce commit 5c81676

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

provider/cluster/kube/builder.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ const (
4242

4343
var (
4444
dnsPort = intstr.FromInt(53)
45-
dnsProtocol = corev1.Protocol("UDP")
45+
udpProtocol = corev1.Protocol("UDP")
46+
tcpProtocol = corev1.Protocol("TCP")
4647
)
4748

4849
type builder struct {
@@ -575,17 +576,25 @@ func (b *netPolBuilder) create() ([]*netv1.NetworkPolicy, error) { // nolint:gol
575576
{ // Allow DNS to internal server
576577
Ports: []netv1.NetworkPolicyPort{
577578
{
578-
Protocol: &dnsProtocol,
579+
Protocol: &udpProtocol,
580+
Port: &dnsPort,
581+
},
582+
{
583+
Protocol: &tcpProtocol,
579584
Port: &dnsPort,
580585
},
581586
},
582587
To: []netv1.NetworkPolicyPeer{
583588
{
584-
PodSelector: nil,
585-
NamespaceSelector: nil,
586-
IPBlock: &netv1.IPBlock{
587-
CIDR: "169.254.0.0/16",
588-
Except: nil,
589+
PodSelector: &metav1.LabelSelector{
590+
MatchLabels: map[string]string{
591+
"k8s-app": "kube-dns",
592+
},
593+
},
594+
NamespaceSelector: &metav1.LabelSelector{
595+
MatchLabels: map[string]string{
596+
"kubernetes.io/metadata.name": "kube-system",
597+
},
589598
},
590599
},
591600
},

0 commit comments

Comments
 (0)