f3a5070a by Adam Heath

Add ability to set the number of agent nodes.

1 parent 5eeee2dd
version: '3.4'
x-extra-hosts: &_x_extra_hosts
extra_hosts:
- "${APP_REGISTRY_NAME}:${APP_REGISTRY_ADDRESS}"
x-root-cert-volume: &_x-root-cert-volume
type: bind
source: ${CONTEXT_DIR}/certs/root.crt
target: /etc/ssl/certs/root.crt
read_only: true
bind:
create_host_path: false
x-kubelet-volume: &_x-kubelet-volume
type: volume
target: /var/lib/kubelet
# volume:
# propagation: shared
x-k3s-agent-env: &_x-k3s-agent-env
K3S_URL: https://k3s-master:6443
K3S_TOKEN_FILE: /var/lib/rancher/k3s/server/node-token
K3S_NODE_NAME: k3s-agent
VIRTUAL_HOST: ${VHOST_STUB},*${VHOST_SUFFIX}${APP_EXTRA_VHOSTS}
VIRTUAL_PROTO: https
VIRTUAL_PORT: "443"
SELF_SIGNED_HOST: ${VHOST_STUB},*${VHOST_SUFFIX}${APP_EXTRA_VHOSTS}
HTTPS_METHOD: noredirect
x-k3s-agent-base: &_x-k3s-agent-base
<<: *_x_extra_hosts
image: "docker.io/rancher/k3s:${K3S_VERSION:-latest}"
tmpfs:
- /run
- /var/run
ulimits:
nproc: 65535
nofile:
soft: 65535
hard: 65535
volumes:
- ${APP_ROOT_DIR?Please set APP_ROOT_DIR}:${APP_ROOT_MOUNT?Please specify where to mount $PWD}
- *_x-root-cert-volume
- *_x-kubelet-volume
- server:/var/lib/rancher/k3s/server:ro
- local-path-provisioner:/opt/local-path-provisioner
privileged: true
restart: always
networks:
default:
nginx:
ports:
- 443
environment:
<<: *_x-k3s-agent-env
services:
k3s-agent-1:
<<: *_x-k3s-agent-base
command: [
"agent",
]
environment:
<<: *_x-k3s-agent-env
K3S_NODE_NAME: agent-1
......@@ -77,44 +77,6 @@ x-k3s-master-base: &_x-k3s-master-base
- *_x-root-cert-volume
- *_x-kubelet-volume
x-k3s-agent-env: &_x-k3s-agent-env
K3S_URL: https://k3s-master:6443
K3S_TOKEN_FILE: /var/lib/rancher/k3s/server/node-token
K3S_NODE_NAME: k3s-agent
VIRTUAL_HOST: ${VHOST_STUB},*${VHOST_SUFFIX}${APP_EXTRA_VHOSTS}
VIRTUAL_PROTO: https
VIRTUAL_PORT: "443"
SELF_SIGNED_HOST: ${VHOST_STUB},*${VHOST_SUFFIX}${APP_EXTRA_VHOSTS}
HTTPS_METHOD: noredirect
x-k3s-agent-base: &_x-k3s-agent-base
<<: *_x_extra_hosts
image: "docker.io/rancher/k3s:${K3S_VERSION:-latest}"
tmpfs:
- /run
- /var/run
ulimits:
nproc: 65535
nofile:
soft: 65535
hard: 65535
volumes:
- ${APP_ROOT_DIR?Please set APP_ROOT_DIR}:${APP_ROOT_MOUNT?Please specify where to mount $PWD}
# - *_x-registries-yaml-volume
- *_x-root-cert-volume
- *_x-kubelet-volume
- server:/var/lib/rancher/k3s/server:ro
- local-path-provisioner:/opt/local-path-provisioner
privileged: true
restart: always
networks:
default:
nginx:
ports:
- 443
environment:
<<: *_x-k3s-agent-env
x-coredns-base: &_x-coredns-base
image: docker.io/coredns/coredns
command: ['-conf', '/etc/coredns/Corefile']
......@@ -212,24 +174,6 @@ services:
k3s-coredns-3:
<<: *_x-coredns-base
k3s-agent-1:
<<: *_x-k3s-agent-base
command: [
"agent",
]
environment:
<<: *_x-k3s-agent-env
K3S_NODE_NAME: agent-1
k3s-agent-2:
<<: *_x-k3s-agent-base
command: [
"agent",
]
environment:
<<: *_x-k3s-agent-env
K3S_NODE_NAME: agent-2
volumes:
etcd1-data:
etcd2-data:
......
......@@ -13,6 +13,7 @@ declare -A features=(
)
declare -a compose_files=(-f "$APISERVER_DIR/docker-compose.yaml")
declare -a k8s_nodes=()
declare -i agent_count=2
while [[ $# -gt 0 ]]; do
arg="$1"
......@@ -34,6 +35,10 @@ while [[ $# -gt 0 ]]; do
compose_files+=(-f "$1")
shift
;;
(--agent-count)
agent_count="$1"
shift
;;
(-n)
k8s_nodes+=("$1")
shift
......@@ -43,6 +48,11 @@ while [[ $# -gt 0 ]]; do
;;
esac
done
_create_agent_compose() {
sed -e "s/agent-1/agent-$1/g" < "$APISERVER_DIR/agent-compose.yaml"
}
set -- "${args[@]}"
for feature in "${!features[@]}"; do
......@@ -62,8 +72,17 @@ declare -a animations=('-' '\' '|' '/')
declare -i animation_index=0
_compose() {
docker-compose --project-directory "$CONTEXT_DIR" "${compose_files[@]}" "$@"
declare -a agent_files
declare -i agent_index=0
for ((agent_index=1; agent_index < $(($agent_count + 1)); agent_index++)); do
agent_files+=("-f <(_create_agent_compose $agent_index)")
done
eval docker-compose --project-directory "$CONTEXT_DIR" "${compose_files[@]}" "${agent_files[@]}" "$@"
}
declare -i agent_index=0
for ((agent_index=1; agent_index < $(($agent_count + 1)); agent_index++)); do
k8s_nodes+=(k3s-agent-$agent_index)
done
etcdctl() {
_compose exec etcd1 etcdctl "$@"
......@@ -192,7 +211,7 @@ case "$cmd" in
_compose up -d k3s-coredns-1 k3s-coredns-2 k3s-coredns-3
"$APISERVER_DIR/scripts/install-cluster-dns.sh" "$CONTEXT_DIR"
_compose up -d k3s-agent-1 k3s-agent-2 "${k8s_nodes[@]}"
_compose up -d "${k8s_nodes[@]}"
_compose up -d k3s-master-2 k3s-master-3
#"$APISERVER_DIR/scripts/wait-for-system-pods.sh" 1
_wait_for_system
......