Kubernetes_K8S集群快速部署文档(真的真的只要CV即可~)

  • 最低需求:要1台master宿主机 2台node节点机
  • 配置为:2C 4G 60GB

1.修改节点名称(ip和名称匹配很重要 一开始不要出错喔~)

cat >> /etc/hosts <

2…关闭自动挂载

 swapoff -a
sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab

3.关闭selinux以及防火墙

sed -ri 's#(SELINUX=).*#\1disabled#' /etc/selinux/config
setenforce 0
systemctl disable firewalld && systemctl stop firewalld

4.开启内核对流量的转发

cat < /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward=1
vm.max_map_count=262144
EOF
modprobe br_netfilter
sysctl -p /etc/sysctl.d/k8s.conf

5.配置docker-ce.repo镜像

curl -o /etc/yum.repos.d/Centos-7.repo http://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/docker-ce.repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

6.配置kubernetes.repo 镜像

cat < /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
 http://mirrors.aliyun.com/kubernetes/yum/doc/rpm package-key.gpg
EOF

8.清除缓存并且重启配置

yum clean all && yum makecache

9.安装docker

yum install docker-ce -y

10.创建docker文件夹

mkdir -p /etc/docker

11.配置docker文件

vi /etc/docker/daemon.json
{
 "registry-mirrors": ["http://f1361db2.m.daocloud.io"] 
}

12.设置开机自动启动以及启动docker

systemctl enable docker && systemctl start docker

13.查看docker版本以及镜像

docker ps 
docker version

14.#all所有节点(主子节点)都需要安装kubelet组件#

yum install -y kubelet-1.16.2 kubeadm-1.16.2 kubectl-1.16.2 --disableexcludes=kubernetes
kubeadm version

15.设置开机启动启动kubelet

systemctl enable kubelet

16.初始化配置文件 #master节点进行初始化即可

mkdir ~/k8s-install && cd ~/k8s-install
修改kubeadm.yaml配置文件
vi kubeadm.yaml
########################################
apiVersion: kubeadm.k8s.io/v1beta2
bootstrapTokens:
- groups:
  - system:bootstrappers:kubeadm:default-node-token
  token: abcdef.0123456789abcdef
  ttl: 24h0m0s
  usages:
  - signing
  - authentication
kind: InitConfiguration
localAPIEndpoint:
  advertiseAddress: 192.168.89.10
  bindPort: 6443
nodeRegistration:
  criSocket: /var/run/dockershim.sock
  name: jackie001
  taints:
  - effect: NoSchedule
    key: node-role.kubernetes.io/master
---
apiServer:
  timeoutForControlPlane: 4m0s
apiVersion: kubeadm.k8s.io/v1beta2
certificatesDir: /etc/kubernetes/pki
clusterName: kubernetes
controllerManager: {}
dns:
  type: CoreDNS
etcd:
  local:
    dataDir: /var/lib/etcd
imageRepository: registry.aliyuncs.com/google_containers
kind: ClusterConfiguration
kubernetesVersion: v1.16.2
networking:
  dnsDomain: cluster.local
  podSubnet: 10.244.0.0/16
  serviceSubnet: 10.96.0.0/12
scheduler: {}

########################################
#################修改一下配置内容##########
advertiseAddress: 192.168.89.10 # 改为k8s_master内网ip
kubernetesVersion: v1.16.2 #修改K8S版本
podSubnet: 10.244.0.0/16  #添加pod网段,设置容器内网络
imageRepository: registry.aliyuncs.com/google_containers #修改阿里云镜像
########################################
初始化配置文件
kubeadm config print init-defaults > kubeadm.yaml

17.检查镜像列表

kubeadm config images list --config kubeadm.yaml
下载镜像
kubeadm config images pull --config kubeadm.yaml
检查镜像
docker images|grep aliyun

18.初始化kubeadm文件

kubeadm init --config kubeadm.yaml

#####安装成功后出现该文字信息

############安装成功后出现该文字信息#################
Your Kubernetes control-plane has initialized successfully!

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/

Then you can join any number of worker nodes by running the following on each as root:

kubeadm join 192.168.89.10:6443 --token abcdef.0123456789abcdef \
    --discovery-token-ca-cert-hash sha256:de68b9b6003e2dcdc51877c66ff4e6b9c8741b265d5797fabdb43aa76d7b606f 
##########################################################################

19.使用集群创建K8S配置文件

mkdir -p $HOME/.kube
 sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
 sudo chown $(id -u):$(id -g) $HOME/.kube/config
可以进行kubectl进行交互
kubectl get pod -n kube-system
kubectl get pods
kubectl get nodes
kubectl get pods -A
kubectl get nodes -owide
......好多指令不打了 俺想下班呜呜呜呜

20.添加node节点进去集群:

(Then you can join any number of worker nodes by running the following on each as root:)

(在子节点进行添加!!!这段代码在刚才生成的文件里面copy唷~)

kubeadm join 192.168.89.10:6443 --token abcdef.0123456789abcdef \
   --discovery-token-ca-cert-hash sha256:f78b5772ed94954473d1f89243ac67f02318b37abba9ca4fd7115b1c0f2b7676
配置完成后可以进行kubectl指令交互查看node节点是否集群,在此节点状态为no ready,就需要安装网络服务,教程采用flannel网络插件

21.K8S的集群网络,需要额外插件(下载flannel插件)

wget https://raw.githubusercontent.com/coreos/flannel/2140ac876ef134e0ed5af15c65e414cf26827915/Documentation/kube-flannel.yml
如果有点卡就ctrl+c再次输入直至安装成功即可~
安装成功后则需要添加网卡信息(在第190行~)
vim kube-flannel.yml 
进去后输入“:190”

加入相关配置PS:!!!有坑:空格或者缩进的原因,使用tab缩进是不允许的####

- --iface=ens192 

22.在master节点下载flannel镜像

docker pull quay.io/coreos/flannel:v0.11.0-amd64
#显示节点详细信息#kubectl get nodes -owide!
 kubectl get pods -A
#K8S的配置 组件非常多 可以利用namespace,进行分类查看#
23.flannel 集群网络:集群ip(创建flannel文件生效)
kubectl create -f kube-flannel.yml

kubectl get pod -n kube-system
kubectl get nodes
kubectl get pods -A

当查看节点的status时为ready的时候!!证明了一件事。。

##集群安装成功!!!!##

你可能感兴趣的:(计算机小知识~,kubernetes,docker,linux)