7

ubuntu16 kubernetes 1.9.2 集群

 3 years ago
source link: https://blog.csdn.net/oqqYuan1234567890/article/details/89264165
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

参考官方文档
Using kubeadm to Create a Cluster

记得半年前也捣鼓过一次kubernetes的集群,看别人的文章容易踩坑,今天又踩了!!现在记录一下!!

环境说明:

我是在虚拟机上安装的,宿主机是win,两个ubuntu16.04虚拟机,通过nat方式已经可以上网。
两台虚拟机的ip分别是:
master(c):192.168.217.129
slave(c2):192.168.217.130

Step1: install docker ce

apt-get update
apt-get install -y \
    apt-transport-https \
    ca-certificates \
    curl \
    software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
add-apt-repository \
   "deb https://download.docker.com/linux/$(. /etc/os-release; echo "$ID") \
   $(lsb_release -cs) \
   stable"
apt-get update && apt-get install -y docker-ce=$(apt-cache madison docker-ce | grep 17.03 | head -1 | awk '{print $3}')

Step2: install kubenetes

apt-get update && apt-get install -y apt-transport-https
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb http://apt.kubernetes.io/ kubernetes-xenial main
EOF
apt-get update
apt-get install -y kubelet kubeadm kubectl

Step3: initialize via kubeadm

master ops:

kubeadm reset #optinal, if you want to flush all of the old settings
kubeadm init  --pod-network-cidr=10.244.0.0/16 #wait a few minutes

then, you will see logs:

...
To start using your cluster, you need to run the following as a regular user:

  mkdir -p $HOME/.kube
  sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  sudo chown $(id -u):$(id -g) $HOME/.kube/config

You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
  https://kubernetes.io/docs/concepts/cluster-administration/addons/

You can now join any number of machines by running the following on each node
as root:

  kubeadm join --token 31e3a7.afe7ade149e2c2fc 192.168.217.129:6443 --discovery-token-ca-cert-hash sha256:0b226ad3b722f2f39a357526f056da97d211053f70afea0a71e30c9b2292a1**

tips: $HOME/.kube is your kube config diretory, rm if you have old config

and then run commands

mkdir -p $HOME/.kube
  sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  sudo chown $(id -u):$(id -g) $HOME/.kube/config

Step4: install network addon:

sysctl net.bridge.bridge-nf-call-iptables=1
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/v0.9.1/Documentation/kube-flannel.yml

check pods, a ready sample:

$ kubectl get pods --all-namespaces
NAMESPACE     NAME                        READY     STATUS    RESTARTS   AGE
default       redis-master-hz4vq          1/1       Running   0          38m
kube-system   etcd-c                      1/1       Running   0          43m
kube-system   kube-apiserver-c            1/1       Running   0          43m
kube-system   kube-controller-manager-c   1/1       Running   0          43m
kube-system   kube-dns-6f4fd4bdf-sbjdl    3/3       Running   0          44m
kube-system   kube-flannel-ds-v6kc4       1/1       Running   0          43m
kube-system   kube-flannel-ds-zjnlk       1/1       Running   1          39m
kube-system   kube-proxy-47qjv            1/1       Running   0          39m
kube-system   kube-proxy-s9crw            1/1       Running   0          44m
kube-system   kube-scheduler-c            1/1       Running   0          43m

Step5: repeat operations

in other nodes of your kubenetes cluster, repeat Step1&Step2 to prepare environment.

then, root user:

kubeadm join --token 31e3a7.afe7ade149e2c2fc 192.168.217.129:6443 --discovery-token-ca-cert-hash sha256:0b226ad3b722f2f39a357526f056da97d211053f70afea0a71e30c9b2292a1**

now the cluster is ready, in master,you can see

 $ kubectl get nodes
NAME      STATUS    ROLES     AGE       VERSION
c         Ready     master    45m       v1.9.2
c2        Ready     <none>    40m       v1.9.2


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK