2 ##############################################################################
3 # Copyright (c) 2019 Huawei Tech and others.
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
11 KUBE_VERSION=1.16.0-00
12 POD_NETWORK_CIDR=192.168.0.0/16
13 K8S_CNI_VERSION=0.7.5-00
15 #K8s service CIDR range
16 K8s_SVC_CIDR=10.96.0.0/12
18 # Install Kubernetes with Kubeadm
23 sudo apt install -y apt-transport-https curl
24 curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
26 cat <<EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list
27 deb https://apt.kubernetes.io/ kubernetes-xenial main
32 kubernetes-cni=${K8S_CNI_VERSION} kubelet=${KUBE_VERSION} \
33 kubeadm=${KUBE_VERSION} kubectl=${KUBE_VERSION}
35 sudo apt-mark hold kubelet kubeadm kubectl
37 if ! kubectl get nodes; then
38 hostname -I > hostname.tmp
39 MASTER_IP="$(cut -d ' ' -f 1 hostname.tmp)"
41 sudo kubeadm config images pull
43 --apiserver-advertise-address="${MASTER_IP}" \
44 --pod-network-cidr="${POD_NETWORK_CIDR}" \
45 --service-cidr="${K8s_SVC_CIDR}"
47 if [ "$(id -u)" = 0 ]; then
48 KUBECONFIG=/etc/kubernetes/admin.conf
49 echo "export KUBECONFIG=/etc/kubernetes/admin.conf" | \
50 tee -a "${HOME}/.profile"
51 source "${HOME}/.profile"
53 mkdir -p "${HOME}/.kube"
54 sudo cp -i /etc/kubernetes/admin.conf "${HOME}/.kube/config"
55 sudo chown "$(id -u)":"$(id -g)" "${HOME}/.kube/config"
57 #kubectl apply -f "cni/calico/v38/calico.yaml"