Skip to content

Commit 5d4007f

Browse files
author
k8s-merge-robot
committed
Merge pull request kubernetes#21644 from thibserot/dns2
Auto commit by PR queue bot
2 parents 0afbc71 + b6ce3f3 commit 5d4007f

File tree

2 files changed

+63
-4
lines changed

2 files changed

+63
-4
lines changed

docs/devel/running-locally.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,16 @@ One or more of the Kubernetes daemons might've crashed. Tail the logs of each in
175175

176176
#### The pods fail to connect to the services by host names
177177

178-
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)
178+
To start the DNS service, you need to set the following variables:
179179

180+
```sh
181+
KUBE_ENABLE_CLUSTER_DNS=true
182+
KUBE_DNS_SERVER_IP="10.0.0.10"
183+
KUBE_DNS_DOMAIN="cluster.local"
184+
KUBE_DNS_REPLICAS=1
185+
```
180186

187+
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)
181188

182189

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

hack/local-up-cluster.sh

+55-3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ ALLOW_SECURITY_CONTEXT=${ALLOW_SECURITY_CONTEXT:-""}
2626
RUNTIME_CONFIG=${RUNTIME_CONFIG:-""}
2727
NET_PLUGIN=${NET_PLUGIN:-""}
2828
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
29+
ENABLE_CLUSTER_DNS=${KUBE_ENABLE_CLUSTER_DNS:-true}
30+
DNS_SERVER_IP=${KUBE_DNS_SERVER_IP:-10.0.0.10}
31+
DNS_DOMAIN=${KUBE_DNS_NAME:-"cluster.local"}
32+
DNS_REPLICAS=${KUBE_DNS_REPLICAS:-1}
33+
KUBECTL=${KUBECTL:-cluster/kubectl.sh}
34+
WAIT_FOR_URL_API_SERVER=${WAIT_FOR_URL_API_SERVER:-10}
35+
ENABLE_DAEMON=${ENABLE_DAEMON:-false}
36+
2937
cd "${KUBE_ROOT}"
3038

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

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

258274
function start_controller_manager {
@@ -289,6 +305,12 @@ function start_kubelet {
289305
fi
290306
fi
291307
fi
308+
# Enable dns
309+
if [[ "${ENABLE_CLUSTER_DNS}" = true ]]; then
310+
dns_args="--cluster-dns=${DNS_SERVER_IP} --cluster-domain=${DNS_DOMAIN}"
311+
else
312+
dns_args="--cluster-dns=127.0.0.1"
313+
fi
292314

293315
net_plugin_args=""
294316
if [[ -n "${NET_PLUGIN}" ]]; then
@@ -310,7 +332,7 @@ function start_kubelet {
310332
--address="127.0.0.1" \
311333
--api-servers="${API_HOST}:${API_PORT}" \
312334
--cpu-cfs-quota=${CPU_CFS_QUOTA} \
313-
--cluster-dns="127.0.0.1" \
335+
${dns_args} \
314336
${net_plugin_args} \
315337
${kubenet_plugin_args} \
316338
--port="$KUBELET_PORT" >"${KUBELET_LOG}" 2>&1 &
@@ -351,6 +373,31 @@ function start_kubeproxy {
351373
SCHEDULER_PID=$!
352374
}
353375

376+
function start_kubedns {
377+
378+
if [[ "${ENABLE_CLUSTER_DNS}" = true ]]; then
379+
echo "Creating kube-system namespace"
380+
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
381+
sed -e "s/{{ pillar\['dns_server'\] }}/${DNS_SERVER_IP}/g" "${KUBE_ROOT}/cluster/addons/dns/skydns-svc.yaml.in" >| skydns-svc.yaml
382+
cat <<EOF >namespace.yaml
383+
apiVersion: v1
384+
kind: Namespace
385+
metadata:
386+
name: kube-system
387+
EOF
388+
${KUBECTL} config set-cluster local --server=http://127.0.0.1:8080 --insecure-skip-tls-verify=true
389+
${KUBECTL} config set-context local --cluster=local
390+
${KUBECTL} config use-context local
391+
392+
${KUBECTL} create -f namespace.yaml
393+
# use kubectl to create skydns rc and service
394+
${KUBECTL} --namespace=kube-system create -f skydns-rc.yaml
395+
${KUBECTL} --namespace=kube-system create -f skydns-svc.yaml
396+
echo "Kube-dns rc and service successfully deployed."
397+
fi
398+
399+
}
400+
354401
function print_success {
355402
cat <<EOF
356403
Local Kubernetes cluster is running. Press Ctrl-C to shut it down.
@@ -381,14 +428,19 @@ fi
381428
echo "Detected host and ready to start services. Doing some housekeeping first..."
382429
echo "Using GO_OUT $GO_OUT"
383430
KUBELET_CIDFILE=/tmp/kubelet.cid
431+
if [[ "${ENABLE_DAEMON}" = false ]]; then
384432
trap cleanup EXIT
433+
fi
385434
echo "Starting services now!"
386435
startETCD
387436
set_service_accounts
388437
start_apiserver
389438
start_controller_manager
390439
start_kubelet
391440
start_kubeproxy
441+
start_kubedns
392442
print_success
393443

394-
while true; do sleep 1; done
444+
if [[ "${ENABLE_DAEMON}" = false ]]; then
445+
while true; do sleep 1; done
446+
fi

0 commit comments

Comments
 (0)