| 1 | #!/bin/shscip-shell filesystem . . `/bin/sh`. |
| 2 | |
| 3 | . /etc/sysconfig/heat-paramsscip-shell source . . `/etc/sysconfig/heat-params`. |
| 4 | |
| 5 | echoscip-shell system . . echo. "configuring kubernetes (master)" |
| 6 | |
| 7 | # Generate ServiceAccount key if needed |
| 8 | SERVICE_ACCOUNT_KEY="/var/lib/kubernetes/serviceaccount.keyscip-shell filesystem . . `/var/lib/kubernetes/serviceaccount.key`." |
| 9 | if [[ ! -f "${SERVICE_ACCOUNT_KEY}" ]]; then |
| 10 | mkdirscip-shell system . . mkdir. -p "$(dirnamescip-shell system . . dirname. ${SERVICE_ACCOUNT_KEY})" |
| 11 | opensslscip-shell system . . openssl. genrsa -out "${SERVICE_ACCOUNT_KEY}" 2048 2>/dev/nullscip-shell filesystem . . `/dev/null`. |
| 12 | fi |
| 13 | |
| 14 | # Setting correct permissions for Kubernetes files |
| 15 | chownscip-shell system . . chown. -R kube:kube /var/lib/kubernetesscip-shell filesystem . . `/var/lib/kubernetes`. |
| 16 | |
| 17 | KUBE_API_ARGS="--service-account-key-file=$SERVICE_ACCOUNT_KEY --runtime_config=api/all=true" |
| 18 | |
| 19 | if [scip-shell system . . `[`. "$TLS_DISABLED" == "True" ]; then |
| 20 | sedscip-shell system . . sed. -i ' |
| 21 | /^# KUBE_API_PORT=/ s|.*|KUBE_API_PORT="--port=8080 --insecure-port='"$KUBE_API_PORT"'"| |
| 22 | ' /etc/kubernetes/apiserverscip-shell filesystem . . `/etc/kubernetes/apiserver`. |
| 23 | else |
| 24 | # insecure port is used internaly |
| 25 | sedscip-shell system . . sed. -i ' |
| 26 | /^# KUBE_API_PORT=/ s|.*|KUBE_API_PORT="--port=8080 --insecure-port=8080 --secure-port='"$KUBE_API_PORT"'"| |
| 27 | ' /etc/kubernetes/apiserverscip-shell filesystem . . `/etc/kubernetes/apiserver`. |
| 28 | KUBE_API_ARGS="$KUBE_API_ARGS --tls_cert_file=/etc/kubernetes/ssl/server.crt" |
| 29 | KUBE_API_ARGS="$KUBE_API_ARGS --tls_private_key_file=/etc/kubernetes/ssl/server.key" |
| 30 | KUBE_API_ARGS="$KUBE_API_ARGS --client_ca_file=/etc/kubernetes/ssl/ca.crt" |
| 31 | fi |
| 32 | |
| 33 | sedscip-shell system . . sed. -i ' |
| 34 | /^KUBE_ALLOW_PRIV=/ s|=.*|="--allow-privileged='"$KUBE_ALLOW_PRIV"'"| |
| 35 | ' /etc/kubernetes/configscip-shell filesystem . . `/etc/kubernetes/config`. |
| 36 | |
| 37 | sedscip-shell system . . sed. -i ' |
| 38 | /^KUBE_API_ADDRESS=/ s|=.*|="--advertise-address='"$KUBE_NODE_IP"' --insecure-bind-address=0.0.0.0 --bind_address=0.0.0.0"| |
| 39 | /^KUBE_SERVICE_ADDRESSES=/ s|=.*|="--service-cluster-ip-range='"$PORTAL_NETWORK_CIDR"'"| |
| 40 | /^KUBE_API_ARGS=/ s|=.*|="--service-account-key-file='"$SERVICE_ACCOUNT_KEY"' --runtime-config=api\/all=true"| |
| 41 | /^KUBE_ETCD_SERVERS=/ s/=.*/="--etcd-servers=http:\/\/127.0.0.1:2379"/ |
| 42 | /^KUBE_ADMISSION_CONTROL=/ s/=.*/="--admission-control=NamespaceLifecycle,LimitRanger,ServiceAccount,ResourceQuota"/ |
| 43 | ' /etc/kubernetes/apiserverscip-shell filesystem . . `/etc/kubernetes/apiserver`. |
| 44 | |
| 45 | catscip-shell system . . cat. >> /etc/kubernetes/apiserverscip-shell filesystem . . `/etc/kubernetes/apiserver`. <<EOF |
| 46 | #Uncomment the following line to enable Load Balancer feature |
| 47 | #KUBE_API_ARGS="--service-account-key-file='"$SERVICE_ACCOUNT_KEY"' --runtime-config=api\/all=true" --runtime-config=api\/all=true --cloud-config=/etc/sysconfig/kubernetes_openstack_config --cloud-provider=openstack" |
| 48 | EOF |
| 49 | |
| 50 | sedscip-shell system . . sed. -i ' |
| 51 | /^KUBE_CONTROLLER_MANAGER_ARGS=/ s|=.*|="--service_account_private_key_file='"$SERVICE_ACCOUNT_KEY"' --leader-elect=true --cluster-name=kubernetes --cluster-cidr='"$FLANNEL_NETWORK_CIDR"'"| |
| 52 | ' /etc/kubernetes/controller-managerscip-shell filesystem . . `/etc/kubernetes/controller-manager`. |
| 53 | |
| 54 | catscip-shell system . . cat. >> /etc/kubernetes/controller-managerscip-shell filesystem . . `/etc/kubernetes/controller-manager`. <<EOF |
| 55 | #Uncomment the following line to enable Load Balancer feature |
| 56 | #KUBE_CONTROLLER_MANAGER_ARGS="--service_account_private_key_file='"$SERVICE_ACCOUNT_KEY"' --leader-elect=true --cluster-name=kubernetes --cluster-cidr='"$FLANNEL_NETWORK_CIDR"' --cloud-config=/etc/sysconfig/kubernetes_openstack_config --cloud-provider=openstack" |
| 57 | EOF |
| 58 | |
| 59 | # Generate a the configuration for Kubernetes services to talk to OpenStack Neutron |
| 60 | catscip-shell system . . cat. > /etc/sysconfig/kubernetes_openstack_configscip-shell filesystem . . `/etc/sysconfig/kubernetes_openstack_config`. <<EOF |
| 61 | [Global] |
| 62 | auth-url=$AUTH_URL |
| 63 | username=$USERNAME |
| 64 | password=$PASSWORD |
| 65 | tenant-name=$TENANT_NAME |
| 66 | domain-name=$DOMAIN_NAME |
| 67 | [LoadBalancer] |
| 68 | lb-version=v2 |
| 69 | subnet-id=$CLUSTER_SUBNET |
| 70 | create-monitor=yes |
| 71 | monitor-delay=1m |
| 72 | monitor-timeout=30s |
| 73 | monitor-max-retries=3 |
| 74 | EOF |
| 75 | |
| 76 | for service in kube-apiserver kube-scheduler kube-controller-manager; do |
| 77 | echoscip-shell system . . echo. "activating $service service" |
| 78 | systemctl enable $service |
| 79 | |
| 80 | echoscip-shell system . . echo. "starting $service services" |
| 81 | systemctl --no-block start $service |
| 82 | done |