Browse Source

Merge "Add option to deploy coredns"

Zuul 1 month ago
parent
commit
38f1198e82
3 changed files with 94 additions and 0 deletions
  1. 1
    0
      .zuul.d/base.yaml
  2. 1
    0
      .zuul.d/octavia.yaml
  3. 92
    0
      devstack/plugin.sh

+ 1
- 0
.zuul.d/base.yaml View File

@@ -76,6 +76,7 @@
76 76
         kubelet: true
77 77
         kuryr-kubernetes: true
78 78
         kuryr-daemon: true
79
+        coredns: true
79 80
       zuul_copy_output:
80 81
         '{{ devstack_log_dir }}/kubernetes': 'logs'
81 82
     irrelevant-files:

+ 1
- 0
.zuul.d/octavia.yaml View File

@@ -95,6 +95,7 @@
95 95
         kubernetes-controller-manager: false
96 96
         kubernetes-scheduler: false
97 97
         kubelet: false
98
+        coredns: false
98 99
         openshift-master: true
99 100
         openshift-node: true
100 101
         openshift-dnsmasq: true

+ 92
- 0
devstack/plugin.sh View File

@@ -756,6 +756,11 @@ function run_k8s_kubelet {
756 756
         command="$command --fail-swap-on=false"
757 757
     fi
758 758
 
759
+    if is_service_enabled coredns; then
760
+        local k8s_resolv_conf
761
+        command+=" --cluster-dns=${HOST_IP} --cluster-domain=cluster.local"
762
+    fi
763
+
759 764
     wait_for "Kubernetes API Server" "$KURYR_K8S_API_URL"
760 765
     if [[ "$USE_SYSTEMD" = "True" ]]; then
761 766
         # If systemd is being used, proceed as normal
@@ -769,6 +774,86 @@ function run_k8s_kubelet {
769 774
     fi
770 775
 }
771 776
 
777
+function run_coredns {
778
+    local output_dir=$1
779
+    mkdir -p "$output_dir"
780
+    rm -f ${output_dir}/coredns.yml
781
+    cat >> "${output_dir}/coredns.yml" << EOF
782
+apiVersion: v1
783
+kind: ConfigMap
784
+metadata:
785
+  name: coredns
786
+  namespace: kube-system
787
+data:
788
+  Corefile: |
789
+    .:53 {
790
+        bind ${HOST_IP}
791
+        errors
792
+        kubernetes cluster.local in-addr.arpa ip6.arpa {
793
+           pods insecure
794
+           upstream
795
+           fallthrough in-addr.arpa ip6.arpa
796
+        }
797
+        proxy . /etc/resolv.conf
798
+        cache 30
799
+        loop
800
+        reload
801
+        loadbalance
802
+EOF
803
+    if [[ "$ENABLE_DEBUG_LOG_LEVEL" == "True" ]]; then
804
+        cat >> "${output_dir}/coredns.yml" << EOF
805
+        debug
806
+        log
807
+EOF
808
+    fi
809
+    cat >> "${output_dir}/coredns.yml" << EOF
810
+    }
811
+---
812
+apiVersion: extensions/v1beta1
813
+kind: Deployment
814
+metadata:
815
+  name: coredns
816
+  namespace: kube-system
817
+  labels:
818
+    k8s-app: coredns
819
+    kubernetes.io/cluster-service: "true"
820
+    kubernetes.io/name: "CoreDNS"
821
+spec:
822
+  replicas: 1
823
+  selector:
824
+    matchLabels:
825
+      k8s-app: coredns
826
+  template:
827
+    metadata:
828
+      labels:
829
+        k8s-app: coredns
830
+      annotations:
831
+        scheduler.alpha.kubernetes.io/critical-pod: ''
832
+        scheduler.alpha.kubernetes.io/tolerations: '[{"key":"CriticalAddonsOnly", "operator":"Exists"}]'
833
+    spec:
834
+      hostNetwork: true
835
+      containers:
836
+      - name: coredns
837
+        image: coredns/coredns
838
+        imagePullPolicy: Always
839
+        args: [ "-conf", "/etc/coredns/Corefile" ]
840
+        volumeMounts:
841
+        - name: config-volume
842
+          mountPath: /etc/coredns
843
+      dnsPolicy: Default
844
+      volumes:
845
+        - name: config-volume
846
+          configMap:
847
+            name: coredns
848
+            items:
849
+            - key: Corefile
850
+              path: Corefile
851
+EOF
852
+
853
+    /usr/local/bin/kubectl apply -f ${output_dir}/coredns.yml
854
+}
855
+
856
+
772 857
 function run_kuryr_kubernetes {
773 858
     local python_bin=$(which python)
774 859
 
@@ -1073,6 +1158,13 @@ elif [[ "$1" == "stack" && "$2" == "test-config" ]]; then
1073 1158
             run_kuryr_daemon
1074 1159
         fi
1075 1160
 
1161
+        if is_service_enabled coredns; then
1162
+            #Open port 53 so pods can reach the DNS server
1163
+            sudo iptables -I INPUT 1 -p udp -m udp --dport 53 -j ACCEPT
1164
+
1165
+            run_coredns "${DATA_DIR}/kuryr-kubernetes"
1166
+        fi
1167
+
1076 1168
         # Needs kuryr to be running
1077 1169
         if is_service_enabled openshift-dns; then
1078 1170
             configure_and_run_registry

Loading…
Cancel
Save