3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
18 K8S_CLOUD_NAME
="k8s-cloud"
19 KUBECTL
="microk8s.kubectl"
20 IMAGES_OVERLAY_FILE
=~
/.osm
/images-overlay.yaml
21 function check_arguments
(){
22 while [ $# -gt 0 ] ; do
24 --bundle) BUNDLE
="$2" ;;
25 --k8s) KUBECFG
="$2" ;;
26 --vca) CONTROLLER
="$2" ;;
27 --lxd) LXD_CLOUD
="$2" ;;
28 --lxd-cred) LXD_CREDENTIALS
="$2" ;;
29 --microstack) MICROSTACK
=y
;;
30 --ha) BUNDLE
="cs:osm-ha-39" ;;
36 # echo $BUNDLE $KUBECONFIG $LXDENDPOINT
39 function install_snaps
(){
40 if [ ! -v KUBECFG
]; then
41 sudo snap
install microk8s
--classic
42 sudo usermod
-a -G microk8s
`whoami`
44 sudo chown
-f -R `whoami` ~
/.kube
46 microk8s status
--wait-ready
49 sudo snap
install kubectl
--classic
50 export KUBECONFIG
=${KUBECFG}
53 sudo snap
install juju
--classic --channel=2.8/stable
56 function bootstrap_k8s_lxd
(){
57 [ -v CONTROLLER
] && ADD_K8S_OPTS
="--controller ${CONTROLLER}" && CONTROLLER_NAME
=$CONTROLLER
58 [ ! -v CONTROLLER
] && ADD_K8S_OPTS
="--client" && BOOTSTRAP_NEEDED
="yes" && CONTROLLER_NAME
="osm-vca"
60 if [ -v BOOTSTRAP_NEEDED
]; then
61 CONTROLLER_PRESENT
=$
(juju controllers
2>/dev
/null|
grep ${CONTROLLER_NAME} |
wc -l)
62 if [ $CONTROLLER_PRESENT -ge 1 ]; then
64 Threre is already a VCA present with the installer reserved name of "${CONTROLLER_NAME}".
65 You may either explicitly use this VCA with the "--vca ${CONTROLLER_NAME}" option, or remove it
68 juju destroy-controller --release-storage --destroy-all-models -y ${CONTROLLER_NAME}
70 Please retry the installation once this conflict has been resolved.
75 CONTROLLER_PRESENT
=$
(juju controllers
2>/dev
/null|
grep ${CONTROLLER_NAME} |
wc -l)
76 if [ $CONTROLLER_PRESENT -le 0 ]; then
78 Threre is no VCA present with the name "${CONTROLLER_NAME}". Please specify a VCA
79 that exists, or remove the --vca ${CONTROLLER_NAME} option.
81 Please retry the installation with one of the solutions applied.
87 if [ -v KUBECFG
]; then
88 cat $KUBECFG | juju add-k8s
$K8S_CLOUD_NAME $ADD_K8S_OPTS
89 [ -v BOOTSTRAP_NEEDED
] && juju bootstrap
$K8S_CLOUD_NAME $CONTROLLER_NAME \
90 --config controller-service-type
=loadbalancer \
93 sg
${KUBEGRP} -c "echo ${DEFAULT_IP}-${DEFAULT_IP} | microk8s.
enable metallb
"
94 sg ${KUBEGRP} -c "microk8s.
enable ingress
"
95 sg ${KUBEGRP} -c "microk8s.
enable storage dns
"
97 start_time="$
(date -u +%s
)"
101 if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
102 echo "Microk8s storage failed to
enable"
103 sg ${KUBEGRP} -c "microk8s.status
"
106 storage_status=`sg ${KUBEGRP} -c "microk8s.status
-a storage
"`
107 if [[ $storage_status == "enabled
" ]]; then
113 [ ! -v BOOTSTRAP_NEEDED ] && sg ${KUBEGRP} -c "microk8s.config
" | juju add-k8s $K8S_CLOUD_NAME $ADD_K8S_OPTS
114 [ -v BOOTSTRAP_NEEDED ] && sg ${KUBEGRP} -c \
115 "juju bootstrap microk8s
$CONTROLLER_NAME --config controller-service-type
=loadbalancer
--agent-version=2.8.1" \
116 && K8S_CLOUD_NAME=microk8s
119 if [ -v LXD_CLOUD ]; then
120 if [ ! -v LXD_CREDENTIALS ]; then
121 echo "The installer needs the LXD server certificate
if the LXD is external
"
125 LXDENDPOINT=$DEFAULT_IP
126 LXD_CLOUD=~/.osm/lxd-cloud.yaml
127 LXD_CREDENTIALS=~/.osm/lxd-credentials.yaml
128 # Apply sysctl production values for optimal performance
129 sudo cp /usr/share/osm-devops/installers/60-lxd-production.conf /etc/sysctl.d/60-lxd-production.conf
132 sudo apt-get remove --purge -y liblxc1 lxc-common lxcfs lxd lxd-client
133 sudo snap install lxd
134 sudo apt-get install zfsutils-linux -y
136 sudo usermod -a -G lxd `whoami`
137 cat /usr/share/osm-devops/installers/lxd-preseed.conf | sed 's/^config: {}/config:\n core.https_address: '$LXDENDPOINT':8443/' | sg lxd -c "lxd init
--preseed"
138 sg lxd -c "lxd waitready
"
139 DEFAULT_MTU=$(ip addr show $DEFAULT_IF | perl -ne 'if (/mtu\s(\d+)/) {print $1;}')
140 sg lxd -c "lxc profile device
set default eth0 mtu
$DEFAULT_MTU"
141 sg lxd -c "lxc network
set lxdbr0 bridge.mtu
$DEFAULT_MTU"
143 cat << EOF > $LXD_CLOUD
147 auth-types: [certificate]
148 endpoint: "https
://$LXDENDPOINT:8443"
150 ssl-hostname-verification: false
152 openssl req -nodes -new -x509 -keyout ~/.osm/client.key -out ~/.osm/client.crt -days 365 -subj "/C
=FR
/ST
=Nice
/L
=Nice
/O
=ETSI
/OU
=OSM
/CN
=osm.etsi.org
"
153 local server_cert=`cat /var/snap/lxd/common/lxd/server.crt | sed 's/^/ /'`
154 local client_cert=`cat ~/.osm/client.crt | sed 's/^/ /'`
155 local client_key=`cat ~/.osm/client.key | sed 's/^/ /'`
157 cat << EOF > $LXD_CREDENTIALS
161 auth-type: certificate
169 lxc config trust add local: ~/.osm/client.crt
172 juju add-cloud -c $CONTROLLER_NAME lxd-cloud $LXD_CLOUD --force
173 juju add-credential -c $CONTROLLER_NAME lxd-cloud -f $LXD_CREDENTIALS
174 sg lxd -c "lxd waitready
"
175 juju controller-config features=[k8s-operators]
178 function wait_for_port(){
182 start_time="$
(date -u +%s
)"
186 if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
187 echo "Failed to expose external
${SERVICE} interface port
"
191 if [ $(sg ${KUBEGRP} -c "${KUBECTL} get ingresses.networking -n osm -o json | jq -r '.items[$INDEX].metadata.name'") == ${SERVICE} ] ; then
198 function deploy_charmed_osm(){
200 echo "Creating OSM model
"
201 if [ -v KUBECFG ]; then
202 juju add-model osm $K8S_CLOUD_NAME
204 sg ${KUBEGRP} -c "juju add-model osm
$K8S_CLOUD_NAME"
206 echo "Deploying OSM with charms
"
208 [ -v TAG ] && generate_images_overlay && images_overlay="--overlay $IMAGES_OVERLAY_FILE"
209 if [ -v BUNDLE ]; then
210 juju deploy $BUNDLE --overlay ~/.osm/vca-overlay.yaml $images_overlay
212 juju deploy cs:osm-49 --overlay ~/.osm/vca-overlay.yaml $images_overlay
215 echo "Waiting
for deployment to finish...
"
217 echo "OSM with charms deployed
"
218 if [ ! -v KUBECFG ]; then
219 API_SERVER=${DEFAULT_IP}
221 API_SERVER=$(kubectl config view --minify | grep server | cut -f 2- -d ":" | tr -d " ")
222 proto="$
(echo $API_SERVER |
grep :// |
sed -e's,^\(.*://\).*,\1,g')"
223 url="$
(echo ${API_SERVER/$proto/})"
224 user="$
(echo $url |
grep @ | cut
-d@
-f1)"
225 hostport="$
(echo ${url/$user@/} | cut
-d/ -f1)"
226 API_SERVER="$
(echo $hostport |
sed -e 's,:.*,,g')"
229 # Expose OSM services
231 juju config grafana-k8s juju-external-hostname=grafana.${API_SERVER}.xip.io
232 juju expose grafana-k8s
233 wait_for_port grafana-k8s 0
236 juju config nbi-k8s juju-external-hostname=nbi.${API_SERVER}.xip.io
238 wait_for_port nbi-k8s 1
241 juju config ng-ui juju-external-hostname=ui.${API_SERVER}.xip.io
243 wait_for_port ng-ui 2
246 juju config prometheus-k8s juju-external-hostname=prometheus.${API_SERVER}.xip.io
247 juju expose prometheus-k8s
248 wait_for_port prometheus-k8s 3
251 juju config ui-k8s juju-external-hostname=osm.${API_SERVER}.xip.io
253 wait_for_port ui-k8s 4
256 sg ${KUBEGRP} -c "${KUBECTL} annotate ingresses.networking nginx.ingress.kubernetes.io
/backend-protocol
=HTTPS
-n osm
-l juju-app
=nbi-k8s
"
257 sg ${KUBEGRP} -c "${KUBECTL} annotate ingresses.networking nginx.ingress.kubernetes.io
/proxy-body-size
=0 -n osm
-l juju-app
=nbi-k8s
"
258 sg ${KUBEGRP} -c "${KUBECTL} annotate ingresses.networking nginx.ingress.kubernetes.io
/proxy-body-size
=0 -n osm
-l juju-app
=ng-ui
"
259 sg ${KUBEGRP} -c "${KUBECTL} annotate ingresses.networking nginx.ingress.kubernetes.io
/proxy-body-size
=0 -n osm
-l juju-app
=ui-k8s
"
262 function check_osm_deployed() {
264 start_time="$
(date -u +%s
)"
265 total_service_count=15
269 service_count=$(juju status | grep kubernetes | grep active | wc -l)
270 echo "$service_count / $total_service_count services active
"
271 if [ $service_count -eq $total_service_count ]; then
274 if [ $service_count -ne $previous_count ]; then
275 previous_count=$service_count
276 start_time="$
(date -u +%s
)"
279 if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
280 echo "Timed out waiting
for OSM services to become ready
"
287 function create_overlay() {
289 sudo apt install python3-pip -y
290 python3 -m pip install yq
291 PATH=$PATH:$HOME/.local/bin # make yq command available
292 local HOME=/home/$USER
293 local vca_user=$(cat $HOME/.local/share/juju/accounts.yaml | yq --arg CONTROLLER_NAME $CONTROLLER_NAME '.controllers[$CONTROLLER_NAME].user')
294 local vca_password=$(cat $HOME/.local/share/juju/accounts.yaml | yq --arg CONTROLLER_NAME $CONTROLLER_NAME '.controllers[$CONTROLLER_NAME].password')
295 local vca_host=$(cat $HOME/.local/share/juju/controllers.yaml | yq --arg CONTROLLER_NAME $CONTROLLER_NAME '.controllers[$CONTROLLER_NAME]["api-endpoints
"][0]' --raw-output | cut -d ":" -f 1)
296 local vca_port=$(cat $HOME/.local/share/juju/controllers.yaml | yq --arg CONTROLLER_NAME $CONTROLLER_NAME '.controllers[$CONTROLLER_NAME]["api-endpoints
"][0]' --raw-output | cut -d ":" -f 2)
297 local vca_pubkey=\"$(cat $HOME/.local/share/juju/ssh/juju_id_rsa.pub)\"
298 local vca_cloud="lxd-cloud
"
299 # Get the VCA Certificate
300 local vca_cacert=$(cat $HOME/.local/share/juju/controllers.yaml | yq --arg CONTROLLER_NAME $CONTROLLER_NAME '.controllers[$CONTROLLER_NAME]["ca-cert
"]' --raw-output | base64 | tr -d \\n)
302 # Calculate the default route of this machine
303 local DEFAULT_IF=`ip route list match 0.0.0.0 | awk '{print $5}'`
305 # Generate a new overlay.yaml, overriding any existing one
306 cat << EOF > /tmp/vca-overlay.yaml
311 vca_password: $vca_password
314 vca_pubkey: $vca_pubkey
315 vca_cacert: $vca_cacert
316 vca_cloud: $vca_cloud
317 vca_k8s_cloud: $K8S_CLOUD_NAME
321 vca_password: $vca_password
323 vca_cacert: $vca_cacert
325 mv /tmp/vca-overlay.yaml ~/.osm/
326 OSM_VCA_HOST=$vca_host
329 function generate_images_overlay(){
330 cat << EOF > /tmp/images-overlay.yaml
334 image: opensourcemano/lcm:$TAG
337 image: opensourcemano/mon:$TAG
340 image: opensourcemano/ro:$TAG
343 image: opensourcemano/nbi:$TAG
346 image: opensourcemano/pol:$TAG
349 image: opensourcemano/light-ui:$TAG
352 image: opensourcemano/pla:$TAG
355 image: opensourcemano/ng-ui:$TAG
358 mv /tmp/images-overlay.yaml $IMAGES_OVERLAY_FILE
361 function install_osmclient() {
362 sudo snap install osmclient
363 sudo snap alias osmclient.osm osm
367 function install_microstack() {
368 sudo snap install microstack --classic --beta
369 sudo microstack.init --auto
370 wget https://cloud-images.ubuntu.com/releases/16.04/release/ubuntu-16.04-server-cloudimg-amd64-disk1.img -P ~/.osm/
371 microstack.openstack image create \
373 --disk-format qcow2 \
374 --container-format bare \
375 --file ~/.osm/ubuntu-16.04-server-cloudimg-amd64-disk1.img \
377 ssh-keygen -t rsa -N "" -f ~/.ssh/microstack
378 microstack.openstack keypair create --public-key ~/.ssh/microstack.pub microstack
379 export OSM_HOSTNAME=`juju status --format json | jq -rc '.applications."nbi-k8s
".address'`
380 osm vim-create --name microstack-site \
382 --password keystone \
383 --auth_url http://10.20.20.1:5000/v3 \
385 --account_type openstack \
386 --config='{security_groups: default,
389 user_domain_name: default,
390 region_name: microstack,
392 availability_zone: nova,
396 DEFAULT_IF=`ip route list match 0.0.0.0 | awk '{print $5}'`
397 DEFAULT_IP=`ip -o -4 a |grep ${DEFAULT_IF}|awk '{split($4,a,"/"); print a[1]}'`
405 if [ -v MICROSTACK ]; then
409 OSM_HOSTNAME=$(juju config nbi-k8s juju-external-hostname):443
411 echo "Your installation is now complete
, follow these steps
for configuring the osmclient
:"
413 echo "1. Create the OSM_HOSTNAME environment variable with the NBI IP
"
415 echo "export OSM_HOSTNAME
=$OSM_HOSTNAME"
417 echo "2. Add the previous
command to your .bashrc
for other Shell sessions
"
419 echo "echo \"export OSM_HOSTNAME
=$OSM_HOSTNAME\" >> ~
/.bashrc
"