kubeadmin k8s安装
kubeadm k8s 安装
# docker 安装
sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-enginesudo yum install -y yum-utils
sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.reposudo yum install docker-ce docker-ce-cli containerd.io
sudo systemctl start docker
# 这里复制会有问题,打开daemon.json 删掉中文乱码
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://mozsd2i9.mirror.aliyuncs.com"],
"exec-opts": ["native.cgroupdriver=systemd"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
# 安装kubeadmin
cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
br_netfilter
EOFcat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sudo sysctl --system
cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
exclude=kubelet kubeadm kubectl
EOF
sudo setenforce 0#临时关闭
sudo swapoff -a
vim /etc/fstab
# 永久关闭
# /swapfile none swap defaults 0 0
sudo sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/configsudo yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes
sudo systemctl enable --now kubelet
# 启动master节点,节点ip 划分:master: 172.31.0.2 node1: 172.31.0.3node1: 172.31.0.4
kubeadm init \
--apiserver-advertise-address=172.31.0.2 \
--control-plane-endpoint=cluster-endpoint \
--image-repository registry.aliyuncs.com/google_containers \
--service-cidr=10.96.0.0/16 \
--pod-network-cidr=192.168.0.0/16mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config# 加入集群,在每个node节点hosts 文件里 配置master 节点的 xxxx(ip) cluster-endpoint 域名转发
kubeadm join cluster-endpoint:6443 --token jbu2to.i84zz22mfl7n6aya \
--discovery-token-ca-cert-hash sha256:b3a6cf267d8a72378211455f3ad52415fb2c6685e7cff85c72a4adab8c62373a# 安装网络插件
curl -O https://docs.projectcalico.org/manifests/calico.yaml
kubectl apply -f calico.yaml
# 安装dashboard
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.4.0/aio/deploy/recommended.yaml
kubectl edit svc kubernetes-dashboard -n kubernetes-dashboard
# 将type: ClusterIP 改为NodePort
# 查看dashboard 的端口,端口31522是映射到主机的端口,因为是用虚拟机搭建,所以还需要将这个端口映射到电脑本地
kubectl get svc -A | grep kubernetes-dashboard
kubernetes-dashboard dashboard-metrics-scraper ClusterIP 10.96.37.18 <none> 8000/TCP 16h
kubernetes-dashboard kubernetes-dashboard NodePort 10.96.189.87 <none> 443:31522/TCP 16h# 创建用户 dashboard-account.yml 内容如下
apiVersion: v1
kind: ServiceAccount
metadata:
name: admin-user
namespace: kubernetes-dashboard
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: admin-user
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: admin-user
namespace: kubernetes-dashboard
获取用户token
kubectl -n kubernetes-dashboard get secret \
$(kubectl -n kubernetes-dashboard get sa/admin-user -o jsonpath="{.secrets[0].name}") \
-o go-template="{{.data.token | base64decode}}"
good luck !
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/configAlternatively, if you are the root user, you can run:
export KUBECONFIG=/etc/kubernetes/admin.conf
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/You can now join any number of control-plane nodes by copying certificate authorities
and service account keys on each node and then running the following as root:kubeadm join cluster-endpoint:6443 --token jbu2to.i84zz22mfl7n6aya \
--discovery-token-ca-cert-hash sha256:b3a6cf267d8a72378211455f3ad52415fb2c6685e7cff85c72a4adab8c62373a \
--control-planeThen you can join any number of worker nodes by running the following on each as root:
kubeadm join cluster-endpoint:6443 --token jbu2to.i84zz22mfl7n6aya \
--discovery-token-ca-cert-hash sha256:b3a6cf267d8a72378211455f3ad52415fb2c6685e7cff85c72a4adab8c62373a
更多推荐
所有评论(0)