Skip to content

Commit b2732f7

Browse files
committed
Enabling DNS support in local-up-cluster.sh
1 parent 5a3dbed commit b2732f7

File tree

2 files changed

+66
-4
lines changed

2 files changed

+66
-4
lines changed

docs/getting-started-guides/locally.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,16 @@ One or more of the Kubernetes daemons might've crashed. Tail the logs of each in
171171

172172
#### The pods fail to connect to the services by host names
173173

174-
The local-up-cluster.sh script doesn't start a DNS service. Similar situation can be found [here](http://issue.k8s.io/6667). You can start a manually. Related documents can be found [here](../../cluster/addons/dns/#how-do-i-configure-it)
174+
To start the DNS service, you need to set the following variables:
175+
176+
```sh
177+
KUBE_ENABLE_CLUSTER_DNS=true
178+
KUBE_DNS_SERVER_IP="10.0.0.10"
179+
KUBE_DNS_DOMAIN="cluster.local"
180+
KUBE_DNS_REPLICAS=1
181+
```
182+
183+
To know more on DNS service you can look [here](http://issue.k8s.io/6667). Related documents can be found [here](../../cluster/addons/dns/#how-do-i-configure-it)
175184

176185

177186
<!-- BEGIN MUNGE: GENERATED_ANALYTICS -->

hack/local-up-cluster.sh

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ ALLOW_PRIVILEGED=${ALLOW_PRIVILEGED:-""}
2525
ALLOW_SECURITY_CONTEXT=${ALLOW_SECURITY_CONTEXT:-""}
2626
RUNTIME_CONFIG=${RUNTIME_CONFIG:-""}
2727
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
28+
ENABLE_CLUSTER_DNS=${KUBE_ENABLE_CLUSTER_DNS:-true}
29+
DNS_SERVER_IP=${KUBE_DNS_SERVER_IP:-10.0.0.10}
30+
DNS_DOMAIN=${KUBE_DNS_NAME:-"cluster.local"}
31+
DNS_REPLICAS=${KUBE_DNS_REPLICAS:-1}
32+
KUBECTL=${KUBECTL:-cluster/kubectl.sh}
33+
WAIT_FOR_URL_API_SERVER=${WAIT_FOR_URL_API_SERVER:-10}
34+
ENABLE_DAEMON=${ENABLE_DAEMON:-false}
35+
2836
cd "${KUBE_ROOT}"
2937

3038
if [ "$(id -u)" != "0" ]; then
@@ -168,6 +176,14 @@ cleanup_dockerized_kubelet()
168176
cleanup()
169177
{
170178
echo "Cleaning up..."
179+
# delete running images
180+
# if [[ "${ENABLE_CLUSTER_DNS}" = true ]]; then
181+
# Still need to figure why this commands throw an error: Error from server: client: etcd cluster is unavailable or misconfigured
182+
# ${KUBECTL} --namespace=kube-system delete service kube-dns
183+
# And this one hang forever:
184+
# ${KUBECTL} --namespace=kube-system delete rc kube-dns-v10
185+
# fi
186+
171187
# Check if the API server is still running
172188
[[ -n "${APISERVER_PID-}" ]] && APISERVER_PIDS=$(pgrep -P ${APISERVER_PID} ; ps -o pid= -p ${APISERVER_PID})
173189
[[ -n "${APISERVER_PIDS-}" ]] && sudo kill ${APISERVER_PIDS}
@@ -251,7 +267,7 @@ function start_apiserver {
251267

252268
# Wait for kube-apiserver to come up before launching the rest of the components.
253269
echo "Waiting for apiserver to come up"
254-
kube::util::wait_for_url "http://${API_HOST}:${API_PORT}/api/v1/pods" "apiserver: " 1 10 || exit 1
270+
kube::util::wait_for_url "http://${API_HOST}:${API_PORT}/api/v1/pods" "apiserver: " 1 ${WAIT_FOR_URL_API_SERVER} || exit 1
255271
}
256272

257273
function start_controller_manager {
@@ -282,6 +298,13 @@ function start_kubelet {
282298
fi
283299
fi
284300
fi
301+
# Enable dns
302+
if [[ "${ENABLE_CLUSTER_DNS}" = true ]]; then
303+
dns_args="--cluster-dns=${DNS_SERVER_IP} --cluster-domain=${DNS_DOMAIN}"
304+
else
305+
dns_args="--cluster-dns=127.0.0.1"
306+
fi
307+
echo dns_args=$dns_args
285308

286309
sudo -E "${GO_OUT}/kubelet" ${priv_arg}\
287310
--v=${LOG_LEVEL} \
@@ -293,7 +316,7 @@ function start_kubelet {
293316
--address="127.0.0.1" \
294317
--api-servers="${API_HOST}:${API_PORT}" \
295318
--cpu-cfs-quota=${CPU_CFS_QUOTA} \
296-
--cluster-dns="127.0.0.1" \
319+
${dns_args} \
297320
--port="$KUBELET_PORT" >"${KUBELET_LOG}" 2>&1 &
298321
KUBELET_PID=$!
299322
else
@@ -332,6 +355,31 @@ function start_kubeproxy {
332355
SCHEDULER_PID=$!
333356
}
334357

358+
function start_kubedns {
359+
360+
if [[ "${ENABLE_CLUSTER_DNS}" = true ]]; then
361+
echo "Creating kube-system namespace"
362+
sed -e "s/{{ pillar\['dns_replicas'\] }}/${DNS_REPLICAS}/g;s/{{ pillar\['dns_domain'\] }}/${DNS_DOMAIN}/g;" "${KUBE_ROOT}/cluster/addons/dns/skydns-rc.yaml.in" >| skydns-rc.yaml
363+
sed -e "s/{{ pillar\['dns_server'\] }}/${DNS_SERVER_IP}/g" "${KUBE_ROOT}/cluster/addons/dns/skydns-svc.yaml.in" >| skydns-svc.yaml
364+
cat <<EOF >namespace.yaml
365+
apiVersion: v1
366+
kind: Namespace
367+
metadata:
368+
name: kube-system
369+
EOF
370+
${KUBECTL} config set-cluster local --server=http://127.0.0.1:8080 --insecure-skip-tls-verify=true
371+
${KUBECTL} config set-context local --cluster=local
372+
${KUBECTL} config use-context local
373+
374+
${KUBECTL} create -f namespace.yaml
375+
# use kubectl to create skydns rc and service
376+
${KUBECTL} --namespace=kube-system create -f skydns-rc.yaml
377+
${KUBECTL} --namespace=kube-system create -f skydns-svc.yaml
378+
echo "Kube-dns rc and service successfully deployed."
379+
fi
380+
381+
}
382+
335383
function print_success {
336384
cat <<EOF
337385
Local Kubernetes cluster is running. Press Ctrl-C to shut it down.
@@ -362,14 +410,19 @@ fi
362410
echo "Detected host and ready to start services. Doing some housekeeping first..."
363411
echo "Using GO_OUT $GO_OUT"
364412
KUBELET_CIDFILE=/tmp/kubelet.cid
413+
if [[ "${ENABLE_DAEMON}" = false ]]; then
365414
trap cleanup EXIT
415+
fi
366416
echo "Starting services now!"
367417
startETCD
368418
set_service_accounts
369419
start_apiserver
370420
start_controller_manager
371421
start_kubelet
372422
start_kubeproxy
423+
start_kubedns
373424
print_success
374425

375-
while true; do sleep 1; done
426+
if [[ "${ENABLE_DAEMON}" = false ]]; then
427+
while true; do sleep 1; done
428+
fi

0 commit comments

Comments
 (0)