二进制安装k8s之网络安装

一、安装网络插件flannel

所有的node节点都需要安装网络插件才能让所有的Pod加入到同一个局域网中。

yum install -y flannel
vim /usr/lib/systemd/system/flanneld.service
	[Unit]
	Description=Flanneld overlay address etcd agent
	After=network.target
	After=network-online.target
	Wants=network-online.target
	After=etcd.service
	Before=docker.service
	
	[Service]
	Type=notify
	EnvironmentFile=/etc/sysconfig/flanneld
	EnvironmentFile=-/etc/sysconfig/docker-network
	ExecStart=/usr/bin/flanneld-start \
	  -etcd-endpoints=${FLANNEL_ETCD_ENDPOINTS} \
	  -etcd-prefix=${FLANNEL_ETCD_PREFIX} \
	  $FLANNEL_OPTIONS
	
	ExecStartPost=/usr/libexec/flannel/mk-docker-opts.sh -k DOCKER_NETWORK_OPTIONS -d /run/flannel/docker
	Restart=on-failure
	
	[Install]
	WantedBy=multi-user.target
	WantedBy=docker.service
	
vim /etc/sysconfig/flanneld
	# Flanneld configuration options  
	
	# etcd url location.  Point this to the server where etcd runs
	FLANNEL_ETCD_ENDPOINTS="https://192.168.80.112:2379,https://192.168.80.130:2379,https://192.168.80.146:2379"
	
	# etcd config key.  This is the configuration key that flannel queries
	# For address range assignment
	FLANNEL_ETCD_PREFIX="/kube-centos/network"
	
	# Any additional options that you want to pass
	FLANNEL_OPTIONS="-etcd-cafile=/opt/etcd_ca/ca.pem -etcd-certfile=/opt/etcd_ca/server.pem -etcd-keyfile=/opt/etcd_ca/server-key.pem"

#在etcd库中为flannel使用的网络配置
etcdctl mkdir /kube-centos/network
etcdctl mk /kube-centos/network/config '{"Network":"172.30.0.0/16","SubnetLen":24,"Backend":{"Type":"host-gw"}}'

systemctl daemon-reload
systemctl enable flanneld
systemctl start flanneld
systemctl status flanneld

#让docker使用网络插件所配置的网络
#在/usr/lib/systemd/system/docker.service中的[service]添加下面一行
EnvironmentFile=/run/flannel/docker
systemctl daemon-reload
systemctl enable docker
systemctl start docker
systemctl status docker

试着创建pod进行 node节点和pod互ping  pod之间互ping  

二、安装coreDNS

为k8s集群安装CoreDNS插件用于实现域名解析的工作
在master节点上执行

mkdir /opt/coredns  && cd /opt/coredns/
wget https://raw.githubusercontent.com/coredns/deployment/master/kubernetes/deploy.sh
wget https://raw.githubusercontent.com/coredns/deployment/master/kubernetes/coredns.yaml.sed
chmod +x deploy.sh
#修改$DNS_DOMAIN、$DNS_SERVER_IP变量为实际值,并修改image后面的镜像。这里直接用deploy.sh脚本进行修改:
./deploy.sh -s -r 10.0.0.0/16 -i 10.0.0.2 -d cluster.local > coredns.yaml

[root@192-168-80-112 coredns]# kubectl create -f coredns.yaml

serviceaccount/coredns created
clusterrole.rbac.authorization.k8s.io/system:coredns created
clusterrolebinding.rbac.authorization.k8s.io/system:coredns created
configmap/coredns created
deployment.apps/coredns created
service/kube-dns created

[root@192-168-80-112 coredns]# kubectl get svc,pod -n kube-system
NAME               TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)                  AGE
service/kube-dns   ClusterIP   10.0.0.2     <none>        53/UDP,53/TCP,9153/TCP   19s

NAME                           READY   STATUS    RESTARTS   AGE
pod/coredns-55f46dd959-rdsf7   1/1     Running   0          19s
pod/coredns-55f46dd959-vwxcd   1/1     Running   0          19s

node节点中kubelet配置使用coredns
在/opt/kubernetes/cfg/kubelet文件添加如下三行
–cluster-dns=10.0.0.2
–cluster-domain=cluster.local.
–resolv-conf=/etc/resolv.conf \

验证coredns工作

kubectl run busybox --replicas=2 --labels="run=load-balancer-example" --image=busybox  --port=80 --command sleep 3600

[root@192-168-80-112 coredns]# kubectl exec -it  busybox-654f446c66-92s79 /bin/sh

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值