Commit a2bd9ad3 authored by Yong Tang's avatar Yong Tang Committed by GitHub

Use docker container (instead of binary) for kubectl and travis cleanup (#352)

This fix uses docker container for kubectl. Since Kubernetes docker
image hyperkube has already been downloaded and it consists of
kubectl, there is really no need to download kubectl binary again.

This fix cleans up the Kubernetes related travis setup and removes
unneeded scripts.

This fix also fixes several mismatches of the Kubernetes version used,
so that any changes in version in the future only need to update .travis.yml.
Signed-off-by: default avatarYong Tang <yong.tang.github@outlook.com>
parent 14dc376e
...@@ -12,7 +12,7 @@ go: ...@@ -12,7 +12,7 @@ go:
go_import_path: github.com/miekg/coredns go_import_path: github.com/miekg/coredns
env: env:
- ETCD_VERSION=2.3.1 K8S_VERSION=1.3.7 - ETCD_VERSION=2.3.1 K8S_VERSION=1.3.7 KUBECTL="docker exec hyperkube /hyperkube kubectl" DNS_ARGUMENTS=""
# In the Travis VM-based build environment, IPv6 networking is not # In the Travis VM-based build environment, IPv6 networking is not
# enabled by default. The sysctl operations below enable IPv6. # enabled by default. The sysctl operations below enable IPv6.
...@@ -30,11 +30,19 @@ before_install: ...@@ -30,11 +30,19 @@ before_install:
before_script: before_script:
- docker run -d --net=host --name=etcd quay.io/coreos/etcd:v$ETCD_VERSION - docker run -d --net=host --name=etcd quay.io/coreos/etcd:v$ETCD_VERSION
- ./.travis/kubernetes/start_k8s_with_services.sh - docker run -d --volume=/:/rootfs:ro --volume=/sys:/sys:ro --volume=/var/lib/docker/:/var/lib/docker:rw --volume=/var/lib/kubelet/:/var/lib/kubelet:rw --volume=/var/run:/var/run:rw --net=host --pid=host --privileged --name=hyperkube gcr.io/google_containers/hyperkube-amd64:v$K8S_VERSION /hyperkube kubelet --containerized --hostname-override=127.0.0.1 --api-servers=http://localhost:8080 --config=/etc/kubernetes/manifests $DNS_ARGUMENTS --allow-privileged --v=2
# Wait until kubectl is ready
- for i in {1..10}; do $KUBECTL version && break || sleep 5; done
- $KUBECTL version
- $KUBECTL config set-cluster test-doc --server=http://localhost:8080
- $KUBECTL config set-context test-doc --cluster=test-doc
- $KUBECTL config use-context test-doc
# Wait until k8s is ready
- for i in {1..30}; do $KUBECTL get nodes && break || sleep 5; done
- .travis/kubernetes/setup_k8s_services.sh
- docker ps -a
script: script:
- docker ps -a
- ./.travis/kubernetes/kubectl version
- make coverage - make coverage
after_success: after_success:
......
#!/bin/bash
set -e
# Based on instructions at: http://kubernetes.io/docs/getting-started-guides/docker/
#K8S_VERSION=$(curl -sS https://storage.googleapis.com/kubernetes-release/release/latest.txt)
K8S_VERSION=${K8S_VERSION:-"1.3.7"}
ARCH="amd64"
export K8S_VERSION
export ARCH
#RUN_SKYDNS="yes"
RUN_SKYDNS="no"
if [ "${RUN_SKYDNS}" = "yes" ]; then
DNS_ARGUMENTS="--cluster-dns=10.0.0.10 --cluster-domain=cluster.local"
else
DNS_ARGUMENTS=""
fi
echo "Starting kubernetes..."
docker run -d \
--volume=/:/rootfs:ro \
--volume=/sys:/sys:ro \
--volume=/var/lib/docker/:/var/lib/docker:rw \
--volume=/var/lib/kubelet/:/var/lib/kubelet:rw \
--volume=/var/run:/var/run:rw \
--net=host \
--pid=host \
--privileged \
gcr.io/google_containers/hyperkube-${ARCH}:v${K8S_VERSION} \
/hyperkube kubelet \
--containerized \
--hostname-override=127.0.0.1 \
--api-servers=http://localhost:8080 \
--config=/etc/kubernetes/manifests \
${DNS_ARGUMENTS} \
--allow-privileged --v=2
#!/bin/bash
set -e
PWD=`pwd`
BASEDIR=`readlink -e $(dirname ${0})`
cd ${BASEDIR}
echo "Setting up kubectl..."
if [ ! -e kubectl ]; then
curl -O http://storage.googleapis.com/kubernetes-release/release/v1.3.7/bin/linux/amd64/kubectl
chmod u+x kubectl
fi
${BASEDIR}/kubectl config set-cluster test-doc --server=http://localhost:8080
${BASEDIR}/kubectl config set-context test-doc --cluster=test-doc
${BASEDIR}/kubectl config use-context test-doc
cd ${PWD}
alias kubctl="${BASEDIR}/kubectl"
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
Requirements: Requirements:
docker docker
curl
The scripts in this directory startup kubernetes with docker as the container runtime. The scripts in this directory startup kubernetes with docker as the container runtime.
After starting kubernetes, a couple of kubernetes services are started to allow automatic After starting kubernetes, a couple of kubernetes services are started to allow automatic
...@@ -10,16 +9,10 @@ testing of CoreDNS with kubernetes. The kubernetes integration tests in `test/ku ...@@ -10,16 +9,10 @@ testing of CoreDNS with kubernetes. The kubernetes integration tests in `test/ku
automate the launch of kubernetes and the creation of the expected sample services. automate the launch of kubernetes and the creation of the expected sample services.
To start up kubernetes and launch some sample services, To start up kubernetes and launch some sample services,
run the script `start_k8s_with_services.sh`. run the script `setup_k8s_services.sh`.
~~~ ~~~
$ ./start_k8s_with_services.sh $ ./setup_k8s_services.sh
~~~
Alternatively, the individual scripts may be run independently as needed:
~~~
$ ./00_run_k8s.sh && ./10_setup_kubectl.sh && ./20_setup_k8s_services.sh
~~~ ~~~
After running the above scripts, kubernetes will be running on the localhost with the following services After running the above scripts, kubernetes will be running on the localhost with the following services
...@@ -33,11 +26,3 @@ demo webserver 10.0.0.28 <none> 80/TCP 2m ...@@ -33,11 +26,3 @@ demo webserver 10.0.0.28 <none> 80/TCP 2m
test mynginx 10.0.0.4 <none> 80/TCP 2m test mynginx 10.0.0.4 <none> 80/TCP 2m
test webserver 10.0.0.39 <none> 80/TCP 2m test webserver 10.0.0.39 <none> 80/TCP 2m
~~ ~~
Kubernetes and all running containers can be uncerimoniously stopped by
running the `kill_all_containers.sh` script.
~~~
$ ./kill_all_containers.sh
~~~
#!/bin/bash
docker rm -f $(docker ps -a -q)
sleep 1
docker rm -f $(docker ps -a -q)
...@@ -4,19 +4,25 @@ ...@@ -4,19 +4,25 @@
PWD=`pwd` PWD=`pwd`
BASEDIR=`readlink -e $(dirname ${0})` BASEDIR=`readlink -e $(dirname ${0})`
cd ${BASEDIR} cd ${BASEDIR}
KUBECTL='./kubectl' KUBECTL='docker exec hyperkube /hyperkube kubectl'
#RUN_SKYDNS="yes" #RUN_SKYDNS="yes"
RUN_SKYDNS="no" RUN_SKYDNS="no"
# DNS_ARGUMENTS needs to be passed when Kubernetes is setup.
if [ "${RUN_SKYDNS}" = "yes" ]; then
DNS_ARGUMENTS="--cluster-dns=10.0.0.10 --cluster-domain=cluster.local"
else
DNS_ARGUMENTS=""
fi
wait_until_k8s_ready() { wait_until_k8s_ready() {
# Wait until kubernetes is up and fully responsive # Wait until kubernetes is up and fully responsive
while : while :
do do
${KUBECTL} get nodes 2>/dev/null | grep -q '127.0.0.1' ${KUBECTL} get nodes 2>/dev/null | grep -q '127.0.0.1'
if [ "${?}" = "0" ]; then if [ "${?}" = "0" ]; then
break break
else else
......
#!/bin/bash #!/bin/bash
PWD=`pwd` set -x
BASEDIR=`readlink -e $(dirname ${0})`
cd ${BASEDIR}
KUBECTL='./kubectl' KUBECTL='docker exec hyperkube /hyperkube kubectl'
wait_until_k8s_ready() { PWD=`pwd`
# Wait until kubernetes is up and fully responsive cd `readlink -e $(dirname ${0})`
while :
do
${KUBECTL} get nodes 2>/dev/null | grep -q '127.0.0.1'
if [ "${?}" = "0" ]; then
break
else
echo "sleeping for 5 seconds (waiting for kubernetes to start)"
sleep 5
fi
done
echo "kubernetes nodes:"
${KUBECTL} get nodes
}
create_namespaces() { create_namespaces() {
for n in ${NAMESPACES}; for n in ${NAMESPACES};
do do
echo "Creating namespace: ${n}" echo "Creating namespace: ${n}"
${KUBECTL} get namespaces --no-headers 2>/dev/null | grep -q ${n} ${KUBECTL} get namespaces --no-headers 2>/dev/null | grep -q ${n}
if [ "${?}" != "0" ]; then if [ "${?}" != "0" ]; then
${KUBECTL} create namespace ${n} ${KUBECTL} create namespace ${n}
fi fi
done done
echo "kubernetes namespaces:" echo "kubernetes namespaces:"
...@@ -39,58 +23,55 @@ create_namespaces() { ...@@ -39,58 +23,55 @@ create_namespaces() {
# run_and_expose_service <servicename> <namespace> <image> <port> # run_and_expose_service <servicename> <namespace> <image> <port>
run_and_expose_service() { run_and_expose_service() {
if [ "${#}" != "4" ]; then if [ "${#}" != "4" ]; then
return -1 return -1
fi fi
service="${1}" service="${1}"
namespace="${2}" namespace="${2}"
image="${3}" image="${3}"
port="${4}" port="${4}"
echo " starting service '${service}' in namespace '${namespace}'" echo " starting service '${service}' in namespace '${namespace}'"
${KUBECTL} get deployment --namespace=${namespace} --no-headers 2>/dev/null | grep -q ${service} ${KUBECTL} get deployment --namespace=${namespace} --no-headers 2>/dev/null | grep -q ${service}
if [ "${?}" != "0" ]; then if [ "${?}" != "0" ]; then
${KUBECTL} run ${service} --namespace=${namespace} --image=${image} ${KUBECTL} run ${service} --namespace=${namespace} --image=${image}
else else
echo "warn: service '${service}' already running in namespace '${namespace}'" echo "warn: service '${service}' already running in namespace '${namespace}'"
fi fi
${KUBECTL} get service --namespace=${namespace} --no-headers 2>/dev/null | grep -q ${service} ${KUBECTL} get service --namespace=${namespace} --no-headers 2>/dev/null | grep -q ${service}
if [ "${?}" != "0" ]; then if [ "${?}" != "0" ]; then
${KUBECTL} expose deployment ${service} --namespace=${namespace} --port=${port} ${KUBECTL} expose deployment ${service} --namespace=${namespace} --port=${port}
else else
echo "warn: service '${service}' already exposed in namespace '${namespace}'" echo "warn: service '${service}' already exposed in namespace '${namespace}'"
fi fi
} }
#run_and_expose_rc nginx-controller nginx-rc.yml poddemo 80 #run_and_expose_rc nginx-controller nginx-rc.yml poddemo 80
run_and_expose_rc() { run_and_expose_rc() {
if [ "${#}" != "4" ]; then if [ "${#}" != "4" ]; then
return -1 return -1
fi fi
rc_name="${1}" rc_name="${1}"
rc_file="${2}" rc_file="${2}"
namespace="${3}" namespace="${3}"
port="${4}" port="${4}"
echo " starting replication controller '${rc_name}' from '${rc_file}' in namespace '${namespace}'" echo " starting replication controller '${rc_name}' from '${rc_file}' in namespace '${namespace}'"
${KUBECTL} get rc --namespace=${namespace} --no-headers 2>/dev/null | grep -q ${rc_name} ${KUBECTL} get rc --namespace=${namespace} --no-headers 2>/dev/null | grep -q ${rc_name}
if [ "${?}" != "0" ]; then if [ "${?}" != "0" ]; then
${KUBECTL} expose -f ${rc_file} --namespace=${namespace} --port=${port} ${KUBECTL} expose -f ${rc_file} --namespace=${namespace} --port=${port}
else else
echo "warn: rc '${rc_name}' already running in namespace '${namespace}'" echo "warn: rc '${rc_name}' already running in namespace '${namespace}'"
fi fi
} }
echo "Starting sample kubernetes services..." echo "Starting sample kubernetes services..."
wait_until_k8s_ready
NAMESPACES="demo poddemo test" NAMESPACES="demo poddemo test"
create_namespaces create_namespaces
...@@ -115,5 +96,4 @@ echo "" ...@@ -115,5 +96,4 @@ echo ""
echo "ReplicationControllers exposed:" echo "ReplicationControllers exposed:"
${KUBECTL} get rc --all-namespaces ${KUBECTL} get rc --all-namespaces
cd ${PWD} cd ${PWD}
#!/bin/bash
PWD=`pwd`
BASEDIR=`readlink -e $(dirname ${0})`
cd ${BASEDIR}
./00_run_k8s.sh && \
./10_setup_kubectl.sh && \
./20_setup_k8s_services.sh
cd ${PWD}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment