请安装k8s集群,centos安装k8s集群
请安装k8s集群,ubuntu安装k8s集群
kubectl edit configmaps kube-proxy -n kube-system #修改kube-proxy
#大约在40多行
37 ipvs:
38 excludeCIDRs: null
39 minSyncPeriod: 0s
40 scheduler: ""
41 strictARP: true #这里由原来的false修改为true
42 syncPeriod: 0s
43 tcpFinTimeout: 0s
44 tcpTimeout: 0s
45 udpTimeout: 0s
46 kind: KubeProxyConfiguration
47 metricsBindAddress: ""
48 mode: "ipvs" #这里原来是空的修改为ipvs
49 nodePortAddresses: null
50 oomScoreAdj: null
51 portRange: ""
52 showHiddenMetricsForVersion: ""
53 winkernel:
54 enableDSR: false
55 forwardHealthCheckVip: false
56 networkName: ""
57 rootHnsEndpointName: ""
58 sourceVip: ""
kubectl rollout restart daemonset kube-proxy -n kube-system
kubectl get pods -n kube-system
#无网络情况下,先上传kubeedge.tar 和 metallb-native.yaml文件
docker load -i kubeedge.tar #导入镜像
#有网络可以直接拉去镜像
docker pull quay.io/metallb/controller:v0.13.5
docker pull quay.io/metallb/speaker:v0.13.5
wget https://raw.githubusercontent.com/metallb/metallb/v0.13.5/config/manifests/metallb-native.yaml
kubectl apply -f metallb-native.yaml
kubectl get pods -n metallb-system
[root@k8s-master01 ~]# kubectl get pods -n metallb-system
NAME READY STATUS RESTARTS AGE
controller-8d9cf599f-m4x27 1/1 Running 0 23s
speaker-zm7w4 1/1 Running 0 23s
speaker-zww5l 1/1 Running 0 23s
[root@k8s-master01 ~]#
#具体参考官网地址:https://metallb.universe.tf/configuration/#layer-2-configuration
#创建IP地址资源池,原则是跟主机在同一个网段,没有使用的地址,根据自己项目的规模我合理预留了21个IP
cat > first-ippool.yaml << EOF
apiVersion: metallb.io/v1beta1
kind: IPAddressPool
metadata:
name: first-pool
namespace: metallb-system
spec:
addresses:
- 192.168.186.200-192.168.186.220
EOF
kubectl apply -f first-ippool.yaml
kubectl get ipaddresspools -n metallb-system
[root@k8s-master01 ~]# kubectl get ipaddresspools -n metallb-system
NAME AGE
first-pool 2m1s
[root@k8s-master01 ~]#
#开启二层转发,实现k8s集群节点外访问
cat > l2forward.yaml << EOF
apiVersion: metallb.io/v1beta1
kind: L2Advertisement
metadata:
name: example
namespace: metallb-system
EOF
kubectl apply -f l2forward.yaml
#二层转发案例测试
cat > nginx.yaml << EOF
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- image: nginx
name: nginx
imagePullPolicy: IfNotPresent
---
apiVersion: v1
kind: Service
metadata:
name: nginx-svc
spec:
type: LoadBalancer
ports:
- port: 80
targetPort: 80
selector:
app: nginx
EOF
kubectl apply -f nginx.yaml
[root@k8s-master01 ~]# kubectl get pods,svc #svc的ip从地址池中分配的
NAME READY STATUS RESTARTS AGE
pod/nginx-5f5c64f949-bhpvf 1/1 Running 0 50s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 5h43m
service/nginx-svc LoadBalancer 10.99.41.146 192.168.186.200 80:30293/TCP 50s
[root@k8s-master01 ~]#
kubectl delete -f nginx.yaml #删除无用的pod和svc
KubeEdge由云和边缘组成。它建立在Kubernetes之上,为联网应用部署和云与边缘之间的元数据同步提供核心基础设施支持。所以如果我们想要设置KubeEdge,我们需要设置Kubernetes集群(可以使用现有的集群),云端和边缘端在cloud side, 我们需要安装
Docker
Kubernetes cluster
cloudcore
在 edge side, 我们需要安装
Docker
MQTT (配置可以选用,不是一定需要)
edgecore
#wget https://github.com/kubeedge/kubeedge/releases/download/v1.10.1/keadm-v1.10.1-linux-amd64.tar.gz
wget https://github.com/kubeedge/kubeedge/releases/download/v1.14.2/keadm-v1.14.2-linux-amd64.tar.gz
tar -zxvf keadm-v1.14.2-linux-amd64.tar.gz
cp keadm-v1.14.2-linux-amd64/keadm/keadm /usr/local/bin/
keadm version
#在master上部署
#设置云端 使用keadm初始化,安装cloudcore
docker pull kubeedge/cloudcore:v1.14.2
docker pull kubeedge/iptables-manager:v1.14.2
keadm init --advertise-address=192.168.110.100 --kubeedge-version=1.14.2 #这是master的ip
keadm init --advertise-address=192.168.186.200 --set iptablesManager.mode="external" --profile version=v1.14.2 #这里的IP是负载均衡器metallb分配的IP
#以上参数分别为master节点地址和要安装的KubeEdge版本。
#keadm reset #安装错误可以重置
keadm gettoken #获取token
[root@master ~]# keadm init --advertise-address=192.168.186.200 --set iptablesManager.mode="external" --profile version=v1.14.2 # 这里的IP是负载均衡器metallb分配的IP
Kubernetes version verification passed, KubeEdge installation will start...
CLOUDCORE started
=========CHART DETAILS=======
NAME: cloudcore
LAST DEPLOYED: Thu Oct 5 14:22:00 2023
NAMESPACE: kubeedge
STATUS: deployed
REVISION: 1
[root@master ~]#