k8s安装flannel网络插件
时间: 2023-06-17 11:03:22 浏览: 207
Flannel.rar
安装Flannel网络插件需要以下步骤:
1. 在所有节点上安装flannel二进制文件:
```bash
$ wget https://github.com/coreos/flannel/releases/download/v0.13.0/flannel-v0.13.0-linux-amd64.tar.gz
$ tar -xvf flannel-v0.13.0-linux-amd64.tar.gz
$ cd flannel-v0.13.0-linux-amd64
$ sudo cp flanneld /usr/local/bin/
$ sudo cp mk-docker-opts.sh /usr/local/bin/
```
2. 创建flannel配置文件 `/etc/kubernetes/cni/net.d/10-flannel.conf`:
```bash
{
"cniVersion": "0.3.1",
"name": "flannel",
"type": "flannel",
"delegate": {
"isDefaultGateway": true
}
}
```
3. 在所有节点上启动flannel服务:
```bash
$ sudo systemctl start flanneld
```
4. 验证flannel是否运行正常:
```bash
$ sudo systemctl status flanneld
```
5. 在Master节点上检查kubelet配置文件 `/etc/kubernetes/kubelet.conf`是否包含以下内容:
```yaml
apiVersion: v1
clusters:
- cluster:
certificate-authority: /etc/kubernetes/pki/ca.crt
server: https://127.0.0.1:6443
name: kubernetes
contexts:
- context:
cluster: kubernetes
user: system:node:<node-name>
name: default
current-context: default
kind: Config
preferences: {}
users:
- name: system:node:<node-name>
user:
client-certificate: /etc/kubernetes/pki/apiserver-kubelet-client.crt
client-key: /etc/kubernetes/pki/apiserver-kubelet-client.key
```
6. 在Master节点上创建kube-flannel.yml文件:
```yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: kube-flannel-cfg
namespace: kube-system
labels:
tier: node
app: flannel
data:
cni-conf.json: |
{
"name": "cbr0",
"cniVersion": "0.3.1",
"plugins": [
{
"type": "flannel",
"delegate": {
"isDefaultGateway": true
}
},
{
"type": "portmap",
"capabilities": {
"portMappings": true
}
}
]
}
net-conf.json: |
{
"Network": "10.244.0.0/16",
"Backend": {
"Type": "vxlan"
}
}
---
apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
name: kube-flannel-ds
namespace: kube-system
labels:
tier: node
app: flannel
spec:
updateStrategy:
type: RollingUpdate
selector:
matchLabels:
tier: node
app: flannel
template:
metadata:
labels:
tier: node
app: flannel
spec:
hostNetwork: true
containers:
- name: kube-flannel
image: quay.io/coreos/flannel:v0.13.0-rc2
command:
- /opt/bin/flanneld
args:
- --ip-masq
- --kube-subnet-mgr
- --iface=$(POD_IP)
env:
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
securityContext:
privileged: true
volumeMounts:
- name: flannel-cfg
mountPath: /etc/kube-flannel/
volumes:
- name: flannel-cfg
configMap:
name: kube-flannel-cfg
- name: run
hostPath:
path: /run
type: ""
```
7. 在Master节点上应用kube-flannel.yml:
```bash
$ kubectl apply -f kube-flannel.yml
```
8. 检查所有节点上的flannel是否运行正常:
```bash
$ kubectl get pods -n kube-system
```
如果所有节点上的flannel状态都是Running,则表示flannel网络插件安装成功。
阅读全文