k8s集群安装CNI插件
1.下载插件的配置文件
[root@master231 ~]# mkdir /manifests/cni
wget https://github.com/flannel-io/flannel/releases/latest/download/kube-flannel.yml -O /manifests/cni/kube-flannel.yml
kube-flannel.yml : 连接
2.修改配置文件
vim /manifests/cni/kube-flannel.yml
将
"Network": "10.244.0.0/16",
修改为:
"Network": "10.100.0.0/16",
3.安装flannel插件
[root@master231 ~]# kubectl apply -f /manifests/cni/kube-flannel.yml
4.验证网络插件是否部署成功
kubectl -n kube-flannel get pods
kubectl get nodes
kubectl -n kube-flannel get pods -o wide
5.推送测试镜像到harbor
docker login -u admin -p 1 harbor.baimei.com
我们用 alpine 镜像做测试
拉一个 alpine 镜像
docker pull alpine
先在 harbor 上建立一个 个项目
找到 "推送命令"
docker tag SOURCE_IMAGE[:TAG] harbor.baimei.com/testk8s/REPOSITORY[:TAG]
仿照上边的的命令 给本地打镜像打 tag
docker tag alpine harbor.baimei.com/testk8s/alpine #不加tag 默认是 laste
推送到 harbor
docker push harbor.baimei.com/testk8s/alpine
6.启动Pod测试
[root@master231 ~]# mkdir /manifests/pod
[root@master231 ~]# cat /manifests/pod/01-flannel-test.yaml
# 指定apiserver版本号
apiVersion: v1
# 指定资源的类型
kind: Pod
# 定义源数据信息
metadata:
# Pod的名称
name: pod-c1
# 用户定义资源期望运行的状态
spec:
# 指定在worker232的工作节点运行
nodeName: worker232
# 在Pod内运行的容器定义
containers:
# 容器的名称
- name: c1
# 镜像名称
image: harbor.baimei.com/baimei-linux/alpine:latest
# 相当于Dockerfile的ENTRYPOINT指令,指定容器运行的命令
command: ["tail","-f","/etc/hosts"]
---
apiVersion: v1
kind: Pod
metadata:
name: pod-c2
spec:
nodeName: worker233
containers:
- name: c2
image: harbor.baimei.com/baimei-linux/alpine:latest
command: ["sleep","3600"]
然后执行:
kubectl apply -f /manifests/pod/01-flannel-test.yaml
kubectl get pods -o wide
kubectl exec pod-c1 -- ifconfig
kubectl exec pod-c1 -- ping 10.100.2.2 -c 3