coredns 安装使用
k8s service的存在就是为了与外界连通。
- 防止Pod失联(服务发现)
- 定义一组Pod的访问策略(负载均衡[基于iptables,ipvs])
- 支持ClusterIP,NodePort以及LoadBalancer三种类型
- Service的底层实现主要有iptables和ipvs二种网络模式
默认使用iptables 如需使用ipvs 需要指定
编辑kube-proxy 配置文件 添加以下内容
--proxy-mode=ipvs
--masquerade-all=true
查看
yum install ipvsadm
ipvsadm -L -n
对比
Iptables:
- 灵活,功能强大
- 规则遍历匹配和更新,呈线性时延
- 可扩展性
IPVS:
- 工作在内核态,有更好的性能
- 调度算法丰富:rr,wrr,lc,wlc,ip hash…
coredns安装
tar xvf kubernetes-src.tar.gz 这个包可以从github下载
cd cluster/addons/dns/coredns/
#指定你自己的DNSSERVER地址和Domain
[root@node1 coredns]# cat transforms2sed.sed
s/__PILLAR__DNS__SERVER__/10.254.0.10/g
s/__PILLAR__DNS__DOMAIN__/cluster.local./g
s/__PILLAR__CLUSTER_CIDR__/$SERVICE_CLUSTER_IP_RANGE/g
s/__MACHINE_GENERATED_WARNING__/Warning: This is a file generated from the base underscore template file: __SOURCE_FILENAME__/g
sed -f transforms2sed.sed coredns.yaml.base > coredns.yaml
kubectl create -f coredns.yaml
修改镜像地址为ccr.ccs.tencentyun.com/cl0411/coredns:1.2.6
查看coredns pod
[root@node1 coredns]# kubectl get pods -n kube-system
NAME READY STATUS RESTARTS AGE
coredns-77c77b6f8d-v2nhn 1/1 Running 0 38m
[root@node1 coredns]#
暴露一个nginx server
[root@node1 ~]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.254.0.1 <none> 443/TCP 23h
nginx-service NodePort 10.254.7.144 <none> 80:49896/TCP,443:38447/TCP 66m
创建一个nginx deployment
[root@node1 ~]# kubectl get deploy
NAME READY UP-TO-DATE AVAILABLE AGE
nginx-deployment 2/2 2 2 70m
[root@node1 ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-deployment-587ccff74-4z5pt 1/1 Running 0 70m
nginx-deployment-587ccff74-gwb44 1/1 Running 0 70m
验证dns解析
[root@node1 cfg]# kubectl exec -it nginx-deployment-587ccff74-4z5pt -- /bin/bash
root@nginx-deployment-587ccff74-4z5pt:/# apt-get update -y
root@nginx-deployment-587ccff74-4z5pt:/# apt-get install iputils-ping
root@nginx-deployment-587ccff74-4z5pt:/# ping nginx-service
PING nginx-service.default.svc.cluster.local (10.254.7.144) 56(84) bytes of data.
64 bytes from nginx-service.default.svc.cluster.local (10.254.7.144): icmp_seq=1 ttl=64 time=0.035 ms
64 bytes from nginx-service.default.svc.cluster.local (10.254.7.144): icmp_seq=2 ttl=64 time=0.079 ms
64 bytes from nginx-service.default.svc.cluster.local (10.254.7.144): icmp_seq=3 ttl=64 time=0.067 ms
64 bytes from nginx-service.default.svc.cluster.local (10.254.7.144): icmp_seq=4 ttl=64 time=0.060 ms
coredns 安装使用
http://www.jcwit.com/article/90/