安装条件:
2台虚机,centos 7.2,一台作为控制节点,一台为计算节点,能访问外网。
1. 准备工作,所有节点都执行
(1)关闭selinux
# vim /etc/sysconfig/selinux
# service firewalld stop
# systemctl disable firewalld
# reboot
(2)配置yum源
# vim /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
(3)安装docker
# yum install docker
# systemctl enable docker && systemctl start docker
(4)安装k8s组件
# yum install kubelet kubeadm kubectl
# systemctl enable kubelet && systemctl start kubelet
(5)开启net.bridge.bridge-nf-call功能
# cat <<EOF >  /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
# sysctl --system
(6)下载组件
# CNI_VERSION="v0.6.0"
# mkdir -p /opt/cni/bin
# curl -L  "https://github.com/containernetworking/plugins/releases/download/${CNI_VERSION}/cni-plugins-amd64-${CNI_VERSION}.tgz" | tar -C /opt/cni/bin -xz
# RELEASE="$(curl -sSL https://dl.k8s.io/release/stable.txt)" 
# echo $RELEASE
v1.9.3
# mkdir -p /opt/bin
# cd /opt/bin
# curl -L --remote-name-all https://storage.googleapis.com/kubernetes-release/release/${RELEASE}/bin/linux/amd64/{kubeadm,kubelet,kubectl}
# chmod +x {kubeadm,kubelet,kubectl}
# curl -sSL "https://raw.githubusercontent.com/kubernetes/kubernetes/${RELEASE}/build/debs/kubelet.service" | sed "s:/usr/bin:/opt/bin:g" > /etc/systemd/system/kubelet.service
# mkdir -p /etc/systemd/system/kubelet.service.d
# curl -sSL "https://raw.githubusercontent.com/kubernetes/kubernetes/${RELEASE}/build/debs/10-kubeadm.conf" | sed "s:/usr/bin:/opt/bin:g" > /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
# systemctl enable kubelet && systemctl start kubelet
2. 部署控制节点
(1)配置cgroup driver
# docker info | grep -i cgroup
Cgroup Driver: systemd
# vim /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
Environment="KUBELET_CGROUP_ARGS=--cgroup-driver=systemd"
# systemctl daemon-reload# systemctl restart kubelet
(2)初始化k8s
编辑初始化用的config文件
# vim kubeadm.config 
apiVersion: kubeadm.k8s.io/v1alpha1
api:
  advertiseAddress: "10.132.46.119"
controllerManagerExtraArgs:
  horizontal-pod-autoscaler-use-rest-clients: "true"
  horizontal-pod-autoscaler-sync-period: "10s"
  node-monitor-grace-period: "10s"
apiServerExtraArgs:
  runtime-config: "api/all=true"
  feature-gates: "TaintBasedEvictions=true"
kubernetesVersion: "v1.9.3"
imageRepository: "registry.cn-hangzhou.aliyuncs.com/zhangoic"
network:
  serviceSubnet: 10.96.0.0/12
  podSubnet: 192.168.0.0/16

编辑10-kubeadm.conf文件

# cat  /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
[Service]
Environment="KUBELET_KUBECONFIG_ARGS=--bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf"
Environment="KUBELET_SYSTEM_PODS_ARGS=--pod-manifest-path=/etc/kubernetes/manifests --allow-privileged=true"
Environment="KUBELET_NETWORK_ARGS=--network-plugin=cni --cni-conf-dir=/etc/cni/net.d --cni-bin-dir=/opt/cni/bin"
Environment="KUBELET_DNS_ARGS=--cluster-dns=10.96.0.10 --cluster-domain=cluster.local"
Environment="KUBELET_AUTHZ_ARGS=--authorization-mode=Webhook --client-ca-file=/etc/kubernetes/pki/ca.crt"
# Value should match Docker daemon settings.
# Defaults are "cgroupfs" for Debian/Ubuntu/OpenSUSE and "systemd" for Fedora/CentOS/RHEL
Environment="KUBELET_CGROUP_ARGS=--cgroup-driver=systemd"
Environment="KUBELET_CADVISOR_ARGS=--cadvisor-port=0"
Environment="KUBELET_CERTIFICATE_ARGS=--rotate-certificates=true"
Environment="KUBELET_EXTRA_ARGS=--fail-swap-on=false --pod-infra-container-image=registry.cn-hangzhou.aliyuncs.com/zhangoic/pause-amd64:3.0"
ExecStart=
ExecStart=/opt/bin/kubelet $KUBELET_KUBECONFIG_ARGS $KUBELET_SYSTEM_PODS_ARGS $KUBELET_NETWORK_ARGS $KUBELET_DNS_ARGS $KUBELET_AUTHZ_ARGS $KUBELET_CGROUP_ARGS $KUBELET_CADVISOR_ARGS $KUBELET_CERTIFICATE_ARGS $KUBELET_EXTRA_ARGS

执行init
# kubeadm init --ignore-preflight-errors Swap --config kubeadm.config

最后会返回如下信息,其中kubeadm join是增加计算节点时,在计算节点上执行的命令。

根据返回的提示,继续执行命令:

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

3. 部署计算节点

(1)将master的配置文件拷贝到slave节点

# scp root@ master-ip:/etc/systemd/system/kubelet.service /etc/systemd/system/
# mkdir -p /etc/systemd/system/kubelet.service.d
# scp root@ master-ip:/etc/systemd/system/kubelet.service.d/10-kubeadm.conf /etc/systemd/system/kubelet.service.d/
(2)在slave节点执行命令,将其加入到集群中
# kubeadm join --token f33ea5.29dd1a6c624612aa 10.254.8.13:6443 --discovery-token-ca-cert-hash sha256:f53a8978286aed0bfe1911d7ebea7ca4431dde27f6ff56c35e6a3e37ea216fd5 --ignore-preflight-errors Swap

4. 安装cni组件
k8s提供了多种网络插件,这里使用calico
在控制节点执行命令:
完成以上步骤后,一个k8s集群就安装完毕了,可以用kubectl get nodes和kubectl get pods -n kube-system去查看节点和pod的状态了。

#kubectl apply -f \

https://docs.projectcalico.org/v3.0/getting-started/kubernetes/installation/hosted/kubeadm/1.7/calico.yaml

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐