docker集群運行在calico網絡上

2019獨角獸企業重金招聘Python工程師標準>>> hot3.png

##網絡及版本信息

docker1 centos7 192.168.75.200

docker2 centos7 192.168.75.201

物理網絡 192.168.75.1/24

Docker version 1.10.3, build 3999ccb-unsupported ,安裝過程略

# calicoctl version

Version:      v1.0.0-12-g0d6d228
Build date:   2017-01-17T09:01:03+0000
Git commit:   0d6d228

##1.安裝etcd

####下載安裝etcd

# ETCD_VER=v3.0.16

# DOWNLOAD_URL=https://github.com/coreos/etcd/releases/download

# curl -L ${DOWNLOAD_URL}/${ETCD_VER}/etcd-${ETCD_VER}-linux-amd64.tar.gz -o /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz

# mkdir -p /tmp/test-etcd && tar xzvf /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz -C /tmp/test-etcd --strip-components=1

# cd /tmp/test-etcd && cp etcd* /usr/local/bin/

啟動etcd

# etcd --listen-client-urls 'http://192.168.75.200:2379' --advertise-client-urls 'http://192.168.75.200:2379'

查看etcd信息

# etcdctl --endpoint 'http://192.168.75.200:2379' member list

8e9e05c52164694d: name=default peerURLs=http://localhost:2380 clientURLs=http://192.168.75.200:2379 isLeader=true

##2.下載安裝calico

修改網絡內核參數

# sysctl -w net.netfilter.nf_conntrack_max=1000000 # echo "net.netfilter.nf_conntrack_max=1000000" >> /etc/sysctl.conf

下載calicoctl

# cd /usr/local/bin/ && wget http://www.projectcalico.org/builds/calicoctl

# chmod 755 calicoctl

設置etcd環境變量

# export ETCD_ENDPOINTS=http://192.168.75.200:2379 && echo "export ETCD_ENDPOINTS=http://192.168.75.200:2379" >>/etc/profile

安裝運行calico node

# calicoctl node run

Running command to load modules: modprobe -a xt_set ip6_tables
Enabling IPv4 forwarding
Enabling IPv6 forwarding
Increasing conntrack limit
Removing old calico-node container (if running).
Running the following command to start calico-node:docker run --net=host --privileged --name=calico-node -d --restart=always -e ETCD_AUTHORITY= -e ETCD_SCHEME= -e NODENAME=docker1 -e CALICO_NETWORKING_BACKEND=bird -e NO_DEFAULT_POOLS= -e CALICO_LIBNETWORK_ENABLED=true -e CALICO_LIBNETWORK_IFPREFIX=cali -e ETCD_ENDPOINTS=http://192.168.75.200:2379 -v /run/docker/plugins:/run/docker/plugins -v /var/run/docker.sock:/var/run/docker.sock -v /var/run/calico:/var/run/calico -v /lib/modules:/lib/modules -v /var/log/calico:/var/log/calico calico/node:latestImage may take a short time to download if it is not available locally.
Container started, checking progress logs.
Waiting for etcd connection...
Using auto-detected IPv4 address: 192.168.75.200
No IPv6 address configured
Using global AS number
Calico node name:  docker1
CALICO_LIBNETWORK_ENABLED is true - start libnetwork service
Calico node started successfully

在docker1查看calico node狀態,發現與docker2(192.168.75.201)連接已建立

# calicoctl node status

Calico process is running.IPv4 BGP status
+----------------+-------------------+-------+----------+-------------+
|  PEER ADDRESS  |     PEER TYPE     | STATE |  SINCE   |    INFO     |
+----------------+-------------------+-------+----------+-------------+
| 192.168.75.201 | node-to-node mesh | up    | 01:57:54 | Established |
+----------------+-------------------+-------+----------+-------------+IPv6 BGP status
No IPv6 peers found.

##3.配置calico pool

查看默認pool

# calicoctl get pool

CIDR                       
192.168.0.0/16             
fd80:24e2:f998:72d6::/64   

刪除默認pool,在任意一臺node上操作

# calicoctl delete pool 192.168.0.0/16

Successfully deleted 1 'ipPool' resource(s)

# calicoctl delete pool fd80:24e2:f998:72d6::/64

Successfully deleted 1 'ipPool' resource(s)

創建新的ipPool,在任意一臺node上操作

# vi /etc/calico/ippool_10.1.0.0_16.cfg

apiVersion: v1
kind: ipPool
metadata:cidr: 10.1.0.0/16
spec:ipip:enabled: truenat-outgoing: truedisabled: false

# calicoctl create -f /etc/calico/ippool_10.1.0.0_16.cfg

Successfully created 1 'ipPool' resource(s)

##4.配置docker,創建docker network

修改集群中每臺docker啟動參數,重啟docker

添加--cluster-store=etcd://192.168.75.200:2379/calico 指定docker集群使用的存儲,否則下一步不會成功創建network

# vi /etc/sysconfig/docker

OPTIONS='--selinux-enabled --log-driver=journald --cluster-store=etcd://192.168.75.200:2379/calico'

集群中任意一臺上docker創建網絡

# docker network create --driver=calico --ipam-driver=calico-ipam net1

0501f1b788756d122568e7aed2d7c56fe2de9138f9bd00f6628c4b66c81c7c9b

# docker network create --driver=calico --ipam-driver=calico-ipam net2

4b636bf63b23dee13b817c911335823a84ad6d55771a44e89fb81c16f76663ad

# docker network ls

NETWORK ID          NAME                DRIVER
54a450c39848        net1                calico              
8fdcdecdb0bc        net2                calico              
e0d1a688fef8        none                null                
0e987140865a        host                host                
b5122ac5e20e        bridge              bridge    

##5.測試網絡連否連通

docker1啟動net1,net2各一個container

[root@docker1 bin]# docker run -itd --net=net1 --name=testnet1 centos /bin/bash
579c509e293e25340f10cc188a91136f99ed9021b99f795a9056a683b6b46864
[root@docker1 bin]# docker run -itd --net=net2 --name=testnet2 centos /bin/bash
c8777a2ff6add64e6abf454828820a6cfee332086a58c769a6cf1e5e0fda8760

docker2啟動net1,net2各一個container

[root@docker2 bin]# docker run -itd --net=net1 --name=testnet3 centos /bin/bash
8bb7be8d86a04631a442a9f43e6be9576a891f704b91042550c5fe632fa11f06
[root@docker2 bin]# docker run -itd --net=net2 --name=testnet4 centos /bin/bash
422f4466db503b380f646d6eaee14a2f695550669fd4987fadefff438f456a36

container ip信息如下

testnet1 10.1.174.193
testnet2 10.1.174.194
testnet3 10.1.166.129
testnet4 10.1.166.130

####testnet1上ping其他container

testnet1容器只和docker2上的testnet3容器能通,因為兩個container都屬于net1網絡

[root@579c509e293e /]# ping 10.1.166.129
PING 10.1.166.129 (10.1.166.129) 56(84) bytes of data.
64 bytes from 10.1.166.129: icmp_seq=1 ttl=62 time=0.400 ms
^C
--- 10.1.166.129 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.400/0.400/0.400/0.000 ms
[root@579c509e293e /]# ping 10.1.166.130
PING 10.1.166.130 (10.1.166.130) 56(84) bytes of data.
^C
--- 10.1.166.130 ping statistics ---
4 packets transmitted, 0 received, 100% packet loss, time 3000ms[root@579c509e293e /]# ping 10.1.174.194
PING 10.1.174.194 (10.1.174.194) 56(84) bytes of data.
^C
--- 10.1.174.194 ping statistics ---
3 packets transmitted, 0 received, 100% packet loss, time 2000ms

遇到的問題:

1.docker異常后無法restart testnet3,4容器

docker: Error response from daemon: service endpoint with name testnet3 already exists.

解決方案:

etcd中endpoint信息未刪除,手動刪除吧,查找方法如下

54a450.....是network id,可通過docker network ls查找到

遍歷下/calico/docker/network/v1.0/endpoint/54a450c3984853b3942738163cfaaa7dd247686ccc10b8f395dfb807df11e2bb/的所有數據就能找到對應的數據手工刪除

# etcdctl --endpoint 'http://192.168.75.200:2379' get /calico/docker/network/v1.0/endpoint/54a450c3984853b3942738163cfaaa7dd247686ccc10b8f395dfb807df11e2bb/5d9cad95e7193e47177eb6d8bdfa25ebc878d8565c48227861^Cf6700136a10c

{"anonymous":false,"disableResolution":false,"ep_iface":{"addr":"10.1.174.198/32","dstPrefix":"cali","mac":"ee:ee:ee:ee:ee:ee","routes":["169.254.1.1/32"],"srcName":"temp5d9cad95e71","v4PoolID":"CalicoPoolIPv4","v6PoolID":""},"exposed_ports":[],"generic":{"com.docker.network.endpoint.exposedports":[],"com.docker.network.portmap":[]},"id":"5d9cad95e7193e47177eb6d8bdfa25ebc878d8565c48227861f6f6700136a10c","locator":"","myAliases":null,"name":"testnet1","sandbox":"bc9abf7c29a9532500aeb9618b22254eab9e73aecc9d4b6c3bf488b6d173791e"}

2.node訪問其他node上的container不通

默認net1和net2的profile是允許tag相同的訪問endpoint,但是calico node默認無法訪問,需要修改profile

# calicoctl get profile net1 -o yaml > /etc/calico/profile_net1.yaml

# vi /etc/calico/profile_net1.yaml

- apiVersion: v1kind: profilemetadata:name: net1tags:- net1spec:egress:- action: allowdestination: {}source: {}ingress:- action: allowdestination: {}source:tag: net1
#下面是新加的rule- action: allowdestination: {}source:net: 192.168.75.0/24- action: allowdestination: {}source:net: 10.1.174.192/32- action: allowdestination: {}source:net: 10.1.166.128/32

# calicoctl create -f /etc/calico/profile_net1.yaml

Successfully created 1 'policy' resource(s)

10.1.174.192/32和10.1.166.128/32是docker1和docker2的tunl0的ip,手工配置這個還是比較繁瑣,應該寫成腳本做這個工作

再在集群中任意一臺node上ping另外一臺node上隨便一臺net1下的container都能ping通了

轉載于:https://my.oschina.net/u/1791060/blog/827084

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/541908.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/541908.shtml
英文地址,請注明出處:http://en.pswp.cn/news/541908.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

python批量雷達圖_python批量制作雷達圖

老板要畫雷達圖,但是數據好多組怎么辦?不能一個一個點excel去畫吧,那么可以利用python進行批量制作,得到樣式如下:首先制作一個演示的excel,評分為excel隨機數生成:1 INT((RAND()4)*10)/10加入標…

JavaScript中帶有示例的Math.log()方法

JavaScript | Math.log()方法 (JavaScript | Math.log() Method) Math.log() is a function in math library of JavaScript that is used to return the value of natural Log i.e. (base e) of the given number. It is also known as ln(x) in mathematical terms. Math.log…

SUI踩坑記錄

SUI踩坑記錄 最近做了個項目選型了SUI和vue做單頁應用。下面記錄一下踩坑經歷SUI 介紹 sui文檔:http://m.sui.taobao.org/SUI Mobile 是一套基于 Framework7 開發的UI庫。它非常輕量、精美,只需要引入我們的CDN文件就可以使用,并且能兼容到 i…

java 寫入xml文件_java讀寫xml文件

要讀的xml文件李華姓名>14年齡>學生>張三姓名>16年齡>學生>學生花名冊>package xml;import java.io.FileOutputStream;import java.io.OutputStreamWriter;import java.io.Writer;import java.util.Iterator;import java.util.Vector;import javax.xml.pa…

JavaScript中帶有示例的Math.max()方法

JavaScript | Math.max()方法 (JavaScript | Math.max() Method) Math.max() is a function in math library of JavaScript that is used to return the greatest value of all the passed values to the method. Math.max()是JavaScript數學庫中的函數,用于將所有…

java 修飾符默認_Java和C#默認訪問修飾符

C#中:針對下面幾種類型內部成員的訪問修飾符:enum的默認訪問修飾符:public。class的默認為private。interface默認為public。struct默認為private。其中:public可以被任意存取;protected只可以被本類和其繼承子類存取&…

JavaScript中帶有示例的Math.abs()方法

JavaScript | Math.abs()方法 (JavaScript | Math.abs() Method) Math operations in JavaScript are handled using functions of math library in JavaScript. In this tutorial on Math.abs() method, we will learn about the abs() method and its working with examples.…

人臉識別python face_recognize_python2.7使用face_recognition做人臉識別

偶然看到一篇文章,說是可以實時人臉識別,很有興趣就自己按照文章開始動手人臉識別,但是實現過程中遇到了幾個問題這里做個總結,希望可以幫助到大家安裝face_recognition這個之前需要先安裝編譯dlib,如果沒有安裝dlib&a…

c# reverse_清單 .Reverse()方法,以C#為例

c# reverseC&#xff03;List <T> .Reverse()方法 (C# List<T>.Reverse() Method) List<T>.Reverse() method is used to reverse the all list elements. List <T> .Reverse()方法用于反轉所有列表元素。 Syntax: 句法&#xff1a; void List<T&…

cpuinfo詳解

cat /proc/cpuinfo processor: 23&#xff1a;超線程技術的虛擬邏輯核第24個 ###一般看最后一個0...23 表示24線程 vendor_id: GenuineIntel&#xff1a;CPU制造商cpu family: 6&#xff1a;CPU產品系列代號model: 44&#xff1a;CPU屬于其系列中的哪一代號model name: Intel…

jvm延遲偏向_用于偏向硬幣翻轉模擬的Python程序

jvm延遲偏向Here, we will be simulating the occurrence coin face i.e. H - HEAD, T - TAIL. Simply we are going to use an inbuilt library called as random to call a random value from given set and thereby we can stimulate the occurrence value by storing the o…

java項目沒有bin_WebAPI項目似乎沒有將轉換后的web.config發布到bin文件夾?

我很擅長.NET配置轉換 . 我現在將它們放在用于數據使用的類庫和WPF應用程序上 .但是&#xff0c;當我嘗試使用ASP.NET WebAPI項目進行設置時&#xff0c;似乎發生了一些奇怪的事情 .配置文件永遠不會顯示在我的bin目錄中&#xff0c;因此web.config始終顯示為預先形成的配置文件…

opengl es的射線拾取

2019獨角獸企業重金招聘Python工程師標準>>> 在opengl中關于拾取有封裝好的選擇模式&#xff0c;名字棧&#xff0c;命中記錄&#xff0c;實現拾取的功能&#xff0c;相對容易一些。但是到了opengl es里面就比較倒霉了&#xff0c;因為opengl es是opengl的簡化版&am…

java timezone_Java TimeZone useDaylightTime()方法與示例

java timezoneTimeZone類useDaylightTime()方法 (TimeZone Class useDaylightTime() method) useDaylightTime() method is available in java.util package. useDaylightTime()方法在java.util包中可用。 useDaylightTime() method is used to check whether this time zone u…

視覺學習(4) —— 添加地址傳遞數據

Modbus Slave 選擇一個地址右鍵&#xff0c;選擇發送的數據類型 視覺軟件 一、添加地址 當地址為100時&#xff0c;先將首地址改為100&#xff0c;第0個地址為100&#xff0c;第1個地址為101&#xff0c;往后累加 若想使用100—150的地址&#xff0c;即首地址為100&#xff…

某個JAVA類斷點無效_解決eclipse中斷點調試不起作用的問題

最近幾天&#xff0c;遇到了一個問題&#xff0c;就是在eclipse中進行斷點調試程序到時候&#xff0c;跟蹤不到我設置的斷點。困惑了很久&#xff0c;在網上也查閱了很多資料&#xff0c;都沒能解決我的問題。今天早上&#xff0c;我試著把eclipse的工作空間重新換了一個&#…

jquery中阻止事件冒泡的方法

2019獨角獸企業重金招聘Python工程師標準>>> 根據《jquery基礎教程》 第一種方法&#xff1a;判斷事件的“直接”目標是否是自身&#xff0c;如果不是自身&#xff0c;不予處理 $(div.outter).click(function(event) {if (event.target this) {$(p).css(color, red…

java swing 組織機構_課內資源 - 基于Java Swing的小型社團成員管理系統

一、需求分析1.1 個人信息學號、姓名、性別、年級、系別、專業、出生日期、聯系方式、個性簽名、地址、照片。1.2 基本功能要求管理員信息管理登錄、注銷功能修改密碼功能部落成員信息管理添加成員刪除成員修改成員信息按條件查找篩選成員1.3 高級特性管理員權限管理成員信息包…

Java System類loadLibrary()方法與示例

系統類loadLibrary()方法 (System class loadLibrary() method) loadLibrary() method is available in java.lang package. loadLibrary()方法在java.lang包中可用。 loadLibrary() method is used to load the library with the given parameter named library_name(library …