注意!!!
虚拟机实验环境不要使用’克隆’!!!
唯一标识冲突:K8S集群中的每个节点都需要具有唯一的标识符,例如节点名称、IP地址、MAC地址等。当克隆虚拟机时,这些唯一标识符将与源虚拟机相同, 可能导致网络冲突、资源冲突以及其他问题。
节点状态和配置:K8S集群中的每个节点都应该具有一致的状态和配置。如果使用克隆的虚拟机作为节点,其状态和配置可能不同于其他节点,这可能导致集群中的问题,如调度错误、数据不一致等。
安全性问题:克隆的虚拟机可能会保留源虚拟机的敏感信息,包括证书、密钥等。如果创建证书或秘钥生成或许会出现冲突,导致异常;
rocky8.9配置K8S集群
节点 | 主机名 | IP地址 |
---|---|---|
master | tang1 | 192.168.211.101 |
node1 | tang2 | 192.168.211.102 |
node2 | tang3 | 192.168.211.103 |
vi /etc/sysconfig/network-scripts
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ensxxx
UUID=xxxxxxxxxxxxx
DEVICE=ens32
ONBOOT=yes
IPADDR=192.168.211.101
DNS1=114.114.114.114
NETMASK=255.255.255.0
nmcli connection reload(表示加载配置信息)
nmcli connection up 网卡名,两条命令都要运行才可以
# 关闭 firewalld 防火墙
$ systemctl stop firewalld
$ systemctl disable firewalld
$ setenforce 0
$ sed -ri 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config # 永久关闭 SELinux
# 临时禁用 swap
$ swapoff -a
$ sed -i '/.*swap.*/d' /etc/fstab # 永久禁用 swap
# 配置 /etc/hosts
$ cat > /etc/hosts << EOF
192.168.211.101 tang1
192.168.211.102 tang2
192.168.211.103 tang3
EOF
modprobe br_netfilter ##生成bridge相关内核参数
cat > /etc/sysctl.d/k8s.conf << EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system # 生效
echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf
sysctl -p
yum install -y chrony;
systemctl start chronyd;
systemctl enable chronyd
2)安装containerd(三个节点上操作)
yum install -y yum-utils
yum-config-manager
--add-repo
https://download.docker.com/linux/centos/docker-ce.repo
安装containerd
yum install containerd.io -y
systemctl enable containerd
systemctl start containerd
containerd config default > /etc/containerd/config.toml
修改配置
vi /etc/containerd/config.toml
sandbox_image = "registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.8" # 修改为阿里云镜像地址
SystemdCgroup = true
systemctl restart containerd
3)配置kubernetes仓库(三个节点都操作)
cat <<EOF > /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
EOF
说明:kubernetes用的是RHEL7的源,和8是通用的
yum --showduplicates list kubeadm #都选择y
yum install -y kubelet-1.26.2 kubeadm-1.26.2 kubectl-1.26.2
systemctl start kubelet.service
systemctl enable kubelet.service
5)设置crictl连接 containerd(三个节点都操作)
crictl config --set runtime-endpoint=unix:///run/containerd/containerd.sock
kubeadm init --image-repository=registry.cn-hangzhou.aliyuncs.com/google_containers --apiserver-advertise-address=192.168.211.103 --kubernetes-version=v1.26.2 --service-cidr=10.15.0.0/16 --pod-network-cidr=10.18.0.0/16
#修改ip地址为master节点,只需要master主机修改就可以
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 192.168.211.103:6443 --token 4mvr8t.tqjjac69wg7vtk7x
--discovery-token-ca-cert-hash sha256:6d2f9a8ebc144c3aea5a199a17310adbcfd0fa8605270bc84bd1ae02c82e90b4
说明: 上面这条命令就是如果需要将node节点加入到集群需要执行的命令,这个token有效期为24小时,如果过期,可以使用下面命令获取
kubeadm token create --print-join-command
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
获取节点信息:
kubectl get node
kubectl get pod --all-namespaces
kubeadm join 192.168.211.103:6443 --token 4mvr8t.tqjjac69wg7vtk7x
--discovery-token-ca-cert-hash sha256:6d2f9a8ebc144c3aea5a199a17310adbcfd0fa8605270bc84bd1ae02c82e90b4
curl https://raw.githubusercontent.com/projectcalico/calico/v3.25.0/manifests/calico.yaml -O
下载完后还需要修改⾥⾯定义 Pod ⽹络(CALICO_IPV4POOL_CIDR),与前⾯ kubeadm init 的 –podnetwork–cidr 指定的⼀样
vim calico.yaml
# - name: CALICO_IPV4POOL_CIDR
# value: "192.168.0.0/16"
# 修改为:
- name: CALICO_IPV4POOL_CIDR
value: "10.18.0.0/16"
kubectl apply -f calico.yaml
kubectl get pods -n kube-system
kubectl get node
#如果想在节点上运行这条命令,要把master创建的目录复制到节点上,需要:
yum install -y rsync
rsync -av $HOME/.kube/ tang2:/root/.kube/
运行,拷贝到哪台主机需要修改主机名,tang?:
scp -r /root/.kube/ tang2:/root/.kube/
步骤略
kubectl create deployment testdp --image=nginx:1.23.2 ##deploymnet名字为testdp 镜像为nginx:1.23.2
kubectl get deployment
3)查看pod
kubectl get pods
4)查看pod详情
kubectl describe pod testdp-68dc848667-d6xhg #根据自己的name值去看
kubectl expose deployment testdp --port=80 --type=NodePort --target-port=80 --name=testsvc
kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.15.0.1 <none> 443/TCP 156m
testsvc NodePort 10.15.248.16 <none> 80:30360/TCP 8s
192.168.211.102:30360
原文地址:https://blog.csdn.net/weixin_44681307/article/details/134601308
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.7code.cn/show_15625.html
如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱:suwngjj01@126.com进行投诉反馈,一经查实,立即删除!