kubernetes集群搭建(二进制方式)之--cni部署
部署cni网络
master和node节点均需要部署,先在master节点部署然后拷贝到node节点
下载二进制文件
cd /data/src
wget https://github.com/containernetworking/plugins/releases/download/v0.8.6/cni-plugins-linux-amd64-v0.8.6.tgz
创建工作目录并解压二进制包
mkdir -p /data/cni/bin
tar zxvf cni-plugins-linux-amd64-v0.8.6.tgz -C /data/cni/bin
部署
wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
kubectl apply -f kube-flannel.yml
kubectl get pods -n kube-system
kubectl get node
授权apiserver访问kubelet
cat > apiserver-to-kubelet-rbac.yaml<< EOF
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
annotations:
rbac.authorization.kubernetes.io/autoupdate: "true"
labels:
kubernetes.io/bootstrapping: rbac-defaults
name: system:kube-apiserver-to-kubelet
rules:
- apiGroups:
- ""
resources:
- nodes/proxy
- nodes/stats
- nodes/log
- nodes/spec
- nodes/metrics
- pods/log
verbs:
- "*"
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: system:kube-apiserver
namespace: ""
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: system:kube-apiserver-to-kubelet
subjects:
- apiGroup: rbac.authorization.k8s.io
kind: User
name: kubernetes
EOF
kubectl apply -f apiserver-to-kubelet-rbac.yaml
拷贝目录到node节点:
scp -r /data/cni root@172.21.32.15:/data/
kubectl get node
NAME STATUS ROLES AGE VERSION
k8snode1 Ready 82m v1.19.8
看到ready说明就是可以了
验证:
kubectl create deployment nginx --image=nginx
kubectl expose deployment nginx --port=80 --type=NodePort
kubectl get pod,svc
service/kubernetes ClusterIP 10.0.0.1 443/TCP 4h2m
service/nginx NodePort 10.0.0.123 80:30729/TCP 11s
得到信息如上 获得 80:30729/TCP
在node节点中访问任何node节点ip:30729即可获取到nginx的初始页面