kubeadm is the official community launch of a tool for rapid deployment kubernetes cluster.
This tool can deploy two instructions to complete a kubernetes cluster:
# Create a Master node $ kubeadm the init # Node will join a cluster node to the current $ kubeadm the Join <Master node IP and port>
1. Installation Requirements
Before starting, the machine needs to deploy Kubernetes cluster satisfies the following conditions:
one or more machines, the operating system CentOS7.x-86_x64
hardware configuration: 2GB or more RAM, 2 or more CPU-CPU, 30GB or more hard disk
cluster intercommunication between all the machines in the network
can access the Internet, necessary to pull the mirror
prohibited swap area
2. Learning Objectives
installed on all nodes Docker and kubeadm
deployment Kubernetes Master
deploy plug-ins container network
deployment Kubernetes Node, the node joins the cluster Kubernetes
deploy Dashboard Web pages, visual view Kubernetes resources
3. Prepare the environment
Turn off the firewall: $ systemctl STOP firewalld $ systemctl disable firewalld off SELinux: $ Sed -i ' S / enforcing / Disabled / ' / etc / SELinux / config $ the setenforce 0 Close the swap: $ The swapoff - A temporary $ $ Vim / etc / fstab $ permanently add a host name and IP correspondence relationship (remember to set the hostname): $ CAT / etc / hosts 192.168 . 31.61 k8s- master 192.168 . 31.62 k8s- node1 192.168 . 31.63 k8s- node2 IPv4 traffic will be passed to the bridging chain iptables: $ CAT > << /etc/sysctl.d/k8s.conf the EOF net.bridge.bridge -nf-Call-the ip6tables = . 1 net.bridge.bridge -nf-Call- = iptables 1 EOF $ sysctl --system
4. All nodes installed Docker / kubeadm / kubelet
Kubernetes default CRI (runtime container) is Docker, so install Docker.
4.1 Installation Docker
$ wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo $ yum -y install docker-ce-18.06.1.ce-3.el7 $ systemctl enable docker && systemctl start docker $ docker --version Docker version 18.06.1-ce, build e68fc7a
4.2 Add Ali cloud YUM repositories
$ cat > /etc/yum.repos.d/kubernetes.repo << EOF [kubernetes] name=Kubernetes baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64 enabled=1 gpgcheck=0 repo_gpgcheck=0 gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg EOF
4.3 installation kubeadm, kubelet and kubectl
due to the frequent version updates, deployment version number specified here:
$ Yum install -y kubelet- 1.15 . 0 kubeadm- 1.15 . 0 kubectl- 1.15 . 0 $ systemctl enable omelet
The deployment Kubernetes Master
performed 192.168.31.63 (Master).
The init kubeadm $ \ apiserver-address-advertise = 192.168 . 3161 \ image-repository registryaliyuncscom googlecontainers \ kubernetes-v1 version. 15.0 \ service-cidr = 10.1 . 0.0 and / 16 And \ pod-network-cidr = 10244 . 0.0 / 16
Since the default image address k8s.gcr.io pull the country inaccessible, specify the address of the warehouse Ali cloud mirrored here.
Use kubectl tools:
mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config $ kubectl get nodes
6. Install Network Pod plug (the CNI)
$ kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/a70459be0084506e4ec919aa1c114638878db11b/Documentation/kube-flannel.yml
Ensure access to quay.io this registery.
If the download fails, you can change this image Address: lizhenliang / flannel: v0.11.0-amd64
7. Add Kubernetes Node
executed 192.168.31.65/66(Node).
Add new nodes to the cluster, perform kubeadm join in kubeadm init command output:
$ kubeadm join 192.168.31.61:6443 --token esce21.q6hetwm8si29qxwn \ --discovery-token-ca-cert-hash sha256:00603a05805807501d7181c3d60b478788408cfe6cedefedb1f97569708be9c5
8. Test kubernetes cluster
Creating a pod in Kubernetes cluster, verify proper operation:
$ kubectl create deployment nginx --image=nginx $ kubectl expose deployment nginx --port=80 --type=NodePort $ kubectl get pod,svc
Access address: http: // NodeIP: Port
9. deploy Dashboard
$ kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v1.10.1/src/deploy/recommended/kubernetes-dashboard.yaml
Domestic default image can not be accessed, modified, mirroring address: lizhenliang / kubernetes-dashboard-amd64 : v1.10.1
default Dashboard can only be accessed within the cluster, modify the Service as NodePort type, exposed to the outside:
kind: Service apiVersion: v1 metadata: labels: k8s-app: kubernetes-dashboard name: kubernetes-dashboard namespace: kube-system spec: type: NodePort ports: - port: 443 targetPort: 8443 nodePort: 30001 selector: k8s-app: kubernetes-dashboard
$ kubectl apply -f kubernetes-dashboard.yaml
Access address: http: // NodeIP: 30001
create a service account and bind default cluster-admin administrator roles in a cluster:
$ kubectl create serviceaccount dashboard-admin -n kube-system $ kubectl create clusterrolebinding dashboard-admin --clusterrole=cluster-admin --serviceaccount=kube-system:dashboard-admin $ kubectl describe secrets -n kube-system $(kubectl -n kube-system get secret | awk '/dashboard-admin/{print $1}')
Using the output of token login Dashboard.