|
|
楼主 |
发表于 2018-9-20 11:11:21
|
显示全部楼层
搭建私有库( R( ~' K- x+ q8 a2 J2 I7 |/ j
- [9 a# g7 _- b: a
私有库用于系统内部存储成品镜像,能够快速进行下载及被k8s调度。
2 B4 K m) x9 i1 ~5 k
' R$ L% [- r7 J0 \6 m$ s8 O9 B; v1.下载并启动私有库
* S) D+ w4 U9 ?5 l
! B1 h; t; n! ]. S A) r; K9 g& z[centos-master]:docker run --name registry -v /etc/localtime:/etc/localtime -v /opt/registry:/var/lib/registry -p 5000:5000 -itd docker.io/registry1 Z& w) k% X: U$ b7 ^
; h X/ \6 b1 `* v' o! S. J# A#--name 表示启动的容器后名称,此处为registry" l* j# [$ _1 v" |
#-v 表示挂载路径 格式为宿主机路径:容器内路径
+ X1 A; ~) I1 S( Z7 M, g( ^' g#-p 表示映射端口 格式为宿主机端口:容器内端口/ g3 L- {: e) e. v- A( ^3 }3 Y
#-itd docker的内部参数,此处声明后台运行容器并分配一个伪终端并绑定到容器的标准输入上,后跟镜像名称此处为docker.io/registry
" C* H% z) T: G, Q- T& _
5 R6 ~9 V4 }( u. p( \2.创建一个secret服务,用于k8s调度私有库容器时的“令牌”。简单来说,secret服务就是一个存储密码的服务
7 v9 w: U! z6 O* n9 Z$ m. N3 E) D1 B: H! g5 T0 b7 W; X
[centos-master]:kubectl create secret docker-registry registrykey --docker-server=registry.evehicle.cn --docker-username=docker --docker-password=docker --docker-email=lienhua@zhongchuangsanyou.com
4 L+ }5 a/ Y* i% }2 s/ r
! Z$ c: b+ z" R; t6 X[centos-master]:kubectl get secret
) z) w2 ^' H! Z# n- h$ {4 fNAME TYPE DATA AGE
2 E2 E) R; l+ \: k( A5 W) D$ e/ @" R/ {3 f7 Nregistrykey kubernetes.io/dockercfg 1 6s
8 n- D2 _& y6 d! [4 D+ C8 y/ B; u+ [& m9 \
此时登录时会提示认证错误
4 Z1 d- u2 V U3 S2 ^; l' @
) @- P) Q7 o1 z9 P7 T[centos-master]:docker login -u docker -p docker -e lienhua@zhongchuangsanyou.com registry.evehicle.cn0 ]: _9 F7 Q7 p8 v% g J& R4 V
Flag --email has been deprecated, will be removed in 1.13.+ p, {. [; ^& _" v5 u" C" n
Error response from daemon: login attempt to https://registry.evehicle.cn/v2/ failed with status: 401 Unauthorized
) v7 a1 a/ }0 h" S
% \) P6 f9 }0 J: t; T( k这是因为Docker官方是推荐采用Secure Registry的工作模式的,即transport采用tls。这样我们就需要为Registry配置tls所需的key和crt文件了! t( @: @6 o) o! K& ^! f' @
, U9 z G/ a' Z2 m8 P
3.配置nginx反向代理 % v7 Z1 Q9 ~9 p, L
[centos-master]: cat registry.evehicle.cn.conf& U% K6 S1 y1 E( T6 F# V5 X1 M9 n
0 L) k9 k5 u2 d4 [0 v; W
# For versions of nginx > 1.3.9 that include chunked transfer encoding support: Y! @$ P7 } m% f
# Replace with appropriate values where necessary
0 e ~) _7 Q5 t0 D" Q! l6 r- l. }1 [
upstream docker-registry {
/ v: d- J e, A9 I8 v server 192.168.121.9:5000;
9 n, F7 T( C& ~1 }2 m4 {+ s #server 10.44.170.95:5000;
5 _: F: ` h4 h6 n}
6 K! ?$ `3 `: \8 i/ L4 q- \, B4 v( }8 O6 ?$ i: w
# uncomment if you want a 301 redirect for users attempting to connect7 Y, F; W& J' } }' P4 X1 U
# on port 80$ d7 |1 v% ~ `! a4 s
# NOTE: docker client will still fail. This is just for convenience
& v* A! `7 P1 [+ M# server {# m% M- ^" Z) w: l& P
# listen *:80;* d z+ E0 t" l @, n
# server_name my.docker.registry.com;1 X, t# d8 w' l3 a" w( ^2 L( q4 V! }
# return 301 https://$server_name$request_uri;; |# p# s- `( T" L' l3 @$ C( q
# }& N; G z$ D+ r
: f/ j( } D+ {0 H
server {1 S8 |+ k+ Y: P; F, Y1 v4 J
listen 443;
5 v6 ^8 r) J T5 c* I0 x$ y server_name registry.evehicle.cn;. _ U' g$ k* s" }! ^
# T: v2 `' ~7 T ssl on;' q2 _$ R1 m' r( a9 ~+ R1 d
ssl_certificate ssl/registry.evehicle.cn.crt;! H( B" Z' W- g [% @ {4 c) K0 j# ]' B4 m
ssl_certificate_key ssl/registry.evehicle.cn.key;
# U5 }, b3 C: q$ C/ k5 C9 N0 F: b) O
. \/ k6 b0 T1 o0 P% V0 n/ J client_max_body_size 0; # disable any limits to avoid HTTP 413 for large image uploads
4 @; o5 Z' q. o9 Y1 N
7 }+ u3 l7 ?9 O. w& Q # required to avoid HTTP 411: see Issue #1486 (https://github.com/docker/docker/issues/1486)
! A6 G5 w5 y/ `* R& z' k5 K chunked_transfer_encoding on;
: Z; S. Z8 o: q& ^# @2 J
0 C/ z! a/ B+ w/ V5 I location / {' h" _, z0 j( @( V
auth_basic "Restricted";
2 Y4 D- v; t. W auth_basic_user_file passwd;
- T) t: {, e4 h/ t add_header 'Docker-Distribution-Api-Version' 'registry/2.0' always;, D U i# a3 F+ C5 R
+ d& v! F) G9 `; H( G9 Z. v
proxy_pass http://docker-registry;
/ d% A _3 d" d( @4 m1 j proxy_set_header Host $http_host; # required for docker client's sake
/ H0 W& i1 t" H proxy_set_header X-Real-IP $remote_addr; # pass on real client's IP
& ^/ ^1 m$ b/ b8 ` proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;3 i. ?* n; ~. E/ m; P/ x: ?
proxy_set_header X-Forwarded-Proto $scheme;
7 r3 [% Z2 t9 K# @ proxy_read_timeout 900;
' q3 @6 w+ O; p5 @$ d5 v }% y' I V% I+ l4 X. c
" l3 z$ ?: O8 p- Y& G# O+ Q$ n location /_ping {
6 V6 ?* d+ F: X. c3 ^) C auth_basic off;" Y4 U/ Q* e3 O E- J4 o% v
include docker-registry.conf;
8 C d5 s4 ~/ ]0 c5 t5 l: p }& S$ i! \7 q: y9 {6 K
0 q/ H4 Q+ V1 r0 Z+ O) P
location /v1/_ping {. ^6 f- X2 f- \4 V8 ]
auth_basic off;+ Q4 f0 ] J$ S0 d: G0 V
include docker-registry.conf;4 n- Z7 I- U* F' y
}
# |# f$ x$ d: J, @6 m: \" K7 ~4 S9 x5 B3 z
location /v2/_ping {, O5 U0 d! c0 S( B
auth_basic off;
# B; y- {3 m& h( G include docker-registry.conf;; M4 P( w: v' \6 ~" ^. [, d; u
}& \0 x+ s }, f# n8 C; @
}
, b* _1 x2 Z7 j$ V# Z7 m7 H3 L2 {
将key及crt证书文件放到../ssl目录下。使用htpasswd生成密码放于./上一级目录) p- _, l8 @) C" z y2 E
* T/ U) Q' }% o% a; \* n: I8 a( D htpasswd -bcm passwd docker docker
: X, p R! J( L% B/ m: w #-c:创建一个加密文件
) {( x/ V+ k- N7 J2 c2 d #-m:md5加密,默认可不填写6 t' C9 Z! W* U3 L. z9 z
#-b:表示用户名密码在命令行中一并输入,不用分别填写3 C2 w$ I# Q3 O8 d8 D
' O; m) g% j, }& l, x- u- X4.再次登录$ J9 A! F) u( H
1 C' F1 L# w$ @0 V( ]# f
[centos-master]:docker login -u docker -p docker -e lienhua@zhongchuangsanyou.com registry.evehicle.cn/ d3 u& M! K9 \
0 M+ i4 U) m% Q9 s5 d) g, MLogin Succeeded$ ]0 j' u; d. l9 p( b! j E+ a
表示成功,此时再pull\push既在私有库中进行
+ D4 z, I/ m) h/ n4 I, k6 Z/ }. i2 Z% r. i
构建服务6 M; l0 \5 Z% U5 y7 V, P3 w& T
6 r8 |8 ?% w* i/ l, \0 j) }9 Pdocker的本意是将代码包含在容器内制作成镜像形成“产品”。但出于公司的(频繁修改代码及服务器资源受限)的特殊性,我们将代码以“外挂”的形式运行在宿主机上。下面以部署官网(apache)服务为例:
, z6 P8 H g" x* q2 z( O8 u2 R4 N4 W* }1.从docker的公有库里下载centos7的原生镜像" ~- u) |& t7 Y6 I! V7 V" d
9 u' T$ A1 a; I# J7 e/ Y7 Z. a
[centos-master]:docker pull centos) W1 w& H) v' A0 v3 V4 Y: j& X
9 c; t! @6 q! @) B6 F0 ~7 QUsing default tag: latest1 D4 |2 \7 {; ^: A% Q, N
Trying to pull repository docker.io/library/centos ..., e) O$ N4 }/ v6 }
latest: Pulling from docker.io/library/centos+ w, |+ p' k$ l# F; J
d9aaf4d82f24: Downloading [> ] 540 kB/73.39 MB
$ d' z9 Q: ^7 V" Zd9aaf4d82f24: Pulling fs layer
6 z5 M# K7 V: {" _5 _Digest: sha256:eba772bac22c86d7d6e72421b4700c3f894ab6e35475a34014ff8de74c10872e* i/ Y) u, I% H/ v* ]
Status: Downloaded newer image for centos:latest3 C* o; o$ \+ _. O: a2 f
5 \! m8 F/ T8 O6 B3 E4 ]2.编写Dockerfile制造apache基础镜像
4 q/ l. N* R, |6 M: w
# H; I9 A5 z/ D, N######httpd####2 F) B6 @% G3 N! }; o
FROM centos
. s( i& A0 w8 C: s" D& {# L1 cMAINTAINER lienhua lienhua@zhongchuangsanyou.com
! ~, S5 m6 d' u2 B3 W3 ^RUN yum -y install epel-release* s0 W2 q u7 C& x7 U
RUN yum -y install httpd php php-mysql php-memcache* php-mbstring
7 h) \8 _* k2 z2 gADD httpd.conf /etc/httpd/conf/httpd.conf# S! l0 o. O0 W* D; T
# E( V8 `2 `6 I3 q
EXPOSE 80
S6 Q8 J: W( @3 ^, m) y2 M1 G. N' }3 I
CMD ["/usr/sbin/apachectl", "-D", "FOREGROUND"]
, O/ I2 v& q3 j$ m$ z
5 L0 C, f: p1 ~1 }8 R其中httpd.conf文件需要在当前目录下真实存在,此处其内容为8 K7 ~4 i& T+ a* x- m
% o' w# K! P2 Z) A7 J+ e" V
ServerRoot "/etc/httpd"
$ S, T3 S8 Q# K! Z2 j& ^/ z# P: lListen 80
' p( k C4 v6 _# h$ L6 MListen 8080
{' `( J* `0 ~5 s' FInclude conf.modules.d/*.conf
: _5 p3 H# K: l* U6 y7 c9 d6 LInclude zcsy/*.conf. y# |2 H- O! p3 c9 Q2 ^' A
User apache
, Z" h: o5 v3 P* ^) G. _+ iGroup apache
. g! e! b) F G5 p, X2 B3 sServerAdmin root@localhost. M3 i0 x" N$ J2 z7 c/ ]
<Directory />
6 B3 W* `$ z6 y0 u AllowOverride none
. v; W9 m! [/ j$ I Require all denied
9 S9 D% g- k0 v2 n4 n# e* x</Directory>& Y; t+ B8 C% Y$ `2 t
DocumentRoot "/var/www/html"
& l/ j4 q3 V3 j8 {" s0 Y3 U% k9 @<Directory "/var/www">
2 P2 V+ Q: N7 F" d8 o7 Y AllowOverride None
4 r2 v) L" P* B. i/ i" l- ^ Require all granted
* q& v8 X0 D* I- e- k$ Y! t</Directory>
U( F' r- X0 I2 Y) K0 c<Directory "/var/www/html">
" D$ q- E5 H: n9 c9 U% L. p Options Indexes FollowSymLinks+ K1 f4 Z9 u7 ~6 E
AllowOverride None* \) B- }; m% v* W0 ` w v
Require all granted- Q/ p9 n" L& C' D2 E
</Directory>
2 \' f0 n+ W" J+ _, j/ I3 ~2 j" O<IfModule dir_module>
6 s) a+ j" q& ]( S DirectoryIndex index.html
7 C( C3 s* u- Y* ]( \</IfModule>
% _' P0 e% U' E4 |0 m<Files ".ht*">1 d$ s9 Y" z* \" a1 m- o
Require all denied8 Q7 a* I* ]: b! |4 F$ r
</Files>9 X2 c9 V6 c' a8 } u0 ?
ErrorLog "logs/error_log"% N* i& e8 i6 t8 ~) H: I
LogLevel warn$ a- Z" y- H, P2 A+ Q0 k; Q6 G5 ]# C3 b
<IfModule log_config_module>
* n/ L8 H+ h! e: x LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined( q, o. K% P3 u- u6 m% }. ?+ @
LogFormat "%h %l %u %t \"%r\" %>s %b" common/ ^9 r4 z) }: \, t
<IfModule logio_module>
' G/ g$ A, f# a2 d& g' E2 @ LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio8 K2 F8 I" b" m/ R5 X3 I" }
</IfModule> p6 K; J2 H+ h7 F
CustomLog "logs/access_log" combined
3 G7 J8 b7 A: p3 G0 u0 N</IfModule>2 k1 o! Z" }+ J N
<IfModule alias_module>
3 r9 ^% d. a$ X, B+ r ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
: q; m: d) C' X V! i4 ]. N* f</IfModule>, `7 x2 V) P' S+ r; f. y
<Directory "/var/www/cgi-bin">5 j4 m$ Y# L8 U; b) H2 R5 w0 C
AllowOverride None" H% O* H" _8 i, \
Options None" [9 _: h# @: m. A+ _
Require all granted
9 ^1 ^* m5 f7 h( V* S! Y- A; r</Directory>. ]* P/ X) d+ W8 h0 g# f8 h
<IfModule mime_module>1 O2 s, E2 E+ K& D5 X
TypesConfig /etc/mime.types
0 o7 g/ K2 f% r8 | AddType application/x-compress .Z
$ Y& D# ?1 u! ?2 S) ~ AddType application/x-gzip .gz .tgz# a; d# w8 n; A! B4 @3 U/ c
AddType application/x-httpd-php .php) T1 A* a7 }0 U4 @6 s6 Z. N! g
AddType text/html .shtml8 k, c1 o- @% w1 N
AddOutputFilter INCLUDES .shtml
4 G, a5 j9 e/ A</IfModule>
: h: N' E; W" KAddDefaultCharset UTF-8
. b" N, G% o o U3 v; e5 |<IfModule mime_magic_module>
* ?: i& S# K0 e7 L MIMEMagicFile conf/magic
' }/ R" ?/ Z# J) q0 o</IfModule>
4 o3 }" [1 B( q O% c& W, DEnableSendfile off
- B( a/ X5 l" w/ m% fEnableMMAP off
: j' z5 h$ H7 m: D( |8 t. R1 R r0 WIncludeOptional conf.d/*.conf% }3 |% o& O* A4 M$ q
0 {) u' ^3 n3 K4 N3 C2 a: ^执行[centos-master]:docker build -t registry.evehicle.cn/httpd . 命令制作名为”registry.evehicle.cn/httpd”的镜像(注意此处的点必须要有,并且其意义代表当前目录下的Dockerfile文件)
) a4 z7 p( e7 E. z" |1 E& N6 S l' E9 {- |% O1 Q& I
3.将制作好的镜像上传到私有库
1 d- B" D4 [7 G+ }# N2 `2 i2 A! x+ h- z) x7 [, ~. a% d( P
docker push registry.evehicle.cn/httpd
7 V3 d K" M5 n) x6 a- v5 y0 Z; i* |5 D4 e" b9 I! j
4.编写启动apache服务的yaml文件% c+ e( T: g( q; |
& z& \/ G4 P. w! h" ~9 U; i: u[centos-master]:cat 13-rc-httpd.yaml
& E p3 x; v( \! d- s3 q% P D6 m
v& D* Q* S9 J3 R1 S& ~. `apiVersion: v1; X& j0 U$ ], h5 f0 }4 F: t7 z
kind: ReplicationController1 f, ]9 y5 I* G# W9 l
metadata:
5 n4 d' p7 x; I% h0 I2 _7 @ name: 13-rc-httpd; _3 j6 y0 u. \
labels:& L! f# i" B% k) @5 e
name: 13-rc-httpd' V) B# Y. n& S: F- x4 f0 o2 I
spec:
& a1 l0 O; v/ @' p1 I; \) s replicas: 24 y! C( B( M9 p" {4 L4 f% S. u$ u8 i
selector:
; ` E1 g O; [! J) e% A name: 13-rc-httpd/ c( N' S) _) |$ J4 A) p8 C9 Y
template:# \. b" \ ?* L# a; A1 F
metadata:. ]" w( a4 j! u! Z1 V8 O
labels:
! i$ O" \/ t2 q3 C7 a% ^" Z1 S name: 13-rc-httpd# y7 t4 O* | _, V# C6 ?: e
spec:3 P1 ]; O3 L% }0 @1 q$ f! N
containers:. ~3 r) s- D( q }# ?0 |8 D
- name: 13-rc-httpd( R+ _( w* ?7 j$ R$ o- k
image: registry.evehicle.cn/httpd
; g7 r" y, O8 z" O env:* A3 J2 w$ s9 ~6 o6 ?7 m: ~4 s4 f
- name: LANG* Y' Z7 B$ s& }$ b6 O
value: en_US.UTF-8
8 t1 ?' ~- a2 Q z ports:, |$ p; k2 F" y* I! c$ H
- containerPort: 80
. Y1 `$ A$ L+ y7 _2 a8 K; @ hostPort: 80
9 [, o! C N% R }. Z9 h volumeMounts:, ]" R* v5 R' I2 d8 [& t) z
- name: time f) I& L) K# K5 z- f, Y
mountPath: /etc/localtime. w" K( x( x) K' Y' T
- name: zcsy$ T2 U6 }5 h4 \6 w
mountPath: /etc/httpd/zcsy; H/ }0 x3 _5 `. a$ X
- name: deploy
; p) J$ {) o& X: P mountPath: /docker/httpd/deploy- c9 s- C ]2 k- l8 M
- name: log
) t8 D% ~8 S: M2 _4 B* H mountPath: /var/log/httpd
$ J1 l, R/ J' o volumes:; _ r) d' r: d: C
- name: time
" L5 a* t4 w- g6 p hostPath:6 t b( q: a( j; V: Q$ b% E3 W# O
path: /etc/localtime- C1 b! _& q& J" z. g2 c! P' o
- name: zcsy2 S, n( S6 {% X2 W7 t/ q, {. P
hostPath:
9 ]8 n6 ]2 I- @$ r, f5 H& |" ` path: /docker/httpd/zcsy! _0 h. k. i) n7 n; _- _" T" \
- name: deploy$ ~/ ~6 ]( e5 S" ~% D
hostPath:
, Q( z' M4 p6 I% T path: /docker/httpd/deploy+ @8 `, p0 r" [
- name: log
5 T' A, B4 P' p( y `3 j# c! }! l hostPath:
* s+ J0 R9 T3 n4 f path: /docker/httpd/log
( @7 q$ a8 i7 {! G nodeSelector:
5 D: j5 d3 I; F slave: "13"; s6 e) ~7 `( @2 T8 H; ~
imagePullSecrets:
% ?; k$ S" ]0 ~1 `8 ` - name: registrykey
0 }/ f! M5 V4 b: q4 D# }! m- f2 ^6 X& Q8 K" N% D
5.给其中一个node加上标签为“13”
2 \/ p5 M1 u" \, [# g X1 F7 T$ Z% x
kubectl label nodes centos-minion-1 slave=13# z$ V4 I `6 H( G/ j
' }6 q# B) |( H. Q) @6 z6.此时拥有标签“13”的nodes应具备的条件
8 ~0 p0 Y4 [, a5 x$ ]/ l1 p
7 w# D0 m5 u! @+ G; g/docker/httpd/zcsy下需要有官网的配置文件
6 \4 D4 Z; M8 j/ T: ?$ D# n/ z7 c; S4 Z/ @& U h
<VirtualHost *:80>, `* C/ Z4 B* @& T: P: c
ServerName www.evehicle.cn7 \" k- {! j0 T3 H$ l! Q) \
DocumentRoot /var/deploy/wordpress/
5 R5 j: v% D4 \ RewriteEngine on1 U1 b8 x1 O0 v. q) R; L0 \
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
3 ^2 L0 D# O9 ?' c+ [1 k RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
) P& }) ?& x- {. V RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !^.*\.(ico|pdf|flv|jpe?g|js|gif|png|html|shtml|zip|xml|gz|rar|swf|txt|apk|bmp|css|m4a|ogg|mp3|ipa|plist)$
; G+ E+ n7 @# _) ? RewriteCond %{REQUEST_URI} !^/server-status$" i7 E h5 s c: x5 N$ s2 G) u
RewriteRule . /index.php [QSA,PT,L]
, x3 {2 c. w' ~9 j- A0 P: e" _$ Z3 W0 D2 B$ j5 D# m" k
</VirtualHost>% Y3 {5 m: m- ^- p4 q5 q1 x2 K
<Directory /var/deploy/wordpress/>3 l( }6 _) Z; J$ }/ W6 E7 p( m
Options FollowSymLinks
, ?* g6 Y k" \: q; c AllowOverride All
- k7 [# v( e" X Require all granted) m& Z: T. o& U; J L* ?
</Directory>3 K# h/ l* ^, n" |2 |! n+ `* d
" x: _* z' w4 N w9 H/ I& D
以及/docker/httpd/deploy下需要有官网的代码
% R- [! |! X: Q `) S4 s5 w( y- e' ~9 S
7.运行yaml文件启动容器
6 D3 D s2 U* |. j$ \$ v
6 R. d- e- R* x F. p& |7 J/ z[centos-master]: kuberctl create -f 13-rc-httpd.yaml, m( D+ h6 M+ s! {9 ?% J e( d
6 N# S2 Q0 s7 r5 N' F+ S
8.查看服务
, X$ o! C5 ^9 _% r& K3 ^0 u
3 s1 E% V# g" S1 d' z[centos-master]: kuberctl get rc
& a) e- G+ i/ x0 ]: ^7 M& T I" f4 p- H" d
NAME DESIRED CURRENT AGE
0 p9 O3 b2 c3 |, `/ t! ~13-rc-httpd 2 2 168d
- m& p& H1 C$ a+ b5 L3 i$ A) w- Z, K* ]4 B
9.程序中涉及的mysql\redis\memcache等服务也需使用容器运行起来9 X a/ b p) |+ r5 q1 P2 W$ J
# u# _7 k _! ~. |7 Q; a/ f
[centos-master]: docker pull redis + j3 I' w) R @; \9 }' M
[centos-master]: docker tag registry.evehicle.cn/redis redis " f# I6 |+ `8 c0 N5 d
[centos-master]: docker push registry.evehicle.cn/redis ) _3 S2 l: |3 h' s+ |( g
[centos-master]: kubectl create -f rc-redis.yaml ' u3 {+ f4 m% `2 V
[centos-master]: cat rc-redis.yaml$ P$ X' n( m0 X8 n# E8 a0 I2 Y
/ l5 \2 B+ E: W5 L+ s
apiVersion: v1
* D0 M; o' D1 u) ^kind: ReplicationController j# X3 d5 E( v. h) k" ]
metadata:. P9 ^( K6 V% i: j+ w
name: redis
) |6 E' n+ a' |# S: Q8 M- S labels:4 F: u4 K( M( \& z3 `2 j
name: redis l' j$ p" w: W
spec:4 i, u8 ]' Y% X
replicas: 25 V% L: Y0 Y$ O5 s+ ` F1 d* w
selector:1 f$ ^" k9 D( A
name: redis; Y5 R+ R; k+ E9 e; j u
template:
4 ]2 s$ t: R6 I3 A3 C1 R# X metadata:7 W' c9 u9 } R5 z5 Y9 d* I
labels:
# R$ d5 Y+ O" W* R+ P% ~, h" s. o# p name: redis
2 M( P/ t2 E8 C2 d. l spec:( q6 [- Y& f5 R/ H) v
containers:0 @6 J2 \. R9 S4 ^
- name: redis/ A: y# h# R+ h' i @
image: registry.evehicle.cn/redis* U6 I5 ^6 h% O
ports:
0 D: \0 |2 L5 A3 T% z1 G - containerPort: 6379
' k0 L6 T2 B# \/ ^% f hostPort: 6379
) q/ y3 r" \0 {: j; y volumeMounts:
/ ?+ V7 g w" @/ _ - name: data' Z- R$ l. |9 w, Z
mountPath: /data j& |4 h; b9 n1 a0 i4 `
- name: time" d6 P% M+ _+ l
mountPath: /etc/localtime
/ y' M" D1 `& D; d" v( _ volumes:
: ~9 C5 J( ^* h; ^2 h7 v7 | - name: data, R) @9 t* b* y, C6 n+ g
hostPath:7 F6 F% a0 U; M8 e
path: /docker/redis/6379
O! p$ G9 \' o( A2 R. t - name: time
+ b- _! j# N+ g5 h+ Y% F hostPath:& p2 P2 R2 Z4 Z* r; e) _
path: /etc/localtime
" m; n, p. X8 u/ V: a5 } nodeSelector:$ O& m3 r; I9 ~' c9 g2 p- @
slave: "13"+ V( @9 l5 v5 _
imagePullSecrets:2 V" n* I/ `: N0 ?/ F
- name: registrykey
2 `- n2 `0 A. @* X# f& [( S; s' j( ~2 s1 R9 t
启动memcache ' H/ H( _7 u) d. x4 X
[centos-master]: docker pull memcache
4 S6 }' h0 K. [9 \! s, n[centos-master]: docker tag registry.evehicle.cn/memcached memcache ; t( D2 c/ \" X0 \- f( N
[centos-master]: docker push registry.evehicle.cn/memcached
* Q9 B5 L0 `: D9 W9 @[centos-master]: kubectl create -f rc-memcached.yaml / H% d, ~1 \8 |# Z/ U
[centos-master]: cat rc-memcached.yaml5 G& U! b! r P. `: B
! F; g; T& ^ i" T/ X7 o9 Q
apiVersion: v1
/ ^2 W! D" _/ Q+ g- kkind: ReplicationController+ j7 \( m- H- x5 u3 x: V
metadata:& L# ~+ w% I' i$ k/ Q0 U
name: memcached
: i: @2 b2 M3 ~ labels:6 D$ L# L& G. s# w3 x# `
name: memcached
: v: s4 B: d4 F( pspec:
8 K( S. e! S9 a3 P replicas: 3
* L/ J% _$ |" A9 m' ?! [. z selector:
7 z3 f# K2 v) m; I name: memcached
, [. H$ x; f* [, G- @: c" \ template:9 B% u: H3 W$ r& L
metadata:5 C6 M/ \3 Y9 r5 I
labels:+ @5 y% Z- D% r+ O/ P+ X
name: memcached
: |; Z" L$ Y- m, o. g spec:
+ f2 [0 k, A; v# Y+ i containers:- L# D% i( S' g
- name: memcached
" i, l0 B" M/ e4 s# \9 {6 D, i image: registry.evehicle.cn/memcached& \1 _( Y, K: ~/ Q! x
ports:6 \% @+ J J7 Q2 C' Y
- containerPort: 11211 z! y& e- I; D" b- I/ C4 D
hostPort: 112111 `6 H3 _1 V6 H, N3 U; f7 p; L
#nodeSelector:4 ]1 q7 ^7 V$ {9 G1 r
# slave: "13"* O% n; ^7 b6 Z6 B" C: H
imagePullSecrets:; h; M$ R8 a; T x
- name: registrykey
% F& |* S/ x$ ^& ?1 ^! H9 m3 t& i, O* \+ |. C; N( ~3 u; G
制造mysql镜像 6 U; b7 d1 l$ F
[centos-master]: cat Dockerfile# B# W9 j7 e' r1 V* F/ j
) Z5 ~* e8 j5 ^9 ]FROM alpine
; x/ S* L; x5 V1 z
: ] W3 p* y6 t* M. ]% R& Q m6 h2 S* Z$ Q& F
COPY startup.sh /startup.sh
$ h" t. _' e2 Y2 pRUN addgroup mysql && \) H: }" ~ e& X
adduser -H -D -s /bin/false -G mysql mysql && \# M) \/ S0 v; K) C2 _5 Q
apk add --update mysql mysql-client && rm -f /var/cache/apk/* && \
2 a# H/ Z5 R) J" t* A mkdir /data && \. Q/ o. [( | x0 x
chown -R mysql:mysql /data /etc/mysql && \9 e4 n. n0 W7 D1 w, g9 x# h
chmod 755 /startup.sh \. q+ M! q/ z1 d& A- L: i, B9 t
;
7 T- e2 N- c/ J8 x6 F4 L- H- N, \# ?
5 N4 v; m9 N4 |1 NWORKDIR /data
# L5 n% f( B# v+ i8 K/ ~2 {VOLUME /data& f! i: N. s' Q& g$ @ E- a/ Y6 S
VOLUME /etc/mysql
6 z7 @7 B4 o' X$ {/ V9 W2 @
9 n+ o8 @" }* E+ b$ x r; X
: D1 X' |4 Z Y. z$ W/ `EXPOSE 3306
% f% ?' W' [+ N3 Z% qCMD ["/startup.sh"]
" d$ M$ J0 t0 |1 V9 F/ K, K7 G& j* u" i" _8 Y6 V
启动mysql(建议mysql在宿主机启动)
* [+ q/ \" o8 Z. I4 h' N7 Z[centos-master]: docker build -t registry.evehicle.cn/mysql $ z1 a0 x2 X3 b U0 G8 [; c
[centos-master]: docker push registry.evehicle.cn/mysql , P9 d7 }; M3 f: i9 f& D1 q" O
[centos-master]: kubectl create -f rc-mysql.yaml
$ @: B( e# t2 a, F, S: X8 v h[centos-master]: cat rc-mysql.yaml; ]; ^' Z2 s" M* i
1 m$ y9 M1 h! ], e3 c; Z
apiVersion: v14 [0 ?5 T! ^7 H. S
kind: ReplicationController
# ?/ [$ p6 q0 M7 Ymetadata:& a7 R ]% L. k8 @
name: 13-rc-mysql
( b8 o1 q2 j2 `6 e2 R labels:
$ A4 s/ Q/ R- l: Q2 ], v0 x name: 13-rc-mysql
+ O5 {* b- C& M$ sspec:
. ?! y* b# R0 V: t& ^1 c replicas: 2
6 U# `3 A+ P3 \! C1 m2 V selector:4 U9 V7 L7 N1 }7 r/ Y$ |
name: 13-rc-mysql
; |" ~: d8 }3 P8 V4 | template:
0 ^ B% L1 _$ S. K& x( o metadata:, M0 y" X* y6 `; l% l! T0 ?3 z
labels:
7 l' ?( n" K/ N3 N name: 13-rc-mysql
2 n* C' l* o7 g. K- I0 K spec:/ s8 [! x7 ^8 N- v
containers:
4 M& Z: {" G5 M/ ~ - name: 13-rc-mysql6 T$ G" f# _* X7 t7 q; Q
image: registry.evehicle.cn/mysql
$ x! D$ { q) x8 I/ D5 o env:8 }2 R: j2 l" ] o
- name: MYSQL_DATABASE1 l6 B$ {; [3 `: L# j
value: admin
1 d" x* r( d# `: E4 ~ - name: MYSQL_USER
% s \/ k! T3 g; \ value: tony0 X! `8 d1 a) I1 Y G
- name: MYSQL_PASSWORD
5 N }; \* V1 v value: 456
8 G$ v6 M7 i: w7 v) K J ^( D - name: MYSQL_ROOT_PASSWORD' u% _! E. c6 A! w4 L# Y
value: 123- p+ Y" }% {: D9 z) _1 |
ports:* _* p `, z$ B7 `
- containerPort: 33067 D2 G, @+ f w2 _/ a8 p% z
hostPort: 3306( u3 x4 N& v2 H( R
volumeMounts:! q7 O5 g, C6 X; f1 Z
- name: time' n$ ^) E' ]. R3 U$ @; K' |* O! Q
mountPath: /etc/localtime
9 |3 t9 l Z% n0 [ - name: data
6 ]. _3 e- I- I0 G# ^4 M; q: t mountPath: /data
: i8 s( C7 T @3 d9 c, Z - name: etc5 g1 K" i* i1 e/ i3 j/ `7 c- d
mountPath: /etc/mysql* G4 a* t; |3 o9 R% h( U
- name: run
9 f3 s8 I7 O- R B+ @6 J) o9 p mountPath: /run/mysqld( @5 U# J# q1 S( ]" I
volumes:
/ E( ~$ x3 h; K - name: time& I" M% t3 a/ e& [# Y
hostPath:& A# [# t- T$ d5 R' F
path: /etc/localtime
. A$ L. r% l6 ?! I3 W - name: data. Q* G% `1 j9 u$ G7 \6 }
hostPath:
' c6 c* _* q2 s- x0 Z" W path: /docker/mysql/data
1 b8 X" u& w* t$ H; H2 S% ^8 Y5 K- }% V - name: etc2 N1 U3 h& ]/ c* I2 E' L
hostPath:
4 x i, w% _9 P; C path: /docker/mysql/etc
( u0 J" k$ H0 w1 d. l/ a. p - name: run+ ~6 M% f3 U b) c I
hostPath:8 T! O# M( L& n8 J2 D3 y
path: /docker/mysql/run) v _! _, Q5 w
nodeSelector:; J; F, E7 V1 N8 D. D( ` C* N
slave: "13"3 b" q' s: e; }, e" b* Q
imagePullSecrets:
. V X6 x) H0 Q1 W1 ~ - name: registrykey
f2 H8 T/ K. q9 ~8 y7 ~: o0 X; y1 P2 B/ J1 Y$ g R
为方便代码编写及统一管理,应提前做好内部DNS解析。将所负责的应用规整到对应的机器上。 |
|