k8s集群

1.关闭selinux
sed -i ‘s/enforcing/disabled’ /etc/selinx/config #永久
setenforce=0 #临时
关闭swap
swapoff -a #临时
sed -ri ‘s/.swap./#&/’ /etc/fstab #永久
sed -ri ‘s/.swap./#\0/’ /etc/fstab

2.设置主机名
hostnamectl set-hostname xxx

确保网络桥接的数据包经过iptables处理,启用相关内核参数
cat > sysctl.d/k8s.conf << EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF

tee /etc/sysctl.d/k8s.conf << EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF

重新加载配置生效
sysctl -p /etc/sysctl.d/k8s.conf

3.配置集群时间同步
yum install ntp ntpdate -y
ntpdate cn.pool.ntp.org
systemctl enable ntp && systemctl start ntp

4.配置k8syum源
vim /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=0

5.安装docker过程省略
6.安装kubeadm,kubectl,kubelet
kubeadm:用来初始化k8s集群的指令。
kubelet:在集群的每个节点上用来启动 Pod 和容器等。
kubectl:用来与k8s集群通信的命令行工具,查看、创建、更新和删除各种资源。

yum install -y kubelet-1.28.0 kubeadm-1.28.0 kubectl-1.28.0

systemctl enable kubelet

7.初始化master节点
kubeadm init \
–apiserver-advertise-address=主机ip地址 \
–control-plane-endpoint=cluster-endpoint \
–image-repository registryaliyuncs.com/google_containers \ #指定镜像仓库
–kubernetes-version v1.28.0 \
–service-cidr=10.96.0.0/12 \
–pod-network-cidr=172.20.0.0/16

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

Alternatively, 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/

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

kubeadm join cluster-endpoint:6443 –token xxxxxx \
–discovery-token-ca-cert-hash sha256:xxxxx

改 $HOME/.kube/config 文件的所有权UID,GID
id -u返回用户ID,和主组id
kubectl get node

8.将其他节点加入到kubenetes集群
输入kubeadm join指令

9.status:NOREADY
安装网络插件
Calico(负责集群中网络通信)
kubectl create -f tigera-operator.yaml
kubectl create -f custom-resource.yaml

kubectl get pods -n calico-system

10.安装dashboard图形化管理kubenetes
kubectl apply -f kubernetes-dashboard.yaml
kubectl get pods -n kubenetes-dashboard

访问dashboard
ip:30001(https访问

11.创建用户,用户授权,获取token
kubectl create serviceaccount dashboard-admin -n kubernetes-dashboard
kubectl create clusterrolebinding dashboard-cluster-admin –clusterrole=cluster-admin –serviceaccount=kube-system:dashboard-admin
kubectl create token dashboard-admin -n kubernetes-dashboard

复制token

图片[1]-k8s集群-晴天生活分享日志
------本页内容已结束,喜欢请分享------

感谢您的来访,获取更多精彩文章请收藏本站。

© 版权声明
THE END
喜欢就支持一下吧
点赞14 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容