kubeadm 部署 k8s

2020-08-25  本文已影响0人  麟之趾a

环境准备

IP 角色 系统
192.168.1.31 master CentOS7.6
192.168.1.32 node CentOS7.6
192.168.1.33 node CentOS7.6
192.168.1.34 node CentOS7.6

关闭 firewalld 和禁用selinux

配置ssh密钥连接

ssh keygen
cd /root/.ssh
mv id_rsa.pub authorized_keys
scp -r /root/.ssh/ 192.168.1.32:/root/
scp -r /root/.ssh/ 192.168.1.33:/root/
scp -r /root/.ssh/ 192.168.1.34:/root/

配置hosts文件

[root@k8s-test-1 .ssh]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.31 k8s-test-1
192.168.1.32 k8s-test-2
192.168.1.33 k8s-test-3
192.168.1.34 k8s-test-4

scp /etc/hosts 192.168.1.31:/etc
scp /etc/hosts 192.168.1.32:/etc
scp /etc/hosts 192.168.1.33:/etc

禁用swap

swapoff -a

启用ipvs模块

vim ipvs.sh
#!/bin/bash
ipvs_mods_dir="/usr/lib/modules/$(uname -r)/kernel/net/netfilter/ipvs"
for mod in $(ls $ipvs_mods_dir | grep -o "^[^.]*"); do
    /sbin/modinfo -F filename $mod  &> /dev/null
    if [ $? -eq 0 ]; then
        /sbin/modprobe $mod
    fi
done

yum 仓库配置

cd  /etc/yum.repos.d/
vim kubernetes.repo
[kubernetes]
name=Kubernetes repo
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
gpgcheck=0
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
enabled=1
wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

安装k8s

参考博客
[https://yq.aliyun.com/articles/759407](https://yq.aliyun.com/articles/759407)

网络

pod网络:
flannel 插件默认地址10.244.0.0/16,需要在两处指定。一是部署k8s时指定,
二是部署flannel时指定。两者的网络地址要匹配
calico:默认地址192.168.0.0/16
需要自己部署网络插件

[root@k8s-master ~]# kubectl get pods -n kube-system
NAME                                      READY   STATUS    RESTARTS   AGE
calico-kube-controllers-75d555c48-twgt9   1/1     Running   0          68m
calico-node-fvqvh                         1/1     Running   0          61m
calico-node-r8hq2                         1/1     Running   0          62m
calico-node-tfnjf                         1/1     Running   0          68m
calico-node-zvhh4                         1/1     Running   0          62m
coredns-546565776c-fn29b                  1/1     Running   0          77m
coredns-546565776c-sstbz                  1/1     Running   0          77m
etcd-k8s-master                           1/1     Running   0          77m
kube-apiserver-k8s-master                 1/1     Running   0          77m
kube-controller-manager-k8s-master        1/1     Running   0          77m
kube-proxy-28mcj                          1/1     Running   0          61m
kube-proxy-hrskf                          1/1     Running   0          62m
kube-proxy-nqzr4                          1/1     Running   0          62m
kube-proxy-qfmkq                          1/1     Running   0          77m
kube-scheduler-k8s-master                 1/1     Running   0          77m

-n 后面接k8s的名称空间,与内核名称空间不一样。
kubectl  get nodes   查看节点
kubectl 在任何节点上都能执行,但有个前提,在此节点的家目录有.kube目录和复制过去的配置文件

kubectl config view  查看配置文件信息
k8s 支持多用户管理,管理员和普通用户
上一篇下一篇

猜你喜欢

热点阅读