centos7 k8s 安装搭建

环境:
centos7

192.168.172.133:k8s-maser
192.168.172.132:k8s-node1

三个虚拟机同步操作
1:关闭防火墙
systemctl stop firewalld
setenforce 0

2:时间同步
yum -y install ntpdate
ntpdate pool.ntp.org

3:修改主机名
hostnamectl set-hostname k8s-master
hostnamectl set-hostname k8s-node1

4: 编辑hosts文件
vim /etc/hosts
192.168.172.133 k8s-master
192.168.172.132 k8s-node1

5: 安装指定版本的docker
yum -y install wget 【先安装这个】
wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo
【复制docker源到另两台虚拟机】
scp /etc/yum.repos.d/docker-ce.repo 192.168.112.154:/etc/yum.repos.d/
scp /etc/yum.repos.d/docker-ce.repo 192.168.112.155:/etc/yum.repos.d/
【同步安装】
yum -y install docker-ce-18.06.3.ce-3.el7

6:运行docker
systemctl enable docker
systemctl start docker

7:docker镜像加速
vim /etc/docker/daemon.json

{
“exec-opts”: [“native.cgroupdriver=systemd”],
“log-driver”: “json-file”,
“log-opts”: {
“max-size”: “100m”
},
“storage-driver”: “overlay2”,
“registry-mirrors”:[
“https://kfwkfulq.mirror.aliyuncs.com”,
“https://2lqq34jg.mirror.aliyuncs.com”,
“https://pee6w651.mirror.aliyuncs.com”,
“http://hub-mirror.c.163.com”,
“https://docker.mirrors.ustc.edu.cn”,
“https://registry.docker-cn.com”
]
}

【重启】
systemctl restart docker

8:上传k8s的yum源
【rz上传,并分发给node端】
cp k8s.repo /etc/yum.repos.d/
scp k8s.repo 192.168.112.154:/etc/yum.repos.d/
scp k8s.repo 192.168.112.155:/etc/yum.repos.d/
【同步安装】
yum -y install kubelet-1.17.0 kubeadm-1.17.0 kubectl-1.17.0

9:设置kubelet 开机自启
systemctl enable kubelet【先不要启动它!!!】

上传k8s zip包
解压
cd k8s
cd images
docker load -i k.tar
导入k8star包

10 初始化集群
【三端都执行】
swapoff -a 关闭交换分区
在master节点上执行:
kubeadm init --apiserver-advertise-address=192.168.172.133 --image-repository registry.aliyuncs.com/google_containers --kubernetes-version v1.17.0 --service-cidr=10.1.0.0/16 --pod-network-cidr=10.244.0.0/16

【报错处理:】
[ERROR FileContent–proc-sys-net-bridge-bridge-nf-call-iptables]: /proc/sys/net/bridge/bridge-nf-call-iptables contents are not set to 1
echo “1” > /proc/sys/net/bridge/bridge-nf-call-iptables

[ERROR Swap]: running with swap on is not supported. Please disable swap
swapoff -a 【3个节点都要执行】

master上执行:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown ( i d − u ) : (id -u): (idu):(id -g) $HOME/.kube/config

  1. 将node节点加入到集群中:
    kubeadm join 192.168.112.153:6443 --token ssw908.dhsa03p4r64cl6xt
    –discovery-token-ca-cert-hash sha256:ba0f967e3c400acc8e9d8a9b9a06d6c1013dfa5785d416d04a1918d14547028d
    kubeadm reset
    验证:
    [root@k8s-master yum.repos.d]# kubectl get nodes
    NAME STATUS ROLES AGE VERSION
    k8s-master NotReady master 7m24s v1.17.0
    k8s-node1 NotReady 2m23s v1.17.0
    k8s-node2 NotReady 27s v1.17.0

12: 安装k8s的网络组件falneel
[root@k8s-master k8s-v1.17.0]# kubectl apply -f kube-flannel.yml
podsecuritypolicy.policy/psp.flannel.unprivileged created
clusterrole.rbac.authorization.k8s.io/flannel created
clusterrolebinding.rbac.authorization.k8s.io/flannel created
serviceaccount/flannel created
configmap/kube-flannel-cfg created
daemonset.apps/kube-flannel-ds-amd64 created
daemonset.apps/kube-flannel-ds-arm64 created
daemonset.apps/kube-flannel-ds-arm created
daemonset.apps/kube-flannel-ds-ppc64le created
daemonset.apps/kube-flannel-ds-s390x created

13: 查看pod转态
[root@k8s-master k8s-v1.17.0]# kubectl get pod -A
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system coredns-9d85f5447-jf28g 1/1 Running 0 14m
kube-system coredns-9d85f5447-xrwgf 1/1 Running 0 14m
kube-system etcd-k8s-master 1/1 Running 0 14m
kube-system kube-apiserver-k8s-master 1/1 Running 0 14m
kube-system kube-controller-manager-k8s-master 1/1 Running 0 14m
kube-system kube-flannel-ds-amd64-9qbnz 1/1 Running 0 29s
kube-system kube-flannel-ds-amd64-jjzx9 1/1 Running 0 29s
kube-system kube-flannel-ds-amd64-mq68h 1/1 Running 0 29s
kube-system kube-proxy-5j497 1/1 Running 0 10m
kube-system kube-proxy-cl655 1/1 Running 0 8m20s
kube-system kube-proxy-d7wrw 1/1 Running 0 14m
kube-system kube-scheduler-k8s-master 1/1 Running 0 14m

14: 再次查看node状态
[root@k8s-master k8s-v1.17.0]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
k8s-master Ready master 16m v1.17.0
k8s-node1 Ready 11m v1.17.0
k8s-node2 Ready 9m12s v1.17.0
已经变为ready!!

15.【rz上传dash_board.yaml】
kubectl apply -f dash_board.yaml
查看kubernetes-dashboard镜像是否运行
kubectl get pod -A
kubernetes-dashboard dashboard-metrics-scraper-b68468655-9prh8 1/1 Running 0 2m20s
kubernetes-dashboard kubernetes-dashboard-64999dbccd-r7z5z 1/1 Running 0 2m21s

  1. 网页访问
    https://192.168.172.133:30002
    查看节点安装位置【然后切换ip地址】
    kubectl get pod -A -o wide
    kubernetes-dashboard dashboard-metrics-scraper-b68468655-9prh8 1/1 Running 0 152m 10.244.2.2 k8s-node2
    kubernetes-dashboard kubernetes-dashboard-64999dbccd-r7z5z 1/1 Running 0 152m 10.244.1.2 k8s-node1
    https://192.168.172.132:30002

[root@localhost ~]# kubectl get secret -n kubernetes-dashboard |grep dashboard-admin
dashboard-admin-token-rjn8d kubernetes.io/service-account-token 3 11m
[root@localhost ~]# kubectl describe secret dashboard-admin-token-rjn8d -n kubernetes-dashboard
Name: dashboard-admin-token-rjn8d
Namespace: kubernetes-dashboard
Labels:
Annotations: kubernetes.io/service-account.name: dashboard-admin
kubernetes.io/service-account.uid: 8488b1b4-4220-47a8-b1dd-86bce8fdf6f5

Type: kubernetes.io/service-account-token

Data

ca.crt: 1025 bytes
namespace: 20 bytes
token: eyJhbGciOiJSUzI1NiIsImtpZCI6ImN5Z0tlM1RINENRbkFWLWRPSmItV3hmMDBIVXd3V21nRWVBM0duSUltenMifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlcm5ldGVzLWRhc2hib2FyZCIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJkYXNoYm9hcmQtYWRtaW4tdG9rZW4tcmpuOGQiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC5uYW1lIjoiZGFzaGJvYXJkLWFkbWluIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQudWlkIjoiODQ4OGIxYjQtNDIyMC00N2E4LWIxZGQtODZiY2U4ZmRmNmY1Iiwic3ViIjoic3lzdGVtOnNlcnZpY2VhY2NvdW50Omt1YmVybmV0ZXMtZGFzaGJvYXJkOmRhc2hib2FyZC1hZG1pbiJ9.NhL8fMoNZGzPz7Ssar4xR5yv1chxWb4ncOrLhwBCY0nHPXsM8P86l9n84oy18nYsnmJcMJIgSk2_XlHmOWH9xMeRe0EytCyVWgvkCXxEj_xQzJ4leY2btoCa9DjpH8Ad8rMmiDCjzTGtaFbXlz0Uu8FbDRScfFKVKSI9koFoLxbVRlOiZCaoRteKj97i10zj5HsAqNynMvINW-3-m2G5K67aIApSQjrGYpE-VpddzxpqEdvbSHdiswc9x-sGVa4G9Y9CysqiaKUGkzCACtSPz9hPPVp2JB77rmgXRsjAVNbE39Wem0OMqcEHiUrnwZ3kvx_gZFlhQGKKOyQRReqBaw

©️2020 CSDN 皮肤主题: 游动-白 设计师:上身试试 返回首页