|
|
楼主 |
发表于 2018-9-20 11:11:21
|
显示全部楼层
搭建私有库$ d: B6 C Z+ F' i9 m6 K* C6 f
6 `) q* r4 ~3 i, k, W1 c4 |& c
私有库用于系统内部存储成品镜像,能够快速进行下载及被k8s调度。! S" Z/ G+ ~% P% B( K
; M/ z$ M. r0 a! @
1.下载并启动私有库
7 B9 t, o& b ]7 i! S
' z& O* Z- i7 w+ G3 d8 U[centos-master]:docker run --name registry -v /etc/localtime:/etc/localtime -v /opt/registry:/var/lib/registry -p 5000:5000 -itd docker.io/registry
0 ^* O' V K- F6 G. v! V
8 {; k# Y: Z& ]- D. a) o5 D* E#--name 表示启动的容器后名称,此处为registry# V% L) C9 ?: B' ]
#-v 表示挂载路径 格式为宿主机路径:容器内路径. K- {( P* m7 Q
#-p 表示映射端口 格式为宿主机端口:容器内端口
* f1 p$ c1 ^2 l7 P E#-itd docker的内部参数,此处声明后台运行容器并分配一个伪终端并绑定到容器的标准输入上,后跟镜像名称此处为docker.io/registry! t6 o. n9 p4 W/ }4 t
8 U' W A/ ~ I2.创建一个secret服务,用于k8s调度私有库容器时的“令牌”。简单来说,secret服务就是一个存储密码的服务
# r6 g0 V- e0 C3 h# M5 h+ C6 H. I" V' M* b. ]# c# w! D
[centos-master]:kubectl create secret docker-registry registrykey --docker-server=registry.evehicle.cn --docker-username=docker --docker-password=docker --docker-email=lienhua@zhongchuangsanyou.com. O# j# z5 k2 \% [% ?. Z7 Y
: I3 U s0 U- z7 B' a% B3 ^% O% a1 U
[centos-master]:kubectl get secret/ C3 b' }5 q5 l0 g( F; T3 `
NAME TYPE DATA AGE
( h! {5 ^4 J4 V- xregistrykey kubernetes.io/dockercfg 1 6s' n- ?& e% m& A/ b0 s& P. N: r4 j
7 o$ q+ a) P% g% r8 a" z9 R此时登录时会提示认证错误$ o+ j1 Y# l& T% }6 x. N4 i* G
& u. N2 |5 q7 n# ][centos-master]:docker login -u docker -p docker -e lienhua@zhongchuangsanyou.com registry.evehicle.cn, r5 c+ X6 X3 y* @7 ]1 y; p
Flag --email has been deprecated, will be removed in 1.13., }1 b/ M* O3 k) R6 V. f* v
Error response from daemon: login attempt to https://registry.evehicle.cn/v2/ failed with status: 401 Unauthorized
+ n2 t& P% l6 _% F- h5 K
2 J6 n$ U; y/ S" Z8 M( L# t这是因为Docker官方是推荐采用Secure Registry的工作模式的,即transport采用tls。这样我们就需要为Registry配置tls所需的key和crt文件了4 ]9 S1 d+ M' L5 J2 F
3 I( [0 ]' L9 Y3 Q% P- b7 B( y" C- S3.配置nginx反向代理 - t% Z4 j0 f5 R+ K- h2 y1 c
[centos-master]: cat registry.evehicle.cn.conf
: C# ]- U, H* A4 s
# M! T" X+ b! y# For versions of nginx > 1.3.9 that include chunked transfer encoding support8 ?4 _$ ?, M6 m$ L) u v1 f# M- l
# Replace with appropriate values where necessary3 f( ?/ q& U4 {/ G( l# e4 i
1 }& x2 |$ P }7 u8 K P
upstream docker-registry {
) H6 R& l- d6 q! N% Q- Q9 d: ^' E. U server 192.168.121.9:5000;* ^; y! V8 p/ v5 m$ ?5 k
#server 10.44.170.95:5000;
* u* K" B9 K8 L}1 @6 N% k# h4 I; k
) E% }( D+ c% o2 R% ~' A% Q- o( O
# uncomment if you want a 301 redirect for users attempting to connect0 n m# Q6 G: r
# on port 80
3 B1 m4 F$ t0 U, b5 d# NOTE: docker client will still fail. This is just for convenience2 v6 M. E5 J5 d/ ?0 Y/ h
# server {
4 P+ B6 Z: H& \. E' C) B( y2 R# listen *:80;# N; x3 m) a0 O# S b
# server_name my.docker.registry.com;
4 ]0 I& b l) h$ }( w$ @# return 301 https://$server_name$request_uri;: y4 p5 E8 `9 {# `
# }( a V9 @! T% {3 U
& a+ y6 t& P- u( Kserver {1 I6 V; H% T o
listen 443;' h- h4 T" Y* k* K; |; U
server_name registry.evehicle.cn;: N1 w4 Y' h* D
9 `- c- l& c& C1 b
ssl on;
' x$ T8 ~3 Y& g4 k" x" n/ U ssl_certificate ssl/registry.evehicle.cn.crt;% p! f# v# |- }
ssl_certificate_key ssl/registry.evehicle.cn.key;
1 |, S- s/ m2 _3 t6 Z# I! _8 f' j: r. l O1 l
client_max_body_size 0; # disable any limits to avoid HTTP 413 for large image uploads
! V/ w# G; q9 m# u. Y A" _
; u$ ~0 w0 Y+ X1 s # required to avoid HTTP 411: see Issue #1486 (https://github.com/docker/docker/issues/1486)
: n9 b7 H4 w# g$ J; R chunked_transfer_encoding on;1 D& f% P% n" ~2 h1 m' q( c# ~3 l5 ]
$ P! M0 P/ _0 h( @9 J" {% c
location / { Q* d9 R3 q' {( Z5 e! Z" N
auth_basic "Restricted"; g# @4 r* l5 y8 }, O
auth_basic_user_file passwd;8 F5 m' [. s2 S& F7 Z* U
add_header 'Docker-Distribution-Api-Version' 'registry/2.0' always;) x m9 l; ~6 B( x! ^
+ N' m3 |! M4 Q
proxy_pass http://docker-registry;
8 o+ k Q: ~/ O9 R7 I! o proxy_set_header Host $http_host; # required for docker client's sake( N8 `9 w) a d; u$ s w0 s
proxy_set_header X-Real-IP $remote_addr; # pass on real client's IP
* ], @+ H0 }: R3 m( o proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
8 W7 ]$ e( x, C+ R: y2 C0 @( ] proxy_set_header X-Forwarded-Proto $scheme;
' c& L" S2 i3 _6 a- t! ? proxy_read_timeout 900;1 z: A4 e& v& @/ x
}" c4 _4 c: A$ Q
6 B: r' I' b# U/ T& } location /_ping {* P$ f, E8 ^+ r3 a, p# q) t: M
auth_basic off;
3 i% f2 _; ^! U' } include docker-registry.conf;' s8 d( Q; p/ D3 l7 O
}
- y& g! R! _. ?) J* @' j# U. \) p$ p; S( @6 l! o# P
location /v1/_ping {
2 J/ n% u \. M$ m6 N+ @ auth_basic off;) d; x/ V5 r* D/ C
include docker-registry.conf;* x( c+ c4 r, h c. J. h% Z
}
& I$ B% |7 z* L N& o) ~. G) b, b' M' B4 }
location /v2/_ping {; w7 h1 ~% M8 y- Y+ @3 Z8 S
auth_basic off;0 l0 m! C% U% m) ?8 [0 A( g! [
include docker-registry.conf;
- e! R3 ]" p- x& B }- E+ }$ _. [' k# j; A
}$ U/ L( _# g Z. i
" x9 s E7 ?9 a: [" [. |/ x
将key及crt证书文件放到../ssl目录下。使用htpasswd生成密码放于./上一级目录7 N" A" E- d+ [3 h* J
! s9 C X( h8 g. f
htpasswd -bcm passwd docker docker
" I. X' f' W7 g, G W' u #-c:创建一个加密文件
; c1 j K, _! b) A; B7 O7 N #-m:md5加密,默认可不填写
8 U9 y9 C$ M& R# ?1 q- r; B; i #-b:表示用户名密码在命令行中一并输入,不用分别填写
1 R6 `/ B+ r' d8 a& h- x8 q6 c R& y
4.再次登录
% F$ j6 d& @4 n2 k; a7 q
& Q+ ?+ y8 |0 m4 h3 n2 X$ {[centos-master]:docker login -u docker -p docker -e lienhua@zhongchuangsanyou.com registry.evehicle.cn
5 W/ w- M, M P4 K9 S1 A3 l. j5 L% C$ m- z
Login Succeeded9 B) D* x9 w" N
表示成功,此时再pull\push既在私有库中进行4 o7 r$ [& N/ \5 |" T& @8 a
% V5 c5 U8 i# d( U: z# T构建服务2 l/ k" D- H' {' r, ?" P4 M6 U$ b, p4 _
# U6 M: @( ` p& j8 b5 g2 J
docker的本意是将代码包含在容器内制作成镜像形成“产品”。但出于公司的(频繁修改代码及服务器资源受限)的特殊性,我们将代码以“外挂”的形式运行在宿主机上。下面以部署官网(apache)服务为例: 1 U2 d# X# g) N0 S$ U" j; r5 P
1.从docker的公有库里下载centos7的原生镜像
: l0 R0 o0 k9 [- N+ o
7 a5 r0 A5 Y/ a, A3 M) N[centos-master]:docker pull centos
5 N2 _/ _# r1 A; h/ u+ Q. N
' E T, _- B- \0 `7 z3 ], sUsing default tag: latest
: L& u/ A" ^2 \Trying to pull repository docker.io/library/centos ...
" N n; F* w. e# V% _' flatest: Pulling from docker.io/library/centos6 r% l% S# ^0 }5 d. P# V8 L( x. J
d9aaf4d82f24: Downloading [> ] 540 kB/73.39 MB
) R6 U2 S0 X- h! A ^d9aaf4d82f24: Pulling fs layer
* A5 F: B( O4 H6 J8 CDigest: sha256:eba772bac22c86d7d6e72421b4700c3f894ab6e35475a34014ff8de74c10872e
+ X7 d; d' x3 zStatus: Downloaded newer image for centos:latest+ r; U( t/ G# Q
' {! S* M% }8 o k: `% X! I2.编写Dockerfile制造apache基础镜像3 l: ` X8 C' q! ^4 R
: z) z. ^, F) n% ~
######httpd####6 D$ u! U+ O( |0 ~, D
FROM centos1 a% F6 r" }, ]0 o- ~5 S- l
MAINTAINER lienhua lienhua@zhongchuangsanyou.com- m. f! w5 Q6 o9 t
RUN yum -y install epel-release
& r9 m( M3 ~, B; i' ]( zRUN yum -y install httpd php php-mysql php-memcache* php-mbstring4 Z# h3 X1 u% ~9 J0 F2 U- @. j# D% i
ADD httpd.conf /etc/httpd/conf/httpd.conf$ s G8 e. h; D. F
0 b1 m. @" H) l7 G" `5 f( x
EXPOSE 80
% y% l* \7 ~$ ~7 C }. Y6 k" l* [& U8 [5 l
CMD ["/usr/sbin/apachectl", "-D", "FOREGROUND"]! G7 x. ]: t5 h+ O# |8 q
7 T- C& f6 H a# w5 z
其中httpd.conf文件需要在当前目录下真实存在,此处其内容为# h* d: m; e3 W9 P! o% |
. e5 @2 L8 H% F/ @) U& {ServerRoot "/etc/httpd"
3 u% i. u, t+ V% ZListen 801 m+ h' y9 k7 L" y) n
Listen 8080 A' v6 i e4 v# P+ g3 a& K
Include conf.modules.d/*.conf, |8 s X3 O) o/ l
Include zcsy/*.conf9 E' m: e3 `. I) n9 @
User apache
: |# ^- r& E5 r; S& ?0 p3 GGroup apache# G- D3 `% o# Z& e D- ?
ServerAdmin root@localhost( }& M* D. Y) d/ Z O! M
<Directory />
; t8 z8 v: N: P" O& H AllowOverride none; a2 g4 J- q9 F; B( d4 V# h$ o( ^. v
Require all denied: G6 ]5 g, K7 s; ?2 s
</Directory>
" b: c! N% Z9 `- z, L2 t/ qDocumentRoot "/var/www/html"" C! _" O7 p' O# G* F8 E
<Directory "/var/www">6 V3 s8 A( G N/ v
AllowOverride None
9 s7 v+ }" I$ y! }3 g' I0 `& j* u9 r Require all granted% q3 l& B+ @2 P4 h* W" K# b
</Directory>& A' G! S2 \/ E5 d2 q
<Directory "/var/www/html">
& B2 s' \$ s5 |2 e; b/ D2 u, q Options Indexes FollowSymLinks1 ]' R: @; Q) j: E- k7 y9 j
AllowOverride None5 r; N' h& r. f1 o3 T' o. |
Require all granted
: C+ n, }5 M) J+ K</Directory>
5 n& E6 U; o* `% b8 e<IfModule dir_module>: R4 K- B, f6 Y2 G! f
DirectoryIndex index.html# g2 g- z! c5 k( A; E% W7 P0 E
</IfModule>6 b2 y) ]5 w7 G0 a- {3 b- ~
<Files ".ht*">; D( _5 O+ K) I# o( Q% p
Require all denied% W4 }3 P9 e1 ~0 f4 p8 n
</Files>. G8 X3 a7 H5 c8 T! \1 l& l6 s
ErrorLog "logs/error_log"; @" w& X" D, v: t0 D: @1 H
LogLevel warn; s& v2 N- s3 F/ {
<IfModule log_config_module>
5 X- h- o$ L% K! A' I+ B; a LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined6 t& D4 X+ a1 k, I% `
LogFormat "%h %l %u %t \"%r\" %>s %b" common) t' r7 C. P9 j1 Y d6 F# B0 w
<IfModule logio_module>
, F4 U4 s( Y( _& s9 p/ t LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio4 L/ B5 {2 N1 |. G
</IfModule>
' T7 r+ l8 e# E& }0 J CustomLog "logs/access_log" combined
1 @ Q0 M+ f& C6 M- y7 y; i$ h</IfModule>
+ |* _% N% k& u) x<IfModule alias_module>2 d/ B, ?& X" }0 R9 _4 m1 Q
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
3 H7 |9 l, t0 \) }</IfModule>2 }" O( }4 ?/ V( l' d
<Directory "/var/www/cgi-bin">: _' T1 G! c1 t* r5 g
AllowOverride None# f( |0 Z# T/ L" O/ ^* H) h
Options None, @, E" X7 |" |" ]
Require all granted0 x9 S# d0 d: w: F Y, K; h% |
</Directory>6 d: s2 _+ Q& g
<IfModule mime_module>5 [/ g0 e5 v. K
TypesConfig /etc/mime.types3 y6 h Y# p& \' U' h! ^* x- F
AddType application/x-compress .Z
* Z+ J) z7 r4 O8 f% P) o AddType application/x-gzip .gz .tgz
* h; _8 d, W5 d) a0 f6 G' `3 n AddType application/x-httpd-php .php
# j, ]4 f/ q; i6 h! s AddType text/html .shtml; F5 [) l* I& P; w! S3 w6 ]: Q
AddOutputFilter INCLUDES .shtml ?0 W6 l9 w! M5 K& l& a8 V' D# A
</IfModule>
6 E! v& [% p3 R: a/ g; m% QAddDefaultCharset UTF-84 t* m6 i$ h% x
<IfModule mime_magic_module>$ w" P. _) `* W0 R. E, x
MIMEMagicFile conf/magic
3 V( a `6 ^& u5 |' }4 o7 m</IfModule>
; n# @0 X! d3 qEnableSendfile off4 R% n" W, ?. H: V
EnableMMAP off
0 s+ }9 s: B1 g- f# W2 c( \IncludeOptional conf.d/*.conf
- o+ }- z5 Z* \" g" i7 [3 s- P
- t# `9 Y5 e, o( Z. B! n' b, A执行[centos-master]:docker build -t registry.evehicle.cn/httpd . 命令制作名为”registry.evehicle.cn/httpd”的镜像(注意此处的点必须要有,并且其意义代表当前目录下的Dockerfile文件)
7 D6 m8 z+ L" Y/ i+ q' L! M; r" n" I1 y# a! L
3.将制作好的镜像上传到私有库2 i0 b- a* E* u0 p3 ~
2 c' C! @3 |$ e/ L7 b2 Odocker push registry.evehicle.cn/httpd+ f) Z3 k& {4 F: P
0 ]; ^4 h0 h. M4 {5 _3 D% s
4.编写启动apache服务的yaml文件
: v; O- J; w ^+ s0 c$ j( `1 |* k
[centos-master]:cat 13-rc-httpd.yaml9 ]0 U5 \& x& y0 z
, Z+ V2 ]' [; I- `& p
apiVersion: v1
% I2 B( r% G x0 M8 N$ Y" |$ Tkind: ReplicationController: V0 A9 O: M9 h& s4 u# V" l
metadata:
/ g0 K' d) q0 `* L4 L2 Y4 l9 B# S name: 13-rc-httpd
0 K' G Y7 T0 l1 r labels:5 b; w! Q9 E) u3 U
name: 13-rc-httpd; z' p7 b9 h( S, K/ I
spec:
: e B; _/ H% B/ }, V replicas: 2
+ q7 N& j, T* x4 q$ G8 B* L selector:
6 L1 i* ]8 N! k9 V' h8 V name: 13-rc-httpd3 d) J- C# W, [) n$ U
template:
m/ |9 I R/ D' ~: [ metadata:
3 z! l* E4 ~0 O1 O0 ` labels:
' L6 x" t+ H) \ name: 13-rc-httpd# S$ \$ H7 v1 [1 ~. O) A( ^5 x
spec:
, v+ N/ R `& Z; k% J3 o containers:3 k& \8 M( `7 L& c* C! F. L: x
- name: 13-rc-httpd" j% P* \2 r! O# a$ K \5 W' w
image: registry.evehicle.cn/httpd; o3 }: _; e7 U9 V& z9 W1 I( Z
env:9 x* |) r! S, {8 A/ Y: f+ o
- name: LANG2 n% G5 P7 Y8 B. [/ n7 w
value: en_US.UTF-8- h; R+ Z$ d' l
ports:
: G$ K1 \+ v( H4 k) Y - containerPort: 80% O* b0 C9 H; Y
hostPort: 80
R& C' ?0 A4 Z, q2 n9 w" m- O9 c# A volumeMounts:
( E" N8 R/ y9 Z6 Z6 m - name: time' P9 A$ T4 I- M; M1 r: l
mountPath: /etc/localtime
/ y9 C* i7 \$ L" g/ O - name: zcsy
/ f$ [7 ]' a+ A6 n mountPath: /etc/httpd/zcsy
% J: K$ E; Y0 b/ _7 k% z; u, C - name: deploy
0 F* x( A0 b! h1 j5 f mountPath: /docker/httpd/deploy
% B7 T9 E+ N n. }7 a - name: log
6 ?+ L2 L7 |$ y- q: ~0 t; I mountPath: /var/log/httpd$ i( L! o+ }/ v) X: i1 H3 G
volumes:
* T* E- ^: W( d3 }9 Q2 P - name: time; B1 e: n, D. Q- k- }$ D1 M
hostPath:/ k! d5 u% G' S
path: /etc/localtime6 c. ]4 Y I0 ` o
- name: zcsy" b0 F5 q8 E/ F, E* G$ ~; Q1 u* M8 w, F; `
hostPath:& i' T! `- @" l/ A6 Q# _8 u
path: /docker/httpd/zcsy w1 R$ i2 W+ J& E
- name: deploy
- V) \% _8 o" ?# a' w hostPath:' k- i: t6 h* P& R) g9 c( m8 P
path: /docker/httpd/deploy/ h2 E& R6 _& ]. U5 p
- name: log$ H4 o9 ]% e" _3 @! F
hostPath:
8 ~/ p7 K, N* y/ V/ N8 V( k path: /docker/httpd/log
2 g3 q* r/ U2 z) F* L" i3 G) z- [ nodeSelector:0 S) i u( E# u) o) j
slave: "13"
3 G7 N1 Q; D. A3 I- o imagePullSecrets:
4 z7 A" Q6 J; p1 p - name: registrykey P3 G/ n2 W" J T* I
" d0 c. ^* c2 |' g- g1 z9 K4 t0 G9 |5.给其中一个node加上标签为“13”
% h5 p. d! g3 ?9 T8 M T k* ]3 H$ i# H
kubectl label nodes centos-minion-1 slave=131 n6 k0 `- |) r
- k& [$ W; P6 j0 g6.此时拥有标签“13”的nodes应具备的条件
' ]+ i9 ?8 A) n* R" g
9 l7 X: ^5 @7 _/docker/httpd/zcsy下需要有官网的配置文件
' i/ w" H- X; R; i H* o/ P
; E6 v' z% Q1 x<VirtualHost *:80>& e& ?4 }" ?2 C( P' `3 |
ServerName www.evehicle.cn5 i! i$ h' m4 G3 ~6 P9 o
DocumentRoot /var/deploy/wordpress/0 [9 F- t9 ]6 t; T2 ?( Y
RewriteEngine on
7 a( z: Y2 w0 Y% F9 ~ RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
" ~+ ]: j" ?3 h! W RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
; `; ]5 P/ X2 E% Z 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)$# w5 H5 w8 @! n/ R0 h
RewriteCond %{REQUEST_URI} !^/server-status$: ?5 ]/ q9 C2 c, u' C
RewriteRule . /index.php [QSA,PT,L]
4 t2 Y+ a% K& _) R' N
; N/ n" f! T, w% s# V2 @. L</VirtualHost>' S- U3 o. P9 {, [* T; \
<Directory /var/deploy/wordpress/>& F [9 | R& X2 o5 \% {" i1 a
Options FollowSymLinks
7 u( l& `+ L) M8 I- g AllowOverride All
3 c( y+ X1 j. |3 S- Y9 w Require all granted0 W) Z* D% s! T3 w- N% l
</Directory>3 T0 @' @& \* T, Z( [
6 t% {1 q7 q* F1 f7 b- ~' X
以及/docker/httpd/deploy下需要有官网的代码5 z5 j# v0 ~+ d* J$ P# P5 T# C
! O p( k- F* J; n7.运行yaml文件启动容器
! P( H7 m0 x0 v) w9 ^; O# Y; f( i+ X: R" P
[centos-master]: kuberctl create -f 13-rc-httpd.yaml, ` V- {: M5 N- h
7 Z c- D$ N2 L1 n) F, v
8.查看服务3 ]. L3 t# ]+ n* q
( \ H2 S/ c6 K& C* G
[centos-master]: kuberctl get rc
' U- e8 Y$ B9 C2 ]/ T1 c# _1 E! h
0 B, y9 ^% W0 L" z/ Q dNAME DESIRED CURRENT AGE' x8 V2 V0 m8 W$ D o+ N! T' ?
13-rc-httpd 2 2 168d; g, D7 d$ g8 N( U; l3 g: H
5 {" T j. o, z8 k) E) a- a9.程序中涉及的mysql\redis\memcache等服务也需使用容器运行起来
, X% a+ \9 a+ ?/ J2 Z! I3 P; T9 _0 @2 k3 e2 y4 v( ^$ r1 S) W
[centos-master]: docker pull redis 0 c3 d7 L& H# E! {$ j, S& Q
[centos-master]: docker tag registry.evehicle.cn/redis redis & n: ]; D3 }& `7 U( y# l
[centos-master]: docker push registry.evehicle.cn/redis 3 T4 f6 \, H; y% s* s$ L2 c
[centos-master]: kubectl create -f rc-redis.yaml
- o- a& G/ b: q( G G2 f[centos-master]: cat rc-redis.yaml& {" ?! \/ \$ m* ?) Y% {8 t
) ?( E$ T2 H9 G9 y& }
apiVersion: v1* q' z) r0 I# l* {$ v; a
kind: ReplicationController
8 m+ i5 x+ f+ l9 R/ ametadata:
6 i) O. C( {: Q# c! y name: redis
, a% c/ [" K, q, T labels:
5 L- T- C& O2 W- k* R% t name: redis
: S8 l `) B* G1 D# Bspec:
& n5 T! \! D$ B. v- M2 U( } replicas: 2
/ R: O9 t( S) Y# c8 P% a3 H selector:
; P! {9 s$ ?+ O9 I/ z name: redis
; J' ^% J) B0 A9 v2 w template:
0 k5 B! S) n+ @% J* D metadata:
" ^* q# Y. n( _' S( a labels:
6 u' q4 ~& H1 z* l. ? name: redis
/ v) n" D, d7 l spec:
% ]% H. [. ~) Q) a* F containers:
8 D) T3 f% ]5 T7 Q6 a# i: U/ N* } - name: redis9 V7 A/ X) P0 ~2 b
image: registry.evehicle.cn/redis* n/ V. S% w# Q4 P8 S3 b
ports:
+ y" k0 M# n9 f( g - containerPort: 63798 c j9 x) p- P* O
hostPort: 6379
% V1 G) r! \/ Z volumeMounts:
# c b* X, I: C* g( |$ N - name: data7 B: H- L$ s E8 m
mountPath: /data8 a% W, u' i z
- name: time
+ |$ B3 {# L9 _' R1 P' k" |. z- E mountPath: /etc/localtime
+ N9 `0 |) g; Q2 x( I( ` volumes:
3 x& b. f4 ]5 m9 W - name: data) F' f9 R( I0 ?
hostPath:
- {- }+ \8 }, Z7 j* \ path: /docker/redis/6379; @# Q0 G& e% J
- name: time. h1 e( M l- R7 y
hostPath:
( z2 W& Q8 f& {7 L path: /etc/localtime
" E% y8 R5 `, N) F% e/ v nodeSelector:4 S8 o3 j4 M+ b2 ^
slave: "13"$ _" `! D4 Y9 K$ ?8 Q6 @6 y' d
imagePullSecrets:
9 r2 x8 W) S( W - name: registrykey
; t0 w$ I1 t/ \* m. T* ~9 X
% M) _; K2 V( [启动memcache
( _; h [ Z$ c5 ^; x2 O[centos-master]: docker pull memcache
* ~7 W* f: y: |. i' V% t, H. U[centos-master]: docker tag registry.evehicle.cn/memcached memcache
- W! X- | }$ `& G4 E[centos-master]: docker push registry.evehicle.cn/memcached 5 ^+ e3 w* I' e2 h& D) b
[centos-master]: kubectl create -f rc-memcached.yaml 6 v1 X: X" K& p2 F) ~, d
[centos-master]: cat rc-memcached.yaml. ?7 S+ z8 {+ v# E; b8 E9 [ `
3 z+ F5 o( ~9 W5 KapiVersion: v1
$ v1 G+ v. c6 m2 P) H- H! [6 y3 ekind: ReplicationController
t; p, Z4 l. |metadata:
5 O; d U0 }4 [" ~ name: memcached
$ G, C" L6 ] E5 }: C* F labels:
2 Z. ~2 V) }: R+ u+ x5 S name: memcached
% q" w& |6 o+ G0 r3 pspec:
; W" o$ Y- ?0 G6 o/ _ replicas: 3/ ~( n. i6 o* k. B+ Q$ ~: z9 A1 a' K
selector:5 [8 ]: |# {1 R
name: memcached, ? Q8 D$ G! I9 B6 A3 h
template:
" V. i1 @; U/ l9 x& e& b7 L3 U2 a metadata:
% ~8 [/ o: k+ Y: x- y labels:* R+ W+ t; x+ D- K. i+ j" ]% D! }
name: memcached. u0 h/ E/ U* N" N6 L
spec:
( y; A! q) c5 c) P$ p2 f containers:8 i* I) l9 [6 U2 {3 k
- name: memcached$ e: E# Y. i8 D i
image: registry.evehicle.cn/memcached" T; j2 N$ p8 N5 M
ports:) z+ `0 ~+ _; t5 p- j" @
- containerPort: 112112 r3 {+ k# q5 [$ [* _4 r/ Q
hostPort: 11211/ U) F: K8 ~+ ]* `
#nodeSelector:+ V! w+ C" A. G% G( B
# slave: "13"
+ v" W% I7 Z H8 c( l8 I imagePullSecrets:& r# n" k4 B" m5 y1 r
- name: registrykey( R; c5 P5 H N6 M
; }5 f/ z; j% D* E. b& y X
制造mysql镜像 " z$ U. `, p- K, h0 ^% W) R
[centos-master]: cat Dockerfile
/ \% }/ x) O _9 R
5 q2 N [( \6 KFROM alpine
% P- y3 I& z5 P3 i+ X4 o: w5 q& ~
# H# o, h( H: M- L3 z) S
2 X$ v; V% A! {; B0 ?7 \0 p3 i9 FCOPY startup.sh /startup.sh2 K! ?) B2 N$ R
RUN addgroup mysql && \
, b" w: \7 p$ O& D1 f adduser -H -D -s /bin/false -G mysql mysql && \
: b& ^# c$ M! [+ J/ e apk add --update mysql mysql-client && rm -f /var/cache/apk/* && \
% I3 e1 r! M3 x mkdir /data && \
: o1 b8 h% k2 d% x chown -R mysql:mysql /data /etc/mysql && \* H( O1 W- b; _( q$ M9 r
chmod 755 /startup.sh \
# v& h# R! L3 A. L+ |( l ;- g0 H2 j1 W1 i" r1 l8 Y* u
v2 O5 Z/ G0 Q" `8 x
$ i! F P' G0 h5 p
WORKDIR /data
. I$ O' k, {+ x4 o5 V1 `& mVOLUME /data
1 |3 U% L! P0 LVOLUME /etc/mysql2 T0 s- b- D% k/ n8 g1 h
( Y' ]$ S$ G1 ]8 Y5 w; ~% o5 Y3 D7 i
EXPOSE 3306" z8 |9 _$ V4 T6 p
CMD ["/startup.sh"]
7 _ v0 i( n8 M2 T. s6 G0 ~. J3 E* S) B5 K3 D; y5 u* f9 h# e
启动mysql(建议mysql在宿主机启动) - z; S" J9 m+ q h, x: x+ \9 ~& Q
[centos-master]: docker build -t registry.evehicle.cn/mysql
7 U$ I' L8 }) ]6 t% e[centos-master]: docker push registry.evehicle.cn/mysql
6 W3 l ^- O" o1 t* @[centos-master]: kubectl create -f rc-mysql.yaml 6 q: \9 V8 | f% Z _# R- b
[centos-master]: cat rc-mysql.yaml
( A4 ^) Q& A; Q P1 Q! N A, f: l0 F. z9 I
apiVersion: v14 `. n! ^: a6 U7 x9 r
kind: ReplicationController
+ W. L( D3 ?+ Ometadata:9 }& ]8 Y3 u5 C# t# r9 @1 Q
name: 13-rc-mysql
L0 o4 t! O$ g- Y4 @1 _4 c" t# i. I labels:
0 m, Q# j. n5 Z1 i- |5 ^9 ^4 D6 r name: 13-rc-mysql
( J( c& R: @, Dspec:# M9 F$ C1 Y9 z3 A; P4 a
replicas: 2
- Y \6 `& r( Q3 T- |1 e. v selector:( Z3 s l) L5 M
name: 13-rc-mysql) m/ [- L. k2 U6 h
template:/ ], V& M1 }. L8 [+ l& Z, `4 i
metadata:
4 T d' a# J- U2 I) e) \6 c9 ] labels:$ L# g+ d6 T/ i' @1 H
name: 13-rc-mysql* V6 L& \ o6 P# Z2 g
spec:* w6 O& W6 N$ \7 P+ O9 X/ J
containers:
U6 U7 C- [: S. Z7 o0 q - name: 13-rc-mysql
( K& X( R' @* W% Q# j/ o image: registry.evehicle.cn/mysql
% }, p) I% F& Q/ e- v5 F5 r env:
D/ t9 u) A1 W( w4 g/ g3 }' Z/ r - name: MYSQL_DATABASE
8 H5 o( N; ]7 M1 t& B m+ A, Z value: admin
6 o4 o8 ?1 F+ u4 j7 k - name: MYSQL_USER
. `7 E2 ?) F* |' y5 L" p. [ value: tony2 V3 }- S( e; w4 J. v2 l& M- ?' O
- name: MYSQL_PASSWORD8 {8 T. }- Z6 A! X5 r# ]) |0 f
value: 456
6 U+ n9 h2 E! _! q8 v! b - name: MYSQL_ROOT_PASSWORD
( G; n+ Z9 I. o0 X9 r4 x value: 123
, r3 h2 f' d. E W9 F6 j9 w ports:
C8 a/ s7 I: O4 n# V8 S - containerPort: 3306
% _4 k) S5 d( g% Y9 Q6 M$ s hostPort: 3306
& n7 E1 q. i# t) p volumeMounts:' e; F5 _0 d: n4 T
- name: time
- K7 z" {8 C- m9 w% ~' O; ] mountPath: /etc/localtime- G" y. x5 j1 |8 f' x) a
- name: data& ~$ `; `/ }6 {1 s5 h. q$ i
mountPath: /data9 E* [& M% v9 r( U6 d) Y5 |+ ]
- name: etc+ }' U3 Z" P: `" s3 i$ X; K
mountPath: /etc/mysql
! a- y3 j1 |* V" ~- J - name: run
' j$ h, \# o4 } mountPath: /run/mysqld
0 H7 w. L# M9 w7 k volumes:
9 O$ V+ w0 |% F3 P2 T5 X - name: time& k& s# K, Q9 |4 G
hostPath:
" ?- X7 n4 P" O- m( U: w# K path: /etc/localtime( K, Y; [, l3 Z8 p
- name: data
, h% i# R0 Y) u7 i8 i! S hostPath:+ Q) {$ M; S; u% K1 b% |3 A2 r" h
path: /docker/mysql/data- l$ `+ h- S2 C
- name: etc
, S! ^, B/ B: F0 V hostPath:
* k: p9 Y" L; K4 t0 Y path: /docker/mysql/etc
8 f3 U. S" \, F. j5 \ - name: run
' N l9 ~5 h9 ^4 l hostPath:" P0 O* E8 B# O. B2 y
path: /docker/mysql/run
- t" F- M+ P" w0 D$ g8 } nodeSelector:
2 b* \& T1 ?# C# W6 A1 c( Y% O slave: "13"7 A" I' ~ d; _$ z1 P
imagePullSecrets:
3 D9 Q: M, {, ] - name: registrykey4 V7 H8 y! C+ ?2 u. d! [7 }
# @) p1 @ w# _5 J: \2 H7 I, X
为方便代码编写及统一管理,应提前做好内部DNS解析。将所负责的应用规整到对应的机器上。 |
|