飞雪团队

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 14471|回复: 0

Docker 与 K8S学习笔记(二十二)—— 高效使用kubectl的小技巧

[复制链接]

8242

主题

8330

帖子

2万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
27056
发表于 2022-2-12 14:35:42 | 显示全部楼层 |阅读模式
$ b. i5 M8 S( J5 X. I  g( U
<p>kubectl作为我们主要的操作K8S的工具,其具备非常丰富的功能,但是如果不经过打磨,使用起来还是存在诸多不便,今天我们来看看如何将我们的kubectl打磨的更加易用。</p>: u3 N- F. l  r0 I1 X
<p>&nbsp;</p>
0 Z+ g* F1 t& S6 o) m' R7 M* p  R<p>一、命令自动补全</p>
7 n# ^' y, \, a/ R<p>kubectl中提供非常多的命令,如果每一次都要手动一个字符一个字符的敲未免太累了,那么如何配置自动补全呢?这里以ubuntu系统为例:</p>
1 K$ e, M3 J' d4 U$ i; ]9 `9 k<p>1、安装auto-completion工具</p>) B9 f9 E+ e( ?- n
<div class="cnblogs_code">) V7 q, A: U" s( B) x0 \: m
<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> apt update
( W( z" T/ B0 T3 e1 lHit:</span><span style="color: rgba(128, 0, 128, 1)">1</span> http:<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">archive.ubuntu.com/ubuntu bionic InRelease</span>: c, Z/ m9 X* |; X& A8 j
Hit:<span style="color: rgba(128, 0, 128, 1)">2</span> http:<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">security.ubuntu.com/ubuntu bionic-security InRelease</span>
; Z5 }+ L5 a! D2 x) @+ kHit:<span style="color: rgba(128, 0, 128, 1)">3</span> http:<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">archive.ubuntu.com/ubuntu bionic-updates InRelease</span>0 S! \1 j% j* T7 R* v
Hit:<span style="color: rgba(128, 0, 128, 1)">4</span> https:<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">download.docker.com/linux/ubuntu bionic InRelease</span>
1 d; z1 X3 T. f% ?- {; IHit:<span style="color: rgba(128, 0, 128, 1)">5</span> http:<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">archive.ubuntu.com/ubuntu bionic-backports InRelease</span>) H+ W- n4 |  I3 K
<span style="color: rgba(0, 0, 0, 1)">Reading package lists... Done4 ^' {/ a  [) c- N- @
Building dependency tree
" L- c# G* \# h& \9 r1 TReading state information... Done7 L- Y1 A5 p8 N4 ]$ S
</span><span style="color: rgba(128, 0, 128, 1)">144</span> packages can be upgraded. Run <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">apt list --upgradable</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)"> to see them.
& T+ C: T) ~; ?/ ?8 `$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span> apt <span style="color: rgba(0, 0, 255, 1)">install</span> bash-<span style="color: rgba(0, 0, 0, 1)">completion# V" e7 S2 _; l8 w& s4 A
Reading package lists... Done/ S# M5 Y/ F+ F+ o4 s
Building dependency tree
. W+ b% f, h9 D! XReading state information... Done9 ?& F( D8 S2 R; R6 V3 B/ a' _6 M
bash</span>-completion is already the newest version (<span style="color: rgba(128, 0, 128, 1)">1</span>:<span style="color: rgba(128, 0, 128, 1)">2.8</span>-<span style="color: rgba(0, 0, 0, 1)">1ubuntu1).
' g9 u8 U0 n8 Z- c</span><span style="color: rgba(128, 0, 128, 1)">0</span> upgraded, <span style="color: rgba(128, 0, 128, 1)">0</span> newly installed, <span style="color: rgba(128, 0, 128, 1)">0</span> to remove and <span style="color: rgba(128, 0, 128, 1)">144</span> not upgraded.</pre>
# p2 J' q& Q; h4 r* b- n9 Z</div>
7 d  h* m" a( a( ^* f$ l<p>PS:如果是centos系统,则使用<span class="js_darkmode__0" data-darkmode-color-16446330660319="rgb(0, 104, 255)" data-darkmode-original-color-16446330660319="#fff|rgb(0, 82, 255)" data-style="color: rgb(0, 82, 255);"><strong data-darkmode-color-16446330660319="rgb(0, 104, 255)" data-darkmode-original-color-16446330660319="#fff|rgb(0, 82, 255)">yum&nbsp;install&nbsp;bash-completion -y</strong>命令安装</span></p>
* c. \* G+ `; P% U<p>2、<span class="js_darkmode__1" data-darkmode-color-16446330660319="rgb(163, 163, 163)" data-darkmode-original-color-16446330660319="#fff|rgb(0, 0, 0)" data-style="color: rgb(0, 0, 0);">配置自动补全<br></span></p>0 t. A1 m: W$ H- p, O6 R
<p><span class="js_darkmode__2" data-darkmode-color-16446330660319="rgb(163, 163, 163)" data-darkmode-original-color-16446330660319="#fff|rgb(0, 0, 0)" data-style="color: rgb(0, 0, 0);"><strong data-darkmode-color-16446330660319="rgb(163, 163, 163)" data-darkmode-original-color-16446330660319="#fff|rgb(0, 0, 0)">Bash</strong>:</span></p>
0 t( u# \" f2 ]9 t' F/ ~<div class="cnblogs_code">
" U/ T5 l. r' E0 k9 n3 k4 A<pre>source &lt;<span style="color: rgba(0, 0, 0, 1)">(kubectl completion bash)
+ z* N5 f- k* v1 B</span><span style="color: rgba(0, 0, 255, 1)">echo</span> <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">source &lt;(kubectl completion bash)</span><span style="color: rgba(128, 0, 0, 1)">"</span> &gt;&gt; ~/.bashrc</pre>4 V# V- j1 W" j; d+ E
</div>  ^) Y( ]6 `; x" Q8 S- u0 e
<p><strong>Zsh</strong>:</p>6 \) q  y7 m4 A1 ]/ f; h! S
<div class="cnblogs_code">
3 \% G; I, g' E: w3 W  K4 D<pre>source &lt;<span style="color: rgba(0, 0, 0, 1)">(kubectl completion zsh)9 ^9 D$ l3 x" @: M8 {
</span><span style="color: rgba(0, 0, 255, 1)">echo</span> <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">[[ $commands[kubectl] ]] &amp;&amp; source &lt;(kubectl completion zsh)</span><span style="color: rgba(128, 0, 0, 1)">"</span> &gt;&gt; ~/.zshrc</pre>4 K" l4 e7 M. W! B  \* ]6 ]9 e
</div>
! O8 ~: n0 a' F' ]" B7 \$ d<p>配置后就可以通过Tab键自动补全命令啦!</p>) I8 F, l* U, [2 V8 N- U
<p>&nbsp;</p>; |2 `/ G8 B/ @
<p>二、配置kubectl别名</p>
2 z9 D  @% d/ ^5 _<p>我们可以通过设置别名简化kubectl命令,编辑.bashrc文件,添加如下内容:</p>
4 W$ P9 M0 {  I( L7 J' p. ?9 n<div class="cnblogs_code">
/ f% p- g) H' Y% G<pre>alias <span style="color: rgba(0, 0, 255, 1)">sudo</span>=<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">sudo </span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">% ^* t9 z; Z, J, M0 A' Q
alias k</span>=<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">kubectl</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">1 I6 J, o0 M5 w8 T4 |  K. j+ J
alias ka</span>=<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">kubectl apply --recursive -f</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">
! ]0 j/ S5 E$ yalias kex</span>=<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">kubectl exec -i -t</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">
) O* S! O- ?; ralias klo</span>=<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">kubectl logs -f</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">
8 M. N5 E3 b. |* k' u3 E$ ^5 nalias kg</span>=<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">kubectl get</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">
2 D$ x0 H8 f; y% r2 balias kd</span>=<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">kubectl describe</span><span style="color: rgba(128, 0, 0, 1)">'</span></pre>8 M; d: y7 m+ u/ s/ [( B& _( f
</div>
- E- C7 j$ a& ?" G1 |' i<p><span class="js_darkmode__4" data-darkmode-color-16446330660319="rgb(0, 104, 255)" data-darkmode-original-color-16446330660319="#fff|rgb(0, 82, 255)" data-style="color: rgb(0, 82, 255);"><strong data-darkmode-color-16446330660319="rgb(0, 104, 255)" data-darkmode-original-color-16446330660319="#fff|rgb(0, 82, 255)">PS:alias sudo是为了解决sudo下别名不可用问题</strong><br></span></p>, W5 D- G: k2 F1 ]8 e
<p><span class="js_darkmode__5" data-darkmode-color-16446330660319="rgb(163, 163, 163)" data-darkmode-original-color-16446330660319="#fff|rgb(0, 0, 0)" data-style="color: rgb(0, 0, 0);">保存后记得执行 source ~/.bashrc哈,接着我们体验下:</span></p># q* L3 V' ~; p8 ^
<div class="cnblogs_code">
6 n2 c5 u0 U1 T% U<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> ka webapp_pod.yaml% s5 t# F! \  N; N# I. `. {5 N) D
pod</span>/<span style="color: rgba(0, 0, 0, 1)">webapp created
/ M2 z5 r  k- t, l$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> kg pods
+ C! K  ^* o9 ]" B+ c2 SNAME     READY   STATUS              RESTARTS   AGE
/ E. l( C6 A3 I3 {' I; |webapp   </span><span style="color: rgba(128, 0, 128, 1)">0</span>/<span style="color: rgba(128, 0, 128, 1)">2</span>     ContainerCreating   <span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">          7s7 V7 A# G& x3 N. |& Y! T
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> kd pod webapp
7 {7 L9 `' w! X/ |, e# ]/ NName:         webapp
/ u0 u# l0 {3 i; G. Z5 T* ^Namespace:    default& i6 Z, E$ d) K) k6 C
Priority:     </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">
6 y4 D  J+ S7 K8 B* Y* NNode:         ayato</span>/<span style="color: rgba(128, 0, 128, 1)">172.16</span>.<span style="color: rgba(128, 0, 128, 1)">194.135</span><span style="color: rgba(0, 0, 0, 1)">
2 b- _+ |% i2 m1 Y: n! y' p# ~' {- TStart Time:   Wed, </span><span style="color: rgba(128, 0, 128, 1)">09</span> Feb <span style="color: rgba(128, 0, 128, 1)">2022</span> <span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">44</span> +<span style="color: rgba(128, 0, 128, 1)">0000</span><span style="color: rgba(0, 0, 0, 1)">
3 I- D  c7 W. B3 rLabels:       app</span>=<span style="color: rgba(0, 0, 0, 1)">webapp
: w; F: ~$ n" wAnnotations:  </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
  [# H3 j, G9 j7 kStatus:       Running
3 r$ c' q+ `8 g) z  l+ g7 t2 KIP:           </span><span style="color: rgba(128, 0, 128, 1)">172.17</span>.<span style="color: rgba(128, 0, 128, 1)">0.6</span><span style="color: rgba(0, 0, 0, 1)">
) w% `2 k. S: x, T! Z0 GIPs:8 ]0 L9 m1 V$ a3 d7 @, O+ {! W. v
  IP:  </span><span style="color: rgba(128, 0, 128, 1)">172.17</span>.<span style="color: rgba(128, 0, 128, 1)">0.6</span><span style="color: rgba(0, 0, 0, 1)">9 L& v# O: D, t. _% ^% Y  u0 `
Containers:0 m& `* o( i5 q' D' I% Q4 b
  webapp:& S2 H4 V6 K' k+ }' v: X; f
    Container ID:   docker:</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">d9ddf9dd47de12b53f2119bf75df6706bee2e7711509638ad52adc9addeda704</span>  v/ @% L! x4 T5 |2 ~+ S
    Image:          <span style="color: rgba(128, 0, 128, 1)">172.16</span>.<span style="color: rgba(128, 0, 128, 1)">194.135</span>:<span style="color: rgba(128, 0, 128, 1)">5000</span>/webapp:<span style="color: rgba(128, 0, 128, 1)">1.0</span><span style="color: rgba(0, 0, 0, 1)">
) ?0 m4 H9 R/ K5 ^7 h# b  I; O    Image ID:       docker</span>-pullable:<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">172.16.194.135:5000/webapp@sha256:df3a447a013ada0642dec67bb31976f42f1a0699a68873d0452f514fa24e5c77</span>
* W& k: V& G/ L, g5 g; U1 T. G& T    Port:           <span style="color: rgba(128, 0, 128, 1)">5000</span>/<span style="color: rgba(0, 0, 0, 1)">TCP! K' x2 D4 [/ W1 |* R
    Host Port:      </span><span style="color: rgba(128, 0, 128, 1)">0</span>/<span style="color: rgba(0, 0, 0, 1)">TCP& V: Y* Z" O: y  F8 [' F% A- C
    State:          Running
" |0 S1 C2 z( P8 H' j6 k1 k8 M& v      Started:      Wed, </span><span style="color: rgba(128, 0, 128, 1)">09</span> Feb <span style="color: rgba(128, 0, 128, 1)">2022</span> <span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">46</span> +<span style="color: rgba(128, 0, 128, 1)">0000</span><span style="color: rgba(0, 0, 0, 1)">9 U  N) N' C5 `. Z5 V+ O2 W+ D
    Ready:          True& Q) N. f) m  [) P
    Restart Count:  </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">
/ H4 `$ b, K7 G+ |) _    Environment:    </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">/ ^# {. ?& t  x; l5 H, @8 N
    Mounts:
7 v1 ^" o' t7 T9 a; g! ]0 X      </span>/tmp from webapp-<span style="color: rgba(0, 0, 0, 1)">logs (rw)  t5 Y3 X+ B4 X2 Z- m: L
      </span>/var/run/secrets/kubernetes.io/serviceaccount from default-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h (ro)
7 c+ j  D( u8 A' Z6 d6 E' Q  busybox:
& v) v# A: w6 w5 r    Container ID:  docker:</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">6a6a35a628a782fc643af3dd49986bbc77c23de1ae4726bc521c77f61abbbf5d</span>% @' W2 P& D% a! z1 J6 n0 f
<span style="color: rgba(0, 0, 0, 1)">    Image:         busybox
6 ?+ s7 q- U2 W6 X  O. S    Image ID:      docker</span>-pullable:<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">busybox@sha256:afcc7f1ac1b49db317a7196c902e61c6c3c4607d63599ee1a82d702d249a0ccb</span>
. I) E+ j. ?2 j. \0 F8 Z    Port:          &lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">. {; p" I' U' H
    Host Port:     </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">6 n; _7 {( P; _0 l% u3 L! J; s3 R
    Command:" P# }. Z7 t$ Q+ R) |: N+ d/ |+ M
      </span><span style="color: rgba(0, 0, 255, 1)">sh</span>
* l' l% b6 a( [3 S3 y      -<span style="color: rgba(0, 0, 0, 1)">c6 m1 J% h8 ?- E, _  d) Z+ z: C
      </span><span style="color: rgba(0, 0, 255, 1)">tail</span> -f /logs/<span style="color: rgba(0, 0, 0, 1)">log.out
8 d* f3 F8 ^0 }; ]7 ^& r    State:          Running* c" y% X! w% o4 r3 ]$ P% m
      Started:      Wed, </span><span style="color: rgba(128, 0, 128, 1)">09</span> Feb <span style="color: rgba(128, 0, 128, 1)">2022</span> <span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">06</span>:<span style="color: rgba(128, 0, 128, 1)">53</span> +<span style="color: rgba(128, 0, 128, 1)">0000</span><span style="color: rgba(0, 0, 0, 1)">7 R  ]. b! I. J# H0 _7 r$ D
    Ready:          True7 A& z9 d3 |& P% ~. U( p2 V' L
    Restart Count:  </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">2 }5 m+ k5 D/ S
    Environment:    </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">! G9 D  U  S& W" f, _
    Mounts:5 c& B8 l/ e  s5 W/ F6 o5 x5 d
      </span>/logs from webapp-<span style="color: rgba(0, 0, 0, 1)">logs (rw)
+ N0 r4 b1 M, _      </span>/var/run/secrets/kubernetes.io/serviceaccount from default-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h (ro)* y* `0 S! G1 r$ l0 x- S
Conditions:( N' F  T) I1 k4 t
  Type              Status
* N: ]) V- M* _* [1 |) A0 {  Initialized       True
% Z1 k( J, F  c4 w  Ready             True- n' ?# j8 Q4 T* [9 d" q
  ContainersReady   True* Z6 {- E8 o- X- [3 Q- ?6 d
  PodScheduled      True
3 j  F  V: c0 O9 B9 a0 LVolumes:
( J$ c7 o0 y3 B5 @/ z  webapp</span>-<span style="color: rgba(0, 0, 0, 1)">logs:
7 C* q0 [- G9 h2 M  _3 I    Type:       EmptyDir (a temporary directory that shares a pod</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">s lifetime)</span>9 i  y) p- s, Q% S2 N
<span style="color: rgba(0, 0, 0, 1)">    Medium:
8 I- q7 Q/ j' z# F1 V7 s: `! K+ u    SizeLimit:  </span>&lt;unset&gt;<span style="color: rgba(0, 0, 0, 1)">; n7 V% {3 b- Z/ ]- R) x# l
  default</span>-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h:, I+ J. V2 m' G% o; g
    Type:        Secret (a volume populated by a Secret)
/ A. p9 b. ?5 H) m/ O    SecretName:  default</span>-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h
) p; d( j: ]; T) J6 C' C( E9 Y5 P    Optional:    </span><span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)">) I3 ^4 ?' @& q6 J
QoS Class:       BestEffort1 T& r$ y$ X) ~1 A0 x& T
Node</span>-Selectors:  &lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">, c$ E# [! J1 i, j" O! G9 j
Tolerations:     node.kubernetes.io</span>/not-ready:NoExecute op=Exists <span style="color: rgba(0, 0, 255, 1)">for</span><span style="color: rgba(0, 0, 0, 1)"> 300s
* L! U8 n0 ?$ o/ i* }7 c                 node.kubernetes.io</span>/unreachable:NoExecute op=Exists <span style="color: rgba(0, 0, 255, 1)">for</span><span style="color: rgba(0, 0, 0, 1)"> 300s7 ?0 w8 u# E" L* Y( l
Events:
6 H( n/ x, ]' I# w& M  Type    Reason     Age    From               Message
( Z, k4 e" y" s9 [8 ?  </span>----    ------     ----   ----               -------<span style="color: rgba(0, 0, 0, 1)">
4 G2 U% p4 G* i% I# h" V  Normal  Scheduled  2m23s  default</span>-scheduler  Successfully assigned default/<span style="color: rgba(0, 0, 0, 1)">webapp to ayato" B8 H) C( Y0 o3 M! h3 m
  Normal  Pulled     2m22s  kubelet            Container image </span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">172.16.194.135:5000/webapp:1.0</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)"> already present on machine
8 Q; f7 I9 p& C* ~& E; H& p6 ^  Normal  Created    2m21s  kubelet            Created container webapp* d- W6 I3 o& [% d; @
  Normal  Started    2m21s  kubelet            Started container webapp/ w* h2 o6 x2 H! H+ T. f+ I6 R
  Normal  Pulling    2m21s  kubelet            Pulling image </span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">busybox</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">3 K  H! J+ l6 E8 R& i8 L' y
  Normal  Pulled     15s    kubelet            Successfully pulled image </span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">busybox</span><span style="color: rgba(128, 0, 0, 1)">"</span> <span style="color: rgba(0, 0, 255, 1)">in</span> <span style="color: rgba(128, 0, 128, 1)">14</span><span style="color: rgba(0, 0, 0, 1)">.633078305s5 v' U/ A; S- w. j* s
  Normal  Created    15s    kubelet            Created container busybox
9 f. r2 Q8 x9 j5 Z9 _: B  Normal  Started    14s    kubelet            Started container busybox</span></pre>
% t- N) q( l6 i  j+ v/ T</div>
; g! {9 W0 Q; B. J) Y<p>真的是飞一般的感觉!!!</p>3 K1 J# \" z) D
<p>&nbsp;</p>
" f$ K0 d* Z+ e& |6 G<p>三、Context和Namespace切换</p>( s, ]" T$ L" S6 A- n9 y
<p>我们在公司的容器平台上使用kubectl时,经常需要切换context和namespace,导致命令非常繁琐,那有没有简便的方式呢?—— kubectx</p>) K5 d  |5 X7 e: X8 O+ c
<p>kubectx安装</p>" T9 b/ Y' Z; \4 P' ]
<div class="cnblogs_code">
7 e& w: {' g+ X+ \<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span> git clone https:<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">github.com/ahmetb/kubectx /opt/kubectx</span>
6 q. [& \( x! s8 J# D# \3 F5 vCloning into <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">/opt/kubectx</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">.... F/ j! H8 e  D+ |! s+ W! `$ x# z
remote: Enumerating objects: </span><span style="color: rgba(128, 0, 128, 1)">1457</span>, <span style="color: rgba(0, 0, 255, 1)">done</span><span style="color: rgba(0, 0, 0, 1)">.
3 I/ ~2 A. H8 ?) t# Gremote: Counting objects: </span><span style="color: rgba(128, 0, 128, 1)">100</span>% (<span style="color: rgba(128, 0, 128, 1)">172</span>/<span style="color: rgba(128, 0, 128, 1)">172</span>), <span style="color: rgba(0, 0, 255, 1)">done</span><span style="color: rgba(0, 0, 0, 1)">.+ R7 H- {& d! y2 m5 W3 _$ c/ A  {" P
remote: Compressing objects: </span><span style="color: rgba(128, 0, 128, 1)">100</span>% (<span style="color: rgba(128, 0, 128, 1)">115</span>/<span style="color: rgba(128, 0, 128, 1)">115</span>), <span style="color: rgba(0, 0, 255, 1)">done</span><span style="color: rgba(0, 0, 0, 1)">.
* s/ S" E+ u9 L8 e: u2 tremote: Total </span><span style="color: rgba(128, 0, 128, 1)">1457</span> (delta <span style="color: rgba(128, 0, 128, 1)">85</span>), reused <span style="color: rgba(128, 0, 128, 1)">97</span> (delta <span style="color: rgba(128, 0, 128, 1)">51</span>), pack-reused <span style="color: rgba(128, 0, 128, 1)">1285</span><span style="color: rgba(0, 0, 0, 1)">
& a- R5 ^9 w' g3 _+ ~: J% w3 A9 EReceiving objects: </span><span style="color: rgba(128, 0, 128, 1)">100</span>% (<span style="color: rgba(128, 0, 128, 1)">1457</span>/<span style="color: rgba(128, 0, 128, 1)">1457</span>), <span style="color: rgba(128, 0, 128, 1)">905.30</span> KiB | <span style="color: rgba(128, 0, 128, 1)">69.00</span> KiB/s, <span style="color: rgba(0, 0, 255, 1)">done</span><span style="color: rgba(0, 0, 0, 1)">./ F5 z5 M& f% w0 i5 [! N2 v6 O
Resolving deltas: </span><span style="color: rgba(128, 0, 128, 1)">100</span>% (<span style="color: rgba(128, 0, 128, 1)">817</span>/<span style="color: rgba(128, 0, 128, 1)">817</span>), <span style="color: rgba(0, 0, 255, 1)">done</span><span style="color: rgba(0, 0, 0, 1)">.. R+ k0 G  n  S+ N5 F$ N
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span> <span style="color: rgba(0, 0, 255, 1)">ln</span> -s /opt/kubectx/kubens /usr/local/bin/kubectl-<span style="color: rgba(0, 0, 0, 1)">ns& L6 y! {0 ?7 ~, v% w
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span> <span style="color: rgba(0, 0, 255, 1)">ln</span> -s /opt/kubectx/kubectx /usr/local/bin/kubectl-ctx</pre>
& x1 o( v2 i$ N$ ]% d+ x</div>0 D+ l$ _/ S. @$ \& t! S- l  E
<p>我们来看一下效果:</p>
0 v6 P& v  @& M+ B. q/ D<div class="cnblogs_code">
8 k( W# L3 Q' T. P<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ctx$ c  [% _) J; N( c2 f
minikube
+ N+ X, h  y% {; n# s+ T$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ctx minikube
: ]0 `: d  y2 v' sSwitched to context </span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">minikube</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">.
5 S  H8 }+ i3 [* |$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ns
( S8 N7 o# A; N' P7 [default
$ u. H9 {# n! z4 ]# G, akube</span>-node-<span style="color: rgba(0, 0, 0, 1)">lease6 @' j: Z8 m1 ~: h* Q8 ^
kube</span>-<span style="color: rgba(0, 0, 0, 1)">public
; x/ ~3 N# j( h' O& k% m& Zkube</span>-<span style="color: rgba(0, 0, 0, 1)">system, {. ?1 U3 a0 {4 L
kubernetes</span>-<span style="color: rgba(0, 0, 0, 1)">dashboard" [8 P$ H; q3 ~8 ^) Y- F0 F
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span> k ns kube-<span style="color: rgba(0, 0, 0, 1)">public5 j# b. e  a+ u: ?( l
Context </span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">minikube</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)"> modified.
% V9 t" T$ ]# |$ gActive namespace is </span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">kube-public</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">.
7 ]8 _; r. K$ ^2 f$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ns default1 R; D( [4 ?' e* q* E1 H
Context </span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">minikube</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)"> modified.
6 ?: L( p4 Y# z, QActive namespace is </span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">default</span><span style="color: rgba(128, 0, 0, 1)">"</span>.</pre>: ~# V" ]6 m8 W5 m4 z* r
</div>
; E3 Q* B6 [1 F5 U  Q! h; h<p>&nbsp;</p>4 t0 j. Y3 k/ Z9 _: r3 F
<p>四、跟踪查看多个Pod的日志</p>
. z. X! E8 u6 b# L1 C2 W<p>我们一般使用kubectl logs命令查看Pod日志,但是它不能通过-f参数同时跟踪查看多个Pod日志,这就不方便了,毕竟实际生产环境中每个服务都会有多个Pod,这时我们可以使用stern这个工具,它具备如下能力:</p>
2 ^% q9 \6 p1 K) T<ul class="list-paddingleft-2">
) X2 S& X/ a; F/ L) r- R<li>
* K9 V/ y1 E: u; b- z; y, w+ M<p>允许使用正则表达式来选择需要查看的PodName</p>. i& v) l; F5 Y/ v6 E4 |  r
</li>
$ z" K  H: ^2 @! H<li>7 H9 K1 i  [+ V6 s5 a3 x
<p>为不同 Pod 的日志展示不同的颜色</p>* q7 X+ V9 D, Q/ j
</li>
3 L+ W3 W/ H- W<li>- t1 y! M8 F6 D1 p& G* u6 I
<p>跟踪日志过程中假如有符合规则的新 Pod 被创建, 那么会自动添加到输出中</p>0 t% q+ ?( Z( q% L! k  G, L5 L
</li>4 k- q% d: z+ |. e) b" `% N* ~
</ul>
' `6 r2 X* R1 M/ P/ |( m<p>首先安装stern(下载stern时可能较慢可以多试几次):</p>, [9 c* n4 q( c" M
<div class="cnblogs_code">
; {8 i3 f1 X/ H. b$ c<pre><span style="color: rgba(0, 0, 255, 1)">wget</span> https:<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">github.com/wercker/stern/releases/download/1.11.0/stern_linux_amd64</span>
8 O2 u, g9 r4 \<span style="color: rgba(0, 0, 255, 1)">sudo</span> <span style="color: rgba(0, 0, 255, 1)">mv</span> stern_linux_amd64 /usr/local/bin/kubectl-<span style="color: rgba(0, 0, 255, 1)">tail</span>
9 c& t$ V5 ]1 ?$ p3 ]<span style="color: rgba(0, 0, 255, 1)">sudo</span> chomd +x /usr/local/bin/kubectl-<span style="color: rgba(0, 0, 255, 1)">tail</span></pre>: u8 v4 q8 Y' i- T8 \1 Y# n
</div>
  X: n/ Z* C) V<p>安装完毕后让我一起感受一下stern的魅力吧,我的Pod里面有两个容器:webapp和busybox,如果使用kubectl logs 还得指定具体的容器,而使用stern就没有这样的限制。</p>
# m2 Y1 Z. Q; W- w1 r" p7 B<div class="cnblogs_code">
9 ?; d- Z9 l; `" T& _<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span> k <span style="color: rgba(0, 0, 255, 1)">tail</span><span style="color: rgba(0, 0, 0, 1)"> .* M" L0 _  ^6 W4 X9 J
</span>+<span style="color: rgba(0, 0, 0, 1)"> webapp › busybox
. h1 o$ g0 D0 O3 x  H2 B4 Z, s6 g</span>+<span style="color: rgba(0, 0, 0, 1)"> webapp › webapp
3 d4 A0 |. }5 }) qwebapp busybox </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.197</span> [INFO ] [main] [org.apache.coyote.http11.Http11NioProtocol] Initializing ProtocolHandler [<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">http-nio-4567</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">]
. B+ g6 |: D( rwebapp busybox </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.200</span><span style="color: rgba(0, 0, 0, 1)"> [INFO ] [main] [org.apache.catalina.core.StandardService] Starting service [Tomcat]
) d% I0 ?, Y" e: u* Uwebapp busybox </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.201</span> [INFO ] [main] [org.apache.catalina.core.StandardEngine] Starting Servlet engine: [Apache Tomcat/<span style="color: rgba(128, 0, 128, 1)">9.0</span>.<span style="color: rgba(128, 0, 128, 1)">41</span><span style="color: rgba(0, 0, 0, 1)">]
3 ~8 W5 C& x2 m  swebapp busybox </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.324</span> [INFO ] [main] [org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/<span style="color: rgba(0, 0, 0, 1)">]] Initializing Spring embedded WebApplicationContext
& ]/ W  `/ `0 y& w$ Z* @4 J/ vwebapp busybox </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.325</span> [INFO ] [main] [org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext] Root WebApplicationContext: initialization completed <span style="color: rgba(0, 0, 255, 1)">in</span> <span style="color: rgba(128, 0, 128, 1)">2952</span><span style="color: rgba(0, 0, 0, 1)"> ms
( f  ?( {: i( o$ _" y1 |3 ~webapp busybox </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.801</span> [INFO ] [main] [org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor] Initializing ExecutorService <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">applicationTaskExecutor</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">* T2 O6 K( ~7 w8 N% I2 H
webapp busybox </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">54.264</span> [WARN ] [main] [org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration$DefaultTemplateResolverConfiguration] Cannot <span style="color: rgba(0, 0, 255, 1)">find</span> template location: classpath:/templates/<span style="color: rgba(0, 0, 0, 1)"> (please add some templates or check your Thymeleaf configuration)7 W+ z: b0 f/ ^) ?  F
webapp busybox </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">54.377</span> [INFO ] [main] [org.apache.coyote.http11.Http11NioProtocol] Starting ProtocolHandler [<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">http-nio-4567</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">]
$ u" H5 Q) |4 T# {webapp busybox </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">54.481</span> [INFO ] [main] [org.springframework.boot.web.embedded.tomcat.TomcatWebServer] Tomcat started on port(s): <span style="color: rgba(128, 0, 128, 1)">4567</span> (http) with context path <span style="color: rgba(128, 0, 0, 1)">''</span><span style="color: rgba(0, 0, 0, 1)"># i" o) ]! o# n2 l* N4 M8 ^
webapp busybox </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">54.509</span> [INFO ] [main] [org.demo.webapp.todolist.TodoListApplication] Started TodoListApplication <span style="color: rgba(0, 0, 255, 1)">in</span> <span style="color: rgba(128, 0, 128, 1)">6.235</span> seconds (JVM running <span style="color: rgba(0, 0, 255, 1)">for</span> <span style="color: rgba(128, 0, 128, 1)">8.074</span><span style="color: rgba(0, 0, 0, 1)">)0 j7 d, \& d9 r: r# [) ~
webapp webapp1 d  ?$ {$ X" v+ P9 O0 ~7 Z  d
webapp webapp   .   ____          _            __ _ _- @, U2 ]. R2 n( i( |& [+ n
webapp webapp  </span>/\\ / ___<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">_ __ _ _(_)_ __  __ _ \ \ \ \</span>5 O: w0 J6 J) E6 _' u. [- U3 |  B
webapp webapp ( ( )\___ | <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">_ | </span><span style="color: rgba(128, 0, 0, 1)">'</span>_| | <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">_ \/ _` | \ \ \ \</span>7 S: F1 B( s& ?& d7 ~
webapp webapp  \\/  ___)| |_)| | | | | || (_| |<span style="color: rgba(0, 0, 0, 1)">  ) ) ) )
, s/ [" A6 M. A5 d, k0 `8 m2 rwebapp webapp   </span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">  |____| .__|_| |_|_| |_\__, | / / / /</span>
5 q' i/ p( J9 ]' C, u' h1 Nwebapp webapp  =========|_|==============|___/=/_/_/_/<span style="color: rgba(0, 0, 0, 1)">
( U- w! `. i2 R) n3 Gwebapp webapp  :: Spring Boot ::                (v2.</span><span style="color: rgba(128, 0, 128, 1)">4.2</span><span style="color: rgba(0, 0, 0, 1)">)! Z$ e) m0 o, k5 ?3 A8 p
webapp webapp" T9 _% ?7 @7 h5 c
webapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">50.124</span> [INFO ] [main] [org.demo.webapp.todolist.TodoListApplication] Starting TodoListApplication v1.<span style="color: rgba(128, 0, 128, 1)">0</span>-SNAPSHOT using Java <span style="color: rgba(128, 0, 128, 1)">1.8</span>.0_111 on webapp with PID <span style="color: rgba(128, 0, 128, 1)">1</span> (/opt/soft/webapp.jar started by root <span style="color: rgba(0, 0, 255, 1)">in</span> /opt/<span style="color: rgba(0, 0, 0, 1)">soft)
6 ~% `, t- x* W0 Hwebapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">50.165</span><span style="color: rgba(0, 0, 0, 1)"> [INFO ] [main] [org.demo.webapp.todolist.TodoListApplication] No active profile set, falling back to default profiles: default: B$ o3 L: N+ X) ?( r2 i& m
webapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.158</span> [INFO ] [main] [org.springframework.boot.web.embedded.tomcat.TomcatWebServer] Tomcat initialized with port(s): <span style="color: rgba(128, 0, 128, 1)">4567</span><span style="color: rgba(0, 0, 0, 1)"> (http)
3 N: Y" ]5 S: b% Twebapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.197</span> [INFO ] [main] [org.apache.coyote.http11.Http11NioProtocol] Initializing ProtocolHandler [<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">http-nio-4567</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">]" A, v$ V3 m' O
webapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.200</span><span style="color: rgba(0, 0, 0, 1)"> [INFO ] [main] [org.apache.catalina.core.StandardService] Starting service [Tomcat]6 e; b- n9 A7 S! d
webapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.201</span> [INFO ] [main] [org.apache.catalina.core.StandardEngine] Starting Servlet engine: [Apache Tomcat/<span style="color: rgba(128, 0, 128, 1)">9.0</span>.<span style="color: rgba(128, 0, 128, 1)">41</span><span style="color: rgba(0, 0, 0, 1)">]2 Q6 J9 Y  J! F
webapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.324</span> [INFO ] [main] [org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/<span style="color: rgba(0, 0, 0, 1)">]] Initializing Spring embedded WebApplicationContext
; {8 J) n  M; Gwebapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.325</span> [INFO ] [main] [org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext] Root WebApplicationContext: initialization completed <span style="color: rgba(0, 0, 255, 1)">in</span> <span style="color: rgba(128, 0, 128, 1)">2952</span><span style="color: rgba(0, 0, 0, 1)"> ms
* D) {) T3 q! O, m! owebapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.801</span> [INFO ] [main] [org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor] Initializing ExecutorService <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">applicationTaskExecutor</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">
! S9 }1 D% Y' B8 P! {+ @7 ]webapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">54.264</span> [WARN ] [main] [org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration$DefaultTemplateResolverConfiguration] Cannot <span style="color: rgba(0, 0, 255, 1)">find</span> template location: classpath:/templates/<span style="color: rgba(0, 0, 0, 1)"> (please add some templates or check your Thymeleaf configuration)
3 J% s( O8 @- |% D- Pwebapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">54.377</span> [INFO ] [main] [org.apache.coyote.http11.Http11NioProtocol] Starting ProtocolHandler [<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">http-nio-4567</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">]
3 q: C; j' |, z( Hwebapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">54.481</span> [INFO ] [main] [org.springframework.boot.web.embedded.tomcat.TomcatWebServer] Tomcat started on port(s): <span style="color: rgba(128, 0, 128, 1)">4567</span> (http) with context path <span style="color: rgba(128, 0, 0, 1)">''</span><span style="color: rgba(0, 0, 0, 1)">
$ J# y* ^+ n5 I/ r2 d8 Y; {webapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">54.509</span> [INFO ] [main] [org.demo.webapp.todolist.TodoListApplication] Started TodoListApplication <span style="color: rgba(0, 0, 255, 1)">in</span> <span style="color: rgba(128, 0, 128, 1)">6.235</span> seconds (JVM running <span style="color: rgba(0, 0, 255, 1)">for</span> <span style="color: rgba(128, 0, 128, 1)">8.074</span>)</pre>
- h- D- B/ |1 w/ D</div>
6 a& [5 x. d5 p6 X( a9 M- {) W<p>&nbsp;</p>+ d0 w) j$ ~5 n2 O1 a
回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|飞雪团队

GMT+8, 2026-2-26 22:48 , Processed in 0.620766 second(s), 22 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表