|
|
楼主 |
发表于 2018-9-20 11:11:21
|
显示全部楼层
搭建私有库
4 t7 e6 o0 R/ O
7 H i3 J+ t3 m& L8 J. O私有库用于系统内部存储成品镜像,能够快速进行下载及被k8s调度。
. N% y: j- c- o% A1 W7 Y
6 r; g: N- g4 {7 M: b1.下载并启动私有库& {( ]& t- X$ Y2 g
# x G2 w% N) F% f: L& B ~9 R- C[centos-master]:docker run --name registry -v /etc/localtime:/etc/localtime -v /opt/registry:/var/lib/registry -p 5000:5000 -itd docker.io/registry
4 A% W) c2 I H: L1 H7 j
9 l" j. a$ u5 x' I#--name 表示启动的容器后名称,此处为registry# A$ ~9 E9 p2 N) ~
#-v 表示挂载路径 格式为宿主机路径:容器内路径
1 u7 ^$ J9 I* J- n; ]#-p 表示映射端口 格式为宿主机端口:容器内端口
3 J5 r9 p, v# S7 o#-itd docker的内部参数,此处声明后台运行容器并分配一个伪终端并绑定到容器的标准输入上,后跟镜像名称此处为docker.io/registry1 ?& |! D7 U6 Z; w" A
' T$ o4 C0 l( w5 }
2.创建一个secret服务,用于k8s调度私有库容器时的“令牌”。简单来说,secret服务就是一个存储密码的服务7 R4 O( B1 r3 q \# ]1 c- L
7 m# @# C/ G: x! 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
% e( ~5 N }5 E& q o7 v/ J4 q7 V9 z2 ]: y1 I+ ^: J2 r
[centos-master]:kubectl get secret' r/ ~, C2 d( W0 v7 e O* L
NAME TYPE DATA AGE
5 \$ G1 o# V4 ^0 D( y% C$ {registrykey kubernetes.io/dockercfg 1 6s
; Q! v7 g1 V' w+ s. d, a# d. [' b' f
# \' E- q" n4 B此时登录时会提示认证错误! ^% t# }+ J- v: y# Z/ ~
# e, d2 S) O' l# b ^5 u[centos-master]:docker login -u docker -p docker -e lienhua@zhongchuangsanyou.com registry.evehicle.cn
! t4 u! V4 Z! y9 eFlag --email has been deprecated, will be removed in 1.13.5 Q& [. p4 N, Y+ S0 z6 k
Error response from daemon: login attempt to https://registry.evehicle.cn/v2/ failed with status: 401 Unauthorized
7 E" }& Q. ]" g' x+ \3 `8 d1 ?0 K" ?! R# h' a. ]) Z; ]1 n
这是因为Docker官方是推荐采用Secure Registry的工作模式的,即transport采用tls。这样我们就需要为Registry配置tls所需的key和crt文件了
8 d2 f! X" o+ i7 S0 n7 H1 K) \% [% P' U6 i) `4 p
3.配置nginx反向代理
' n! Y( m& v' O/ B# v0 p[centos-master]: cat registry.evehicle.cn.conf& F8 V4 g% o8 i3 V1 m, }9 {' N
( B$ h7 o" d( M! E# ~9 R
# For versions of nginx > 1.3.9 that include chunked transfer encoding support0 a5 a. P3 Q/ z& o4 _( x# o E
# Replace with appropriate values where necessary/ K' c) [/ F, ~( e1 N4 H, J
5 x* g6 i; c- q. N$ Z
upstream docker-registry {7 a3 Z1 Q, [" l. o+ ]: Y% i% s
server 192.168.121.9:5000;
8 ^: J% ?2 C: s- I! {6 x! r( a #server 10.44.170.95:5000;
- \. u. x$ k5 _9 I& s4 Y! u/ s}
8 L7 `( B( L) ^) r' p1 Z; r
4 {1 W# I9 ~" i# uncomment if you want a 301 redirect for users attempting to connect: n+ N6 o1 g7 ]% m0 S$ d
# on port 80) E' y; A2 k: N2 O: B- T
# NOTE: docker client will still fail. This is just for convenience" Z" N5 a" a; \$ \, T' `( B- h
# server {8 |. B4 w F/ O' W
# listen *:80; d2 u) L% R8 ~# e& t2 E
# server_name my.docker.registry.com;
7 q( p% {0 `! t5 b1 s. P( [; K# return 301 https://$server_name$request_uri;& ^" T4 R# S( \* Y, ^( V
# }/ v. N1 c5 x& u* s
1 M& ?9 e4 r7 M4 kserver {4 K6 T* U+ e# X/ d
listen 443;
; V* M" m9 D# A* w( A9 E( B server_name registry.evehicle.cn;
5 g' D7 j% V. G$ M* F2 |6 l4 V. l1 i: F, z
ssl on;% `8 g6 _; @: f$ ?5 a
ssl_certificate ssl/registry.evehicle.cn.crt;8 R# l2 A5 F3 B3 z, ]* q
ssl_certificate_key ssl/registry.evehicle.cn.key;
t8 [4 [6 w3 c1 v& E. j
' Z) a& W4 {6 N: y7 |+ ]! c client_max_body_size 0; # disable any limits to avoid HTTP 413 for large image uploads; @ k1 @5 A3 C8 Z6 L; F2 W
. T$ t/ Y- X( s; g' j4 E9 |9 d7 v
# required to avoid HTTP 411: see Issue #1486 (https://github.com/docker/docker/issues/1486)8 I+ ~- V E( `
chunked_transfer_encoding on;
5 \8 I! N" l0 o( P# p: {4 U8 f4 p! Z: t x( }2 b; Y
location / {
: b6 N. c7 R9 F2 P5 y auth_basic "Restricted";
* O5 l9 J Q: v! s# M+ | auth_basic_user_file passwd;9 W- L1 j9 g+ ]. J
add_header 'Docker-Distribution-Api-Version' 'registry/2.0' always;9 Y3 p5 B/ z* s, b+ g+ |: }
1 \1 n% s* q* q0 L7 D proxy_pass http://docker-registry;
0 b* F# x+ v* V7 h3 m! g proxy_set_header Host $http_host; # required for docker client's sake9 H6 Y0 B" r3 \7 h; N
proxy_set_header X-Real-IP $remote_addr; # pass on real client's IP
$ b% K3 `& K% ?) [; {" @9 c' O proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
6 C( @) X5 S9 o9 v proxy_set_header X-Forwarded-Proto $scheme;, } l& L) u! ?, E9 K. F8 N
proxy_read_timeout 900;0 d+ Z8 n- O' ~( ?
}
5 S7 G: w, x/ T/ y# U! [" _* K* n# x: R8 P
location /_ping {6 t3 P( h$ e! L. ~( k2 p
auth_basic off;( s' O2 c9 Y# k7 s
include docker-registry.conf;
) Y, {9 ?" e$ d ~" i! g7 F. d* k }
% ?5 Y: c9 s: B: Y, D2 b4 l; j7 k! N' \
# T9 y4 u1 O5 v/ j% K8 M8 l6 t- Y location /v1/_ping {
% b( q2 u7 s- d1 M/ s0 {( V9 A auth_basic off;2 |7 }; W9 B4 G! @3 c
include docker-registry.conf;0 q. }. }" r: ]
}
! d) u' w$ ?/ ~- `- t
) S# b: Y% B+ p5 W8 o/ e location /v2/_ping {
& {6 s6 ]. c6 t) w2 C auth_basic off;! L: p$ g$ I, S" }, r: y2 K
include docker-registry.conf;
/ p6 Z3 D& _- G1 t1 h3 Q( n. ?0 V }
9 U" T) i6 t. v' _}
5 s3 B9 ~- z$ s$ a# W
2 d! N# y- r& ?3 ^1 W; N$ @将key及crt证书文件放到../ssl目录下。使用htpasswd生成密码放于./上一级目录: L& h8 X' M' [, A0 a3 y, ?/ w
( E$ D+ L4 Y# b8 l6 ]' H
htpasswd -bcm passwd docker docker
& m, |% e6 r7 K3 S) W' C #-c:创建一个加密文件
0 E$ ]: v% J }* f8 z$ {) V: H #-m:md5加密,默认可不填写$ e7 ~! W: V. x
#-b:表示用户名密码在命令行中一并输入,不用分别填写
9 u" A u9 X) |, \4 Z2 v9 Y9 N5 e# U/ N' e: R
4.再次登录
3 {+ w7 U' I7 v% w6 R' V6 P7 ]( d; f6 v" a/ Y; q3 t) w
[centos-master]:docker login -u docker -p docker -e lienhua@zhongchuangsanyou.com registry.evehicle.cn
j$ {+ t6 @# S) q/ r. B4 r
6 O$ A5 _; J; F; u, d& G- }1 xLogin Succeeded& i3 s6 U& r. W
表示成功,此时再pull\push既在私有库中进行. ~- U7 B8 i: V! g9 {
2 n( b* F3 e8 a
构建服务6 Z4 _; k1 k# s0 D: \
0 D- Y) r2 y3 a: L' I0 cdocker的本意是将代码包含在容器内制作成镜像形成“产品”。但出于公司的(频繁修改代码及服务器资源受限)的特殊性,我们将代码以“外挂”的形式运行在宿主机上。下面以部署官网(apache)服务为例:
1 f, M' e* ~$ X3 i+ ^0 l1.从docker的公有库里下载centos7的原生镜像" k5 G; v# W8 ~) z! w6 s0 J4 e
* u! x9 O* u7 Q6 ^/ t' a8 E[centos-master]:docker pull centos
5 e; T: N, e) q5 O# Q2 e* [! e9 U" C
Using default tag: latest
" F) K7 _& W d7 Q5 L. DTrying to pull repository docker.io/library/centos ...
* [$ @3 v4 o$ ?9 W; V, h" flatest: Pulling from docker.io/library/centos; k0 g$ b3 a1 @
d9aaf4d82f24: Downloading [> ] 540 kB/73.39 MB
1 z) N* j/ }! Z! n/ d2 ?7 E3 X9 nd9aaf4d82f24: Pulling fs layer
& s0 G: z3 O; t1 _! y3 S) EDigest: sha256:eba772bac22c86d7d6e72421b4700c3f894ab6e35475a34014ff8de74c10872e
, x6 ? e! E3 a0 T8 b- D3 {Status: Downloaded newer image for centos:latest: H: L& A% p0 z. h* m8 K
+ z8 ?$ b2 X# I$ o: n2.编写Dockerfile制造apache基础镜像
$ q" w: k5 O" E, J# f6 V
8 B% u! \4 u$ K b* h######httpd####
# q' B( b! u5 k [3 aFROM centos
1 R: ?, O+ o3 g4 s$ E# f6 @+ \MAINTAINER lienhua lienhua@zhongchuangsanyou.com p& y0 H \" c+ X) U/ I4 v
RUN yum -y install epel-release+ d1 x R N6 o9 b9 u
RUN yum -y install httpd php php-mysql php-memcache* php-mbstring2 V! G" v( T/ D. n, z
ADD httpd.conf /etc/httpd/conf/httpd.conf: E( w$ B6 D7 h4 ]' D2 U4 J
$ t D6 {% u9 r3 rEXPOSE 80; C( l; ?; q$ M. h# X
5 @* r% d1 c5 d8 U$ m: T9 E6 ICMD ["/usr/sbin/apachectl", "-D", "FOREGROUND"]
+ V4 c& f; q. r2 Q% V# w
5 D& o2 v' V; p其中httpd.conf文件需要在当前目录下真实存在,此处其内容为
2 A0 U7 W$ U; m* {1 [, H! X3 A
/ {" A5 u% s _3 ?9 T* s. HServerRoot "/etc/httpd"
, D# U: ?" q, X+ L% t) }: n! ?Listen 80# t, [/ i2 D q/ w; b8 y" D
Listen 80801 P, L# u* }, E7 g+ X. F, s" m
Include conf.modules.d/*.conf( Z. ^1 l$ c( J7 {' v* p5 f
Include zcsy/*.conf
+ M3 T# w h# Q' N0 ^User apache7 w! D+ q& O/ C, v4 n4 u; [' q
Group apache
' t+ X$ {9 G* Z; X0 z6 S3 XServerAdmin root@localhost
& y7 n2 r" Y/ e: h! k1 @9 [& t<Directory />6 k* v: e- s# T
AllowOverride none
( }8 h% `: F G, _ \ Require all denied
& I: i- G# Q7 e0 n# @0 Q</Directory>
4 |1 m; a8 h+ L" G/ x. s* ZDocumentRoot "/var/www/html"
# G( Q$ i) S% y<Directory "/var/www">4 J' U O4 p8 Q; n3 b
AllowOverride None
/ `1 h ?. p$ N" S1 N( ?6 m Require all granted
t! ^7 ^1 Z- }; A</Directory>) b! S# l, t4 Y! S
<Directory "/var/www/html">
9 k7 t& ?1 U* u6 |) |1 t Options Indexes FollowSymLinks
; ~. U* V" M! u0 ^ M- K, j AllowOverride None
* @6 O" r4 @. }3 p Require all granted( ]; j0 }9 T9 V; Q9 X8 Z2 w. w9 Q
</Directory>
, d6 Z( T% S( {9 U7 p4 p<IfModule dir_module>$ F! b) [/ T0 D/ N
DirectoryIndex index.html. C d5 S7 g! |: i: C
</IfModule>
( ]7 q# u) W3 u5 m+ N% u: D* W8 B<Files ".ht*">
5 R# T/ n: z& u" M& m Require all denied
6 N9 {1 g" P x</Files># K% ^- R/ g, l% A5 Z) v1 ?7 y
ErrorLog "logs/error_log"- x1 P. @( Y j: P
LogLevel warn4 _) T# A8 y3 w% D
<IfModule log_config_module>
8 ?6 A# h1 ]) V) h9 x' B LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined2 b$ Z* R% i8 y) }; Y
LogFormat "%h %l %u %t \"%r\" %>s %b" common
1 [# s7 t; o8 h7 [$ E2 i6 @ <IfModule logio_module> k# o4 z; T. w# f6 v
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
8 I/ e7 o4 Q) \: Y$ Q7 a& x0 F </IfModule>" i: b: [% Z% x5 @' Y, S
CustomLog "logs/access_log" combined
, g; u; Z7 l; O0 r</IfModule>
& a4 ?5 [9 Z3 }( m; [<IfModule alias_module>/ }% C, y' Q1 z# x! E
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"( Q: g# g* z: }; @) s2 B8 Z
</IfModule># _9 e( i& z6 {5 C" y: f
<Directory "/var/www/cgi-bin"> s' B/ |7 G' B3 L4 C
AllowOverride None+ z- u$ s# Q1 ?" S0 o1 Y
Options None! c4 j8 s# s8 D/ _
Require all granted/ M1 G" c6 s' t" \/ w( D
</Directory>
+ J; f- y/ f; g% x$ l<IfModule mime_module>2 D+ U/ I. V9 H1 r0 e/ j
TypesConfig /etc/mime.types
/ r! _6 b; o. g2 x% [5 m8 \2 p& x AddType application/x-compress .Z
6 o4 k: G1 c( ~3 ^3 t- k, U AddType application/x-gzip .gz .tgz
: F" ?+ G4 L( j; r6 {8 k' X AddType application/x-httpd-php .php
, e r m7 |/ Y AddType text/html .shtml
% o2 m6 W" I: n7 Z AddOutputFilter INCLUDES .shtml# m4 i/ |+ I1 I8 r X
</IfModule>6 R% J# b- K: i1 j. [+ c& b: D
AddDefaultCharset UTF-8; s+ n$ T2 v V3 I' E
<IfModule mime_magic_module>
& D: P1 u& j0 t4 j- Z9 Y0 N& a MIMEMagicFile conf/magic
; ^+ T3 @3 l4 J% i8 X' C</IfModule>
- C( ]: F6 i* MEnableSendfile off8 r6 f3 k1 a1 ^' X4 g( R
EnableMMAP off8 l4 I: z- I$ d) H8 ]6 t7 c/ S, _
IncludeOptional conf.d/*.conf& K2 o: W5 T3 Q; ^; L
# m' Z' h- h+ {0 k
执行[centos-master]:docker build -t registry.evehicle.cn/httpd . 命令制作名为”registry.evehicle.cn/httpd”的镜像(注意此处的点必须要有,并且其意义代表当前目录下的Dockerfile文件)
9 K2 H/ W* N! B- ~ t
" c1 c4 A, A. x- d4 J3.将制作好的镜像上传到私有库
* Q, h3 \, `% D4 j; x2 Q& Y- V
docker push registry.evehicle.cn/httpd
) a3 ]8 G) y; N- O1 B4 v [! K8 ]3 E9 @
4.编写启动apache服务的yaml文件- h. G+ E2 y. v9 c! X: x
8 u Y' w5 P \9 N7 S
[centos-master]:cat 13-rc-httpd.yaml
, H5 P4 m5 `' b8 C* }% f$ d, E- w. j1 F" @- ^7 r/ y" T
apiVersion: v11 w4 c8 C! ] d( }) |
kind: ReplicationController+ F3 {8 h% W2 x! Z( p) C& X
metadata:- G& u( Q) m, ?
name: 13-rc-httpd
1 Z2 p* y: J- s" K2 K2 o labels:$ I6 i8 L) l+ I% c) Q* q
name: 13-rc-httpd
" O& Z. F# @2 D8 ^" v: cspec:
& `# _: O4 [8 z% Y% P& f% F, G4 Y3 G replicas: 2 l: n# A T- V- v
selector:
; w) t- S0 p: {5 ~4 F name: 13-rc-httpd
$ Q1 n! @8 X, B0 F6 C& d/ t template:
* @: N; ^! ^' a& u. j! i4 Y2 h metadata:
2 Q- ~/ U8 j) d( c: n9 W' V labels:3 n6 E1 [% n1 G8 r
name: 13-rc-httpd
. m% K% }& p& E* t% O7 C+ h' V spec:7 b1 J7 s4 g9 p$ ~2 _3 }3 {# d
containers:3 L/ O& ~- b; [: f5 U. P; p$ Z5 m, g
- name: 13-rc-httpd6 \' q1 H4 ^/ G; W8 \$ E" ^
image: registry.evehicle.cn/httpd
) A; b3 b' u) P% T9 p8 ~$ T env:) p# `7 n5 {9 Q1 ?% i- H- x: e
- name: LANG
/ b* \) y( K: g8 X+ ]+ V value: en_US.UTF-8
, p$ x* e1 k) g* m" C6 \& U ports:6 l% o& s9 G* o0 d
- containerPort: 80
) S9 C" j) V+ J- t8 z hostPort: 80
* l* M% `( [$ v6 q7 o* _ volumeMounts:
- q! i3 p. ?: A+ q5 f( ]5 B - name: time7 m5 O# Q- v+ p( Q! C0 }. x
mountPath: /etc/localtime+ [, R) R1 J3 g" v8 g" Z
- name: zcsy# D- ^* w9 h: i! M1 N+ M0 L
mountPath: /etc/httpd/zcsy
8 B7 K/ k' ^& T1 G4 C) A - name: deploy# I8 \0 G6 o3 \1 V6 B$ `
mountPath: /docker/httpd/deploy V6 j- s o. K8 Y( W, _+ h. C8 e
- name: log! n# N, M4 R2 O3 a
mountPath: /var/log/httpd
) g% V* r0 D) Y# n+ T7 I; E volumes:0 `. L7 C5 v, X1 I- x4 |6 r! s
- name: time
4 y- x0 w ]3 w |3 z0 ^ hostPath:. _5 \! _4 b/ D5 M- Z
path: /etc/localtime& S U0 d; A+ y; I+ g' I/ [4 V
- name: zcsy
) D o' l( P% t$ E# B hostPath:
F& H- m7 R( ]( g G9 {" G path: /docker/httpd/zcsy
3 N. Z4 A% c; K - name: deploy0 P$ p+ _; O8 e" [! Z8 L" ^+ Q5 D
hostPath:& l% G& d9 `+ H% H. G. R
path: /docker/httpd/deploy$ b$ g' g' H; h6 F8 J5 f$ ]
- name: log
7 D8 I' A2 B6 u7 C3 e. s$ G# [ hostPath:, z& E3 |1 e6 M( u
path: /docker/httpd/log& w; y" Y" U4 c9 f
nodeSelector:
' i* q# c3 R1 C- D- H0 |: e# d, H slave: "13"
7 @. \3 j' I1 k1 J& j1 g/ j# [ imagePullSecrets:8 W6 ~" j, k: c8 [; |
- name: registrykey
' l( p* }; ?' t% j8 b, d
+ v8 G3 P* r) e) t5 R, |" ^5.给其中一个node加上标签为“13”0 D9 a" l" Q G4 z; x; u, n; q
; r' H7 @! N$ jkubectl label nodes centos-minion-1 slave=13$ o! n8 d/ }$ l0 q! ~
8 _. t, u, K7 h* t9 k6.此时拥有标签“13”的nodes应具备的条件
6 P# H/ z( a# k% }4 `; v* R) g/ P5 R' t/ B0 i, l7 y6 p! ~
/docker/httpd/zcsy下需要有官网的配置文件
, b0 Z0 Z* p: S" J! m) x6 @
$ s. a) t( {1 R+ L, _<VirtualHost *:80>6 q" q3 M' m+ ~' O5 G
ServerName www.evehicle.cn9 v5 {- O! a; `3 W4 o }
DocumentRoot /var/deploy/wordpress/
! Q( Q, z; ?/ q6 ` RewriteEngine on
4 O0 z0 ^! B, l4 c. Y8 b$ f RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
) S# ]6 ?# O( x" v RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
$ W: O3 M1 H+ q# M6 I J- O6 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)$
: z$ r" }9 B9 ]9 R- y% T RewriteCond %{REQUEST_URI} !^/server-status$
3 I- i `: i/ f# I$ C RewriteRule . /index.php [QSA,PT,L]
8 R& R' l+ S% U: K4 y, W3 v7 S1 c9 l& _( Y
</VirtualHost>/ t" s; _! K& W2 z; ^5 J" q! R
<Directory /var/deploy/wordpress/>9 z' c# ]9 c" P" E
Options FollowSymLinks
: s: H% m' G8 l$ g, N AllowOverride All
, C" [ ]$ `' x( ~ Require all granted4 E6 h3 o% t# F H4 \; v2 N$ r
</Directory>5 d% ^$ u: r( j1 `$ D6 A
2 E: ^% T2 j8 l+ c {0 k以及/docker/httpd/deploy下需要有官网的代码
- z/ J, n% p; Y
3 k. T( f0 J1 ^+ q2 @3 l" T7 G y7.运行yaml文件启动容器- y; z5 b$ e( M! L$ v- Z
. b6 [& ?- k |2 _[centos-master]: kuberctl create -f 13-rc-httpd.yaml
1 ~+ G; z" `* M2 y: y8 v$ a5 V) C9 M+ R1 Q; Y. f
8.查看服务5 J s- v. I1 X
# r7 g% B2 w: E
[centos-master]: kuberctl get rc7 V/ J! P0 o- @9 s# ]) i
1 S! v% C' e* e! e l' \$ J
NAME DESIRED CURRENT AGE9 I4 H' L2 _1 \1 B& @
13-rc-httpd 2 2 168d
2 m! i/ ]" q; b! c; v# ]# S; P; ? ?$ K
9.程序中涉及的mysql\redis\memcache等服务也需使用容器运行起来
0 R/ V6 K' }& h% W" ]! S
. k& m0 h/ W* ]0 i5 k2 ?[centos-master]: docker pull redis
% u$ j7 ]; k! Y! ] x- D[centos-master]: docker tag registry.evehicle.cn/redis redis
5 A! K6 B6 {* s e' {1 _8 D# O[centos-master]: docker push registry.evehicle.cn/redis ! p* U4 Y9 V& ^4 ]3 Y
[centos-master]: kubectl create -f rc-redis.yaml
|$ _0 |5 T q; H[centos-master]: cat rc-redis.yaml
) H# o& i! h$ V o
2 W5 W0 L: U0 W/ IapiVersion: v1+ G% J; F6 a8 n" B
kind: ReplicationController
' U" v0 e4 v/ J& i( n+ \% [: u; g# S! Lmetadata:& |# V% }( e" R, T0 G
name: redis
2 R0 b3 U6 S% Y* [& m, I& A3 X labels:
) L8 N2 T0 e' { S$ g6 B name: redis
; Y0 {3 k. d) Q" @spec:
6 E2 ]* b) i ?8 ^0 u replicas: 2
/ q) _$ ~1 m \7 }% ` selector:
1 q, j* p6 e' O3 B' j' a name: redis4 S, M! a" I3 @( G3 b2 A
template:
5 e4 G# r" }& {' R# m8 T( @ metadata:' X+ P* U" L' e7 c; ]! o0 u
labels:
6 b; Y( w! ~& z' A0 x+ r5 W name: redis6 v) i- [" b9 ]) V! X2 n
spec:
f' \/ s. b }$ H6 f& k/ f containers:
0 W' f6 J' i( w ]. y - name: redis& i0 q0 [* A1 r
image: registry.evehicle.cn/redis
: g, w$ a, ]6 L" G/ p3 q ports:
0 [ @+ g# c3 J" F) K/ l; l6 K$ o - containerPort: 63795 o7 \( C, M: n. H; v
hostPort: 6379+ a; t# o q9 L9 S' a
volumeMounts:
5 j Z/ ]/ `6 y" c - name: data7 w$ [! s' C# k7 f
mountPath: /data) Y) ^9 o" W# M& x" S4 j# C
- name: time
7 a1 Z* R/ ^9 V) |4 s1 z& y mountPath: /etc/localtime5 F+ o6 n' P/ ^2 D
volumes:9 r3 V8 [- s8 M' [
- name: data2 U, J% p3 `7 w0 ?6 Z
hostPath:: P$ F+ a+ \. `( v/ ~
path: /docker/redis/6379
$ z5 x1 H! d4 |8 l+ {, i8 L - name: time
9 J" ?0 @* L; D6 \* s, @$ L hostPath:
# N6 @6 i0 R1 ~8 L- q7 D path: /etc/localtime
1 W6 P6 S+ X: _2 m+ v nodeSelector:
; M8 D' |4 h3 j. q% K slave: "13"
& E) K" c3 F9 t* ~- i7 _# Y imagePullSecrets:
1 o4 w" g3 k( W/ E; M! s4 ^ - name: registrykey; C1 k0 J8 H* u. u5 F1 A$ I
: P; A! D% Q0 h6 D8 G4 S5 O& z
启动memcache
0 O5 N _4 V( d( D4 d[centos-master]: docker pull memcache ( G( d( f% P2 J' ?
[centos-master]: docker tag registry.evehicle.cn/memcached memcache
8 A: g; o, ]. U[centos-master]: docker push registry.evehicle.cn/memcached
5 ^) Z, `1 a/ c[centos-master]: kubectl create -f rc-memcached.yaml 1 `+ u* q. F0 q3 D2 ?9 a
[centos-master]: cat rc-memcached.yaml8 Z" m4 }6 [8 Y; X0 a; q6 ~
/ X4 \- F e0 a* l
apiVersion: v1. O# T) g8 {8 s! {: I( s
kind: ReplicationController% A; W; X7 s2 T4 [' _, m
metadata:
) {( w3 M. p" G* C1 ^7 N) M' b; E7 t! b name: memcached5 c# F* S5 u- ~& Q$ V9 [
labels:2 W7 B# J, D1 }0 j: m
name: memcached9 r4 r' I [) h, N! g- D/ t/ T
spec:
3 p0 y5 u- h3 K8 `2 o6 f0 z% Y( H replicas: 3
: A: Q( x3 a3 A" ?; v2 o" h% K selector:
& j7 S* B8 O x1 N2 H; ` name: memcached
! g6 Q. L# J9 A3 o6 ` template:0 e1 i4 I9 c, F; S8 @; {, a
metadata:: L, W& P/ S' j8 N( ^. n
labels:0 b, H5 r( O% S" Z
name: memcached
/ h- n- {+ M: I spec:
6 o$ H. y8 Q W containers:
8 t7 J. m& U- e: q- W; z9 B1 m* d - name: memcached5 b% C/ n" {7 H
image: registry.evehicle.cn/memcached
2 [& f& H0 E2 \7 J0 n8 U ports:
, k- Z; j4 ~/ ?$ _( U$ \& a) S - containerPort: 112115 T8 `/ [! j* h6 ?; y8 S C0 v9 A- C6 L
hostPort: 11211
- F" D) K. \( X# T #nodeSelector:, R, N0 X, F& h. [
# slave: "13"3 \7 v% w% [5 t6 D1 T
imagePullSecrets:) W/ r. Y8 P1 l6 o( Z/ v; F& C. O2 k# k
- name: registrykey. \0 c! G+ Z. [+ k/ h y0 L
" c; @0 B! J3 d' {1 ?制造mysql镜像
' t. i2 f q, ^$ {, B; P$ x! F[centos-master]: cat Dockerfile
/ ?5 \# k+ B7 N* w1 S/ D/ R7 { ?" }+ T4 T+ U/ @
FROM alpine
3 |! a% Z' ^" Z$ [; E" O k" i( k5 R. z8 W
# o0 \9 B/ p$ [& Y$ \ ?4 jCOPY startup.sh /startup.sh/ f1 M9 v) H4 s! B W
RUN addgroup mysql && \; d! }! N4 X5 J0 ]$ b: k( O- C
adduser -H -D -s /bin/false -G mysql mysql && \
9 [' Q+ p/ X5 d9 g. g& b apk add --update mysql mysql-client && rm -f /var/cache/apk/* && \0 n7 n8 X7 x: \
mkdir /data && \
/ T7 D! o5 o' o chown -R mysql:mysql /data /etc/mysql && \
& r+ ~) f5 [3 g' K V, R8 A chmod 755 /startup.sh \' p: }" |2 @# I" v4 j2 v# W. z# @& S
;
4 M) l- k) i; j( j+ ^6 c# ~9 Q; _* U3 p2 ^; _! p' ?
5 S2 O- [2 s. a. h5 ?& b6 }
WORKDIR /data: f- L) l- x. m; Q+ w
VOLUME /data) q* F6 x: t8 a! q) Q5 e- O
VOLUME /etc/mysql
" u0 g- b/ t* q( F' D
$ k7 @& {; E4 s/ v; h* L$ V# _, x. N. e* C
EXPOSE 3306
6 ?* q5 [ J4 K5 p' _) A/ BCMD ["/startup.sh"]' ~' v/ A9 q5 {3 C0 u' S* m
; z2 ?( z# z/ M% h/ o1 ^启动mysql(建议mysql在宿主机启动) 0 ?' r3 b6 G [& T! N5 F
[centos-master]: docker build -t registry.evehicle.cn/mysql
" ]6 F: h- j4 Q/ r; w' @. a E( v[centos-master]: docker push registry.evehicle.cn/mysql 7 J! h X+ f& w1 r- W4 {* n3 s
[centos-master]: kubectl create -f rc-mysql.yaml
0 R. f' [3 ^& n4 a[centos-master]: cat rc-mysql.yaml
" T- ~: E5 b7 ]: s A2 v# i2 Y: {7 |/ z1 f! ?7 c0 L; j, u
apiVersion: v1
! c( K0 n$ z& q2 Q- p# i$ Hkind: ReplicationController. Y* e5 w; V6 l `9 M# n' I
metadata:
. o1 V7 J, I" |- V f name: 13-rc-mysql
2 w. m* a* c6 h2 Q; n! I9 G' \6 ? labels:1 @, K* g! c* L( j# F8 K
name: 13-rc-mysql8 `+ }: o7 B u: F: s
spec:
/ s6 q% ~/ ]- U replicas: 2! R8 x; Z( h: F, }2 j. d6 J, V
selector:) u: k4 d$ M( S9 t8 p
name: 13-rc-mysql3 F; z) d, _; U) q
template:
. r" u% R- I0 b6 x8 z# A8 F metadata:
4 y! d% K( f) m9 c labels:' r* u" D: g# o; A# ?9 Y2 d
name: 13-rc-mysql
) H) I$ m6 J* c" L S) v6 D spec:
k" L/ ]" U: _2 P1 J containers:9 x* j4 p3 s0 d
- name: 13-rc-mysql
+ Q- r; y5 c7 [. s: U image: registry.evehicle.cn/mysql+ X- ?( {# ?9 n2 P4 c# d1 @& \: j
env:
5 L$ R# B/ n6 V9 U4 M2 X6 L- n - name: MYSQL_DATABASE `* ~# u2 g2 H% A' I. m0 z9 t
value: admin
# y! P2 \, r' K \ - name: MYSQL_USER
6 c* u$ K4 b& A( W4 W value: tony
7 {& ?2 x! f* d" P6 A - name: MYSQL_PASSWORD
k5 M8 V7 T! \6 \) H: s: g y; ~ value: 4560 }4 t8 f$ i) ?/ e4 |4 x
- name: MYSQL_ROOT_PASSWORD
; ~ {7 j4 ^- d7 a& R+ X value: 1236 t9 v' s, K( K7 e7 \& ?: e- n% f% y
ports:# s) c' ~- h" l) J- ^
- containerPort: 3306
' p1 A1 o$ x5 o) f hostPort: 3306
8 ~7 j% u: ~- A5 Y5 s volumeMounts:
: D4 ^' v ]* \* a. ? - name: time& q' E2 H1 K' c1 }" T
mountPath: /etc/localtime
( X. I# K. }* k1 @" ^ - name: data9 Y7 H0 P+ i! W1 Z9 L$ D
mountPath: /data( v, V0 }2 _5 Z
- name: etc
\3 m8 M, w8 v. M0 |8 A/ S; d mountPath: /etc/mysql
) Q j" O+ n3 f6 {2 J* a& B& t - name: run
I( C/ E# m9 C8 D, _/ i mountPath: /run/mysqld
4 E S% I! ]8 _: N* i volumes:) T2 Q. [0 |' x4 Z" O$ J! a1 d; d g
- name: time
* G6 Z w& S& t- Y hostPath:
. b: H) u# \& |- S1 q path: /etc/localtime
8 p. H1 K6 @. L! [& ] - name: data5 w& E/ }( n; D5 S
hostPath:7 E9 l/ @" N+ V8 z W1 j" b
path: /docker/mysql/data4 K# D4 j8 ]* k* j4 Z' c; J1 V
- name: etc
! y+ g- F6 X5 r hostPath:- _( U& k# `5 e; v+ C
path: /docker/mysql/etc4 F8 U7 E5 M4 L) ~' K
- name: run
/ @9 C0 I$ n l% }( f hostPath:
% j C5 K; D" v: L- G( e path: /docker/mysql/run8 G! K* D6 q. o- Z6 ^$ m
nodeSelector:
% K) C: q9 |$ v3 u6 R4 }3 b, t* d0 i slave: "13"
6 C# [0 P% Y2 d3 ^ F) I imagePullSecrets:
- R$ X$ v) k$ B/ ]4 | - name: registrykey4 T {) \4 Z) U8 O" _) q
) ]3 F( J2 F6 z0 o9 ~
为方便代码编写及统一管理,应提前做好内部DNS解析。将所负责的应用规整到对应的机器上。 |
|