server: 192.168.66.100
master: 192.168.66.101
node1: 192.16t8.66.102
文章目录
- 1.rancher server 安装docker
- 2.部署k8s
- 3.kubeconfig
1.rancher server 安装docker
所有主机开通ipv4
vi /etc/sysctl.conf
#加入
net.ipv4.ip_forward = 1
#配置生效
sysctl -p
rancher-server开通docker服务:
yum remove docker*
yum install -y yum-utils
#配置docker的yum地址
yum-config-manager \
--add-repo \
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
#安装最新版本
yum install -y docker-ce docker-ce-cli
# 启动&开机启动docker
systemctl enable docker --now
# docker加速配置
mkdir -p /etc/docker
tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://82m9ar63.mirror.aliyuncs.com"],
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2"
}
EOF
systemctl daemon-reload
systemctl restart docker
rancher-server 用docker运行 rancher
docker run -d --privileged -p 80:80 -p 443:443 -v /opt/data/rancher_data/:/var/lib/rancher --restart=always --name rancher rancher/rancher:v2.7.5
2.部署k8s
master:
curl -fL https://192.168.66.100/system-agent-install.sh | sudo sh -s - --server https://192.168.66.100 --label 'cattle.io/os=linux' --token 6fr2r8wwdgrxdrqlzg2g2lwl2dwwmms8g49bg54s8chtmjrd4kpd7d --ca-checksum dcb5f0234226851d165c2ea0d212506b6f560eddf84af9e6200bbac4576280f5 --etcd --controlplane --worker
node1:
curl -fL https://192.168.66.100/system-agent-install.sh | sudo sh -s - --server https://192.168.66.100 --label 'cattle.io/os=linux' --token 6fr2r8wwdgrxdrqlzg2g2lwl2dwwmms8g49bg54s8chtmjrd4kpd7d --ca-checksum dcb5f0234226851d165c2ea0d212506b6f560eddf84af9e6200bbac4576280f5 --worker
等待:
3.kubeconfig
master:
mkdir /root/.kube
cd .kube/
vi config
apiVersion: v1
kind: Config
clusters:
- name: "cluster"
cluster:
server: "https://192.168.66.100/k8s/clusters/c-m-bjcmdw4j"
certificate-authority-data: "LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUJ2RENDQ\
VdPZ0F3SUJBZ0lCQURBS0JnZ3Foa2pPUFFRREFqQkdNUnd3R2dZRFZRUUtFeE5rZVc1aGJXbGoKY\
kdsemRHVnVaWEl0YjNKbk1TWXdKQVlEVlFRRERCMWtlVzVoYldsamJHbHpkR1Z1WlhJdFkyRkFNV\
GN4TlRBMQpPVEl4TnpBZUZ3MHlOREExTURjd05USXdNVGRhRncwek5EQTFNRFV3TlRJd01UZGFNR\
Vl4SERBYUJnTlZCQW9UCkUyUjVibUZ0YVdOc2FYTjBaVzVsY2kxdmNtY3hKakFrQmdOVkJBTU1IV\
1I1Ym1GdGFXTnNhWE4wWlc1bGNpMWoKWVVBeE56RTFNRFU1TWpFM01Ga3dFd1lIS29aSXpqMENBU\
VlJS29aSXpqMERBUWNEUWdBRW9EMHkrOFovRzF2NgprYWpLbE15ejFaYnZGQVFER21yV1Axb2JvQ\
1BXajZ5OFRLLzVlTUhwNHQyYVBxSUJVQ0M4bnZGMzV4R3pUUlJMCnJkQ214aEJOOGFOQ01FQXdEZ\
1lEVlIwUEFRSC9CQVFEQWdLa01BOEdBMVVkRXdFQi93UUZNQU1CQWY4d0hRWUQKVlIwT0JCWUVGQ\
VFxK05ONHovTERWT3Zpb3VQL1d2cC9XQ1NCTUFvR0NDcUdTTTQ5QkFNQ0EwY0FNRVFDSUFFNQp1W\
nNQdktwY3JtYjA3QUVCTFJLN240ZW1UTU5RaWJONUw4dzd1OTFDQWlBQTZaZVFNMVY1dWF4b0VKT\
mg0VWlFCk9LU0FyaHRlRWhhaklIRGpxWkVOR0E9PQotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0t"
users:
- name: "cluster"
user:
token: "kubeconfig-user-fmcqm8r5rt:p9fzkm6h4ccrsmrldldxnb8qfd92ttzvlpf9dr6djx5hw2hn48mnvz"
contexts:
- name: "cluster"
context:
user: "cluster"
cluster: "cluster"
current-context: "cluster"
#配置k8s的yum源地址
cat <<EOF | sudo tee /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
#安装 kubelet,kubeadm,kubectl
sudo yum install -y kubelet
#启动kubelet
sudo systemctl enable --now kubelet
于是在master节点上也可以进行命令kubectl get nodes