mirror of
https://github.com/coredns/coredns.git
synced 2025-11-10 05:52:16 -05:00
Moving k8s support scripts out of code folder (#216)
* Adding pod setup to kubernetes startup scripts * Adding template description to k8s README.md * Fix typo. * Moving kubernetes setup scripts out of go folder * Fixing script error * Adding messages to k8s scripts for clarity
This commit is contained in:
@@ -3,7 +3,8 @@
|
||||
`kubernetes` enables reading zone data from a kubernetes cluster. Record names
|
||||
are constructed as "myservice.mynamespace.coredns.local" where:
|
||||
|
||||
* "myservice" is the name of the k8s service (this may include multiple DNS labels, such as "c1.myservice"),
|
||||
* "myservice" is the name of the k8s service (this may include multiple DNS labels,
|
||||
such as "c1.myservice"),
|
||||
* "mynamespace" is the k8s namespace for the service, and
|
||||
* "coredns.local" is the zone configured for `kubernetes`.
|
||||
|
||||
@@ -50,7 +51,7 @@ This is the default kubernetes setup, with everything specified in full:
|
||||
# API documentation: http://kubernetes.io/docs/user-guide/labels/
|
||||
# Example selector below only exposes objects tagged as
|
||||
# "application=nginx" in the staging or qa environments.
|
||||
#labels environment in (staging, qa),application=nginx
|
||||
labels environment in (staging, qa),application=nginx
|
||||
}
|
||||
# Perform DNS response caching for the coredns.local zone
|
||||
# Cache timeout is provided by the integer in seconds
|
||||
@@ -66,46 +67,20 @@ Defaults:
|
||||
is required. The label selector syntax is described in the kubernetes API documentation at:
|
||||
http://kubernetes.io/docs/user-guide/labels/
|
||||
|
||||
### Template syntax
|
||||
Record name templates can be constructed using the symbolic elements:
|
||||
| template symbol | description |
|
||||
| `{service}` | Kubernetes object/service name. |
|
||||
| `{namespace}` | The kubernetes namespace. |
|
||||
| `{type}` | The type of the kubernetes object. Supports values 'svc' and 'pod'. |
|
||||
| `{zone}` | The zone configured for the kubernetes middleware. |
|
||||
|
||||
### Basic Setup
|
||||
|
||||
#### Launch Kubernetes
|
||||
|
||||
Kubernetes is launched using the commands in the following `run_k8s.sh` script:
|
||||
Kubernetes is launched using the commands in the `contrib/kubernetes/testscripts/00_run_k8s.sh` script.
|
||||
|
||||
~~~
|
||||
#!/bin/bash
|
||||
|
||||
# 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="v1.2.4"
|
||||
|
||||
ARCH="amd64"
|
||||
|
||||
export K8S_VERSION
|
||||
export ARCH
|
||||
|
||||
#DNS_ARGUMENTS="--cluster-dns=10.0.0.10 --cluster-domain=cluster.local"
|
||||
DNS_ARGUMENTS=""
|
||||
|
||||
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}:${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
|
||||
~~~
|
||||
|
||||
#### Configure kubectl and test
|
||||
|
||||
@@ -115,31 +90,8 @@ The kubernetes control client can be downloaded from the generic URL:
|
||||
For example, the kubectl client for Linux can be downloaded using the command:
|
||||
`curl -sSL "http://storage.googleapis.com/kubernetes-release/release/v1.2.4/bin/linux/amd64/kubectl"`
|
||||
|
||||
The following `setup_kubectl.sh` script can be stored in the same directory as
|
||||
kubectl to setup
|
||||
kubectl to communicate with kubernetes running on the localhost:
|
||||
|
||||
~~~
|
||||
#!/bin/bash
|
||||
|
||||
BASEDIR=`readlink -e $(dirname ${0})`
|
||||
|
||||
${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
|
||||
|
||||
alias kubctl="${BASEDIR}/kubectl"
|
||||
~~~
|
||||
|
||||
|
||||
Verify that kubectl is working by querying for the kubernetes namespaces:
|
||||
|
||||
~~~
|
||||
$ ./kubectl get namespaces
|
||||
NAME STATUS AGE
|
||||
default Active 8d
|
||||
test Active 7d
|
||||
~~~
|
||||
The `contrib/kubernetes/testscripts/10_setup_kubectl.sh` script can be stored in the same directory as
|
||||
kubectl to setup kubectl to communicate with kubernetes running on the localhost.
|
||||
|
||||
|
||||
#### Launch a kubernetes service and expose the service
|
||||
@@ -158,6 +110,10 @@ $ ./kubectl expose deployment mynginx --namespace=demo --port=80
|
||||
$ ./kubectl get service --namespace=demo
|
||||
~~~
|
||||
|
||||
The script `contrib/kubernetes/testscripts/20_setup_k8s_services.sh` creates a couple of sample namespaces
|
||||
with services running in those namespaces. The automated kubernetes integration tests in
|
||||
`test/kubernetes_test.go` depend on these services and namespaces to exist in kubernetes.
|
||||
|
||||
|
||||
#### Launch CoreDNS
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ func (g *Kubernetes) StartKubeCache() error {
|
||||
return err
|
||||
}
|
||||
if g.LabelSelector == nil {
|
||||
log.Printf("[INFO] Kubernetes middleware configured without a label selector. No label-based filtering will be operformed.")
|
||||
log.Printf("[INFO] Kubernetes middleware configured without a label selector. No label-based filtering will be performed.")
|
||||
} else {
|
||||
var selector labels.Selector
|
||||
selector, err = unversionedapi.LabelSelectorAsSelector(g.LabelSelector)
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 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="v1.2.4"
|
||||
|
||||
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
|
||||
|
||||
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}:${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
|
||||
@@ -1,18 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
PWD=`pwd`
|
||||
BASEDIR=`readlink -e $(dirname ${0})`
|
||||
|
||||
cd ${BASEDIR}
|
||||
if [ ! -e kubectl ]; then
|
||||
curl -O http://storage.googleapis.com/kubernetes-release/release/v1.2.4/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"
|
||||
@@ -1,46 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Running skydns based on instructions at: https://testdatamanagement.wordpress.com/2015/09/01/running-kubernetes-in-docker-with-dns-on-a-single-node/
|
||||
|
||||
PWD=`pwd`
|
||||
BASEDIR=`readlink -e $(dirname ${0})`
|
||||
|
||||
cd ${BASEDIR}
|
||||
|
||||
KUBECTL='./kubectl'
|
||||
|
||||
#RUN_SKYDNS="yes"
|
||||
RUN_SKYDNS="no"
|
||||
|
||||
wait_until_k8s_ready() {
|
||||
# Wait until kubernetes is up and fully responsive
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
if [ "${RUN_SKYDNS}" = "yes" ]; then
|
||||
wait_until_k8s_ready
|
||||
|
||||
echo "Launch kube2sky..."
|
||||
docker run -d --net=host gcr.io/google_containers/kube2sky:1.11 --kube_master_url=http://127.0.0.1:8080 --domain=cluster.local
|
||||
|
||||
echo ""
|
||||
|
||||
echo "Launch SkyDNS..."
|
||||
docker run -d --net=host gcr.io/google_containers/skydns:2015-03-11-001 --machines=http://localhost:4001 --addr=0.0.0.0:53 --domain=cluster.local
|
||||
else
|
||||
true
|
||||
fi
|
||||
|
||||
cd ${PWD}
|
||||
@@ -1,87 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
PWD=`pwd`
|
||||
BASEDIR=`readlink -e $(dirname ${0})`
|
||||
|
||||
cd ${BASEDIR}
|
||||
|
||||
KUBECTL='./kubectl'
|
||||
|
||||
wait_until_k8s_ready() {
|
||||
# Wait until kubernetes is up and fully responsive
|
||||
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() {
|
||||
for n in ${NAMESPACES};
|
||||
do
|
||||
echo "Creating namespace: ${n}"
|
||||
${KUBECTL} get namespaces --no-headers 2>/dev/null | grep -q ${n}
|
||||
if [ "${?}" != "0" ]; then
|
||||
${KUBECTL} create namespace ${n}
|
||||
fi
|
||||
done
|
||||
|
||||
echo "kubernetes namespaces:"
|
||||
${KUBECTL} get namespaces
|
||||
}
|
||||
|
||||
# run_and_expose_service <servicename> <namespace> <image> <port>
|
||||
run_and_expose_service() {
|
||||
|
||||
if [ "${#}" != "4" ]; then
|
||||
return -1
|
||||
fi
|
||||
|
||||
service="${1}"
|
||||
namespace="${2}"
|
||||
image="${3}"
|
||||
port="${4}"
|
||||
|
||||
echo " starting service '${service}' in namespace '${namespace}"
|
||||
|
||||
${KUBECTL} get deployment --namespace=${namespace} --no-headers 2>/dev/null | grep -q ${service}
|
||||
if [ "${?}" != "0" ]; then
|
||||
${KUBECTL} run ${service} --namespace=${namespace} --image=${image}
|
||||
else
|
||||
echo "warn: service '${service}' already running in namespace '${namespace}'"
|
||||
fi
|
||||
|
||||
${KUBECTL} get service --namespace=${namespace} --no-headers 2>/dev/null | grep -q ${service}
|
||||
if [ "${?}" != "0" ]; then
|
||||
${KUBECTL} expose deployment ${service} --namespace=${namespace} --port=${port}
|
||||
else
|
||||
echo "warn: service '${service}' already exposed in namespace '${namespace}'"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
wait_until_k8s_ready
|
||||
|
||||
NAMESPACES="demo poddemo test"
|
||||
create_namespaces
|
||||
|
||||
echo ""
|
||||
echo "Starting services:"
|
||||
|
||||
run_and_expose_service mynginx demo nginx 80
|
||||
run_and_expose_service webserver demo nginx 80
|
||||
run_and_expose_service mynginx test nginx 80
|
||||
run_and_expose_service webserver test nginx 80
|
||||
|
||||
echo ""
|
||||
echo "Services exposed:"
|
||||
${KUBECTL} get services --all-namespaces
|
||||
|
||||
cd ${PWD}
|
||||
@@ -1,35 +0,0 @@
|
||||
## Test scripts to automate kubernetes startup
|
||||
|
||||
Requirements:
|
||||
docker
|
||||
curl
|
||||
|
||||
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
|
||||
testing of CoreDNS with kubernetes.
|
||||
|
||||
To use, run the scripts as:
|
||||
|
||||
~~~
|
||||
$ ./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
|
||||
exposed:
|
||||
|
||||
~~
|
||||
NAMESPACE NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
|
||||
default kubernetes 10.0.0.1 <none> 443/TCP 48m
|
||||
demo mynginx 10.0.0.168 <none> 80/TCP 9m
|
||||
demo webserver 10.0.0.28 <none> 80/TCP 2m
|
||||
test mynginx 10.0.0.4 <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
|
||||
~~~
|
||||
@@ -1,5 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
docker rm -f $(docker ps -a -q)
|
||||
sleep 1
|
||||
docker rm -f $(docker ps -a -q)
|
||||
Reference in New Issue
Block a user