summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwutianwei <wutianwei1@huawei.com>2018-02-09 09:20:45 +0800
committerwutianwei <wutianwei1@huawei.com>2018-03-20 10:15:34 +0800
commitedf351b82f6df2b5fd91c02be9f22f7ae4dccc55 (patch)
tree9fc6b0902dae3c88a4e75e61ceeb0d339815f5be
parentd0c16a80bac11f52bba7cc6e7152ec47aababe1f (diff)
Access the K8s dashboard and configure the CLI in opnfv host
1. Add the type: NodePort in dashboard service. the default is ClustIP, which cannot access from outside. 2. Print the url ,user, password for user to access dashboard. 3. configure the kubectl CLI in opnfv host. Change-Id: I6cb6e6f7547412139ece0c40a85de67a9edce0ef Signed-off-by: wutianwei <wutianwei1@huawei.com>
-rwxr-xr-xxci/installer/kubespray/deploy.sh32
-rw-r--r--xci/installer/kubespray/files/k8s-cluster.yml7
-rw-r--r--xci/installer/kubespray/playbooks/configure-opnfvhost.yml7
3 files changed, 43 insertions, 3 deletions
diff --git a/xci/installer/kubespray/deploy.sh b/xci/installer/kubespray/deploy.sh
index b68fec90..7695894b 100755
--- a/xci/installer/kubespray/deploy.sh
+++ b/xci/installer/kubespray/deploy.sh
@@ -79,4 +79,36 @@ ssh root@$OPNFV_HOST_IP "set -o pipefail; cd releng-xci/.cache/repos/kubespray;\
-i opnfv_inventory/inventory.cfg cluster.yml -b | tee setup-kubernetes.log"
scp root@$OPNFV_HOST_IP:~/releng-xci/.cache/repos/kubespray/setup-kubernetes.log \
$LOG_PATH/setup-kubernetes.log
+echo
+echo "-----------------------------------------------------------------------"
echo "Info: Kubernetes installation is successfully completed!"
+echo "-----------------------------------------------------------------------"
+
+# Configure the kubernetes authentication in opnfv host.
+ssh root@$OPNFV_HOST_IP "mkdir -p ~/.kube/;\
+ cp -f ~/admin.conf ~/.kube/config; \
+ cp -f ~/kubectl /usr/local/bin"
+
+echo "Login opnfv host ssh root@$OPNFV_HOST_IP
+according to the user-guide to create a service
+https://kubernetes.io/docs/user-guide/walkthrough/k8s201/"
+
+echo
+echo "-----------------------------------------------------------------------"
+echo "Info: Kubernetes login details"
+echo "-----------------------------------------------------------------------"
+
+# Get the dashborad URL
+DASHBOARD_SERVICE=$(ssh root@$OPNFV_HOST_IP "kubectl get service -n kube-system |grep kubernetes-dashboard")
+DASHBOARD_PORT=$(echo ${DASHBOARD_SERVICE} | awk '{print $5}' |awk -F "[:/]" '{print $2}')
+KUBER_SERVER_URL=$(ssh root@$OPNFV_HOST_IP "grep -r server ~/.kube/config")
+echo "Info: Kubernetes Dashboard URL:"
+echo $KUBER_SERVER_URL | awk '{print $2}'| sed -n "s#:[0-9]*\$#:$DASHBOARD_PORT#p"
+
+# Get the dashborad user and password
+MASTER_IP=$(echo ${KUBER_SERVER_URL} | awk '{print $2}' |awk -F "[:/]" '{print $4}')
+USER_CSV=$(ssh root@$MASTER_IP " cat /etc/kubernetes/users/known_users.csv")
+USERNAME=$(echo $USER_CSV |awk -F ',' '{print $2}')
+PASSWORD=$(echo $USER_CSV |awk -F ',' '{print $1}')
+echo "Info: Dashboard username: ${USERNAME}"
+echo "Info: Dashboard password: ${PASSWORD}"
diff --git a/xci/installer/kubespray/files/k8s-cluster.yml b/xci/installer/kubespray/files/k8s-cluster.yml
index aeee573a..20d3091d 100644
--- a/xci/installer/kubespray/files/k8s-cluster.yml
+++ b/xci/installer/kubespray/files/k8s-cluster.yml
@@ -157,7 +157,7 @@ kube_users:
## It is possible to activate / deactivate selected authentication methods (basic auth, static token auth)
#kube_oidc_auth: false
-#kube_basic_auth: false
+kube_basic_auth: true
#kube_token_auth: false
@@ -270,9 +270,10 @@ local_volumes_enabled: false
persistent_volumes_enabled: false
# Make a copy of kubeconfig on the host that runs Ansible in GITDIR/artifacts
-# kubeconfig_localhost: false
+kubeconfig_localhost: true
# Download kubectl onto the host that runs Ansible in GITDIR/artifacts
-# kubectl_localhost: false
+kubectl_localhost: true
+artifacts_dir: "{{ ansible_env.HOME }}"
# dnsmasq
# dnsmasq_upstream_dns_servers:
diff --git a/xci/installer/kubespray/playbooks/configure-opnfvhost.yml b/xci/installer/kubespray/playbooks/configure-opnfvhost.yml
index 4db9ac1a..d6e1d7b8 100644
--- a/xci/installer/kubespray/playbooks/configure-opnfvhost.yml
+++ b/xci/installer/kubespray/playbooks/configure-opnfvhost.yml
@@ -62,6 +62,13 @@
state: present
update_cache: "{{ (ansible_pkg_mgr == 'apt') | ternary('yes', omit) }}"
when: XCI_FLAVOR == 'aio'
+
+ - name: change dashboard server type to NodePort
+ lineinfile:
+ path: "{{ remote_xci_path }}/.cache/repos/kubespray/roles/kubernetes-apps/ansible/templates/dashboard.yml.j2"
+ insertafter: 'targetPort'
+ line: " type: NodePort"
+
- name: pip install ansible
pip:
name: ansible