飞雪团队

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

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

[复制链接]

8566

主题

8654

帖子

2万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
28028
发表于 2022-2-12 14:35:42 | 显示全部楼层 |阅读模式

( k% [3 H$ O# z( M<p>kubectl作为我们主要的操作K8S的工具,其具备非常丰富的功能,但是如果不经过打磨,使用起来还是存在诸多不便,今天我们来看看如何将我们的kubectl打磨的更加易用。</p>1 P9 N! @2 W4 o8 y
<p>&nbsp;</p>' @) j0 ~" i8 _
<p>一、命令自动补全</p>) D$ S) o" m9 C0 d) G. ]
<p>kubectl中提供非常多的命令,如果每一次都要手动一个字符一个字符的敲未免太累了,那么如何配置自动补全呢?这里以ubuntu系统为例:</p>  w  ^: x3 ~$ k& h9 S1 B3 R
<p>1、安装auto-completion工具</p>, ?8 {. c5 C7 a% P7 y
<div class="cnblogs_code">
: N8 h) ^! x! l2 m* @8 }) q<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> apt update
% ?  @9 [2 S5 N) r. ?Hit:</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>; ~) l& Y  X6 i# ]6 d
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>; l4 k4 J0 U+ |' f6 F) a
Hit:<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>  |& }7 f6 N5 K! Z: l" r# @/ K9 g
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>: D! G1 w5 O& n, t0 s
Hit:<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>
8 K' I, S" |5 H2 I<span style="color: rgba(0, 0, 0, 1)">Reading package lists... Done# L* q" D" p+ i1 I! M7 ?1 x9 {" t
Building dependency tree% g. J- R; R5 ^2 l
Reading state information... Done$ V' D% W, G9 T8 h0 G
</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.) v, X8 M7 U# K& P- n4 O& d) e4 Z
$ </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
! o# a- I! H/ |5 {: e. eReading package lists... Done
5 c. e: [* ^* G- K( @3 n- iBuilding dependency tree. [" Q4 }- N+ j# `0 j/ F7 w
Reading state information... Done: Q/ Y1 f; c& f$ t; }  C7 L% W
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).
7 n6 p4 Q5 K7 q7 `. P</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>. E# a% C# j, e9 V8 B$ b
</div>7 n: ?7 d5 o) O  E5 f! c7 @+ j
<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>- Z: [) }; d" @
<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>5 X' |- u' b  B* K7 t2 o0 q8 m
<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>( H9 o. W4 v" Z1 d5 s% Y' d8 b
<div class="cnblogs_code">: o5 C( y6 n1 c* n  e1 R
<pre>source &lt;<span style="color: rgba(0, 0, 0, 1)">(kubectl completion bash)! q  L4 K* U: g5 H/ z
</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>& I" R- \8 q1 o- A  c) {- _
</div>
" Y9 [" j9 P0 e, W6 _<p><strong>Zsh</strong>:</p>
& f! Q3 r/ r8 @4 _' f<div class="cnblogs_code">
. `- H+ ^% D2 A! s+ {  e<pre>source &lt;<span style="color: rgba(0, 0, 0, 1)">(kubectl completion zsh)8 }2 F6 a# _4 q: X2 R& ]  f7 `
</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>* g  E5 Y( y( O7 M
</div>
, b+ D% q: Y6 q5 Q/ ]% S<p>配置后就可以通过Tab键自动补全命令啦!</p>1 |0 h' C& z- t% u: S: U2 A
<p>&nbsp;</p>, N# z& H7 I9 t+ r
<p>二、配置kubectl别名</p>
* w9 w7 p3 I+ j! W6 `% n<p>我们可以通过设置别名简化kubectl命令,编辑.bashrc文件,添加如下内容:</p>
5 N  `. g: V! U8 q. e" s5 O<div class="cnblogs_code">
3 b* O& P' {  }& E" L# [<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)">
8 k+ b7 E" J) Q" xalias 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)">/ m" Z) b/ |# Q+ o7 t& i& m
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)">& ], m# E; Q9 \. Y- A1 N' h
alias 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)">
( y& ]6 T" j5 M4 Ualias 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)">2 W6 j5 }' `; ^$ `
alias 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)">& H  G/ J- v/ t3 I7 @+ V
alias 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>
) J. y' z2 J6 I! g2 o) @</div>. w7 r% O- \" a( I9 n6 ^# C
<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>
3 D6 z! z: W6 l4 m1 k; v<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>6 V6 p, f; |5 M# n* m# n1 ^
<div class="cnblogs_code">
0 f# ^+ F% `3 F# ^6 \<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> ka webapp_pod.yaml
1 G2 }, P7 K6 }/ U! F" H: t  L  {pod</span>/<span style="color: rgba(0, 0, 0, 1)">webapp created5 W. F  X# n7 m" V* C2 u
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> kg pods
% k" D4 h6 ?! ZNAME     READY   STATUS              RESTARTS   AGE
) A% c$ d+ Y: D9 x; h4 Q- ?$ K' dwebapp   </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)">          7s
. \$ v, t& y9 P, o* [2 O$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> kd pod webapp
: }6 y$ _) ?) c- IName:         webapp: y5 }  ?$ I% ~# I+ \
Namespace:    default5 G. T* q/ L. J9 c
Priority:     </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">
8 m1 X9 _* C8 z2 g' gNode:         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)">
/ N/ ~, m7 y" P% LStart 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)">
9 W: ?! W- i% ~+ u! Z) qLabels:       app</span>=<span style="color: rgba(0, 0, 0, 1)">webapp# S( X3 W! o6 ?+ ~" \6 U0 v
Annotations:  </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">4 B5 J1 j3 g6 }4 F5 t2 S3 a
Status:       Running# J$ A$ |% a7 Q/ b8 P) V( b
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)">
' Y% s2 n5 @$ @3 n0 U$ U, ZIPs:$ @( D) |- H& b4 V6 _* j# U
  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)">
; \" r- b6 L: t3 `- kContainers:6 J' q; [* h$ B- w( {; ]6 u+ q* \$ l
  webapp:* V3 l" f; X* [/ o8 v2 x. V2 `
    Container ID:   docker:</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">d9ddf9dd47de12b53f2119bf75df6706bee2e7711509638ad52adc9addeda704</span>' ], N- t6 F$ N0 ?7 |; W
    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)">
7 d% Q, s- _5 ?1 U+ H# m) Y    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>+ s6 G% c" _  e/ O2 s1 {/ N
    Port:           <span style="color: rgba(128, 0, 128, 1)">5000</span>/<span style="color: rgba(0, 0, 0, 1)">TCP* C' j9 ?6 W5 G% Q3 o
    Host Port:      </span><span style="color: rgba(128, 0, 128, 1)">0</span>/<span style="color: rgba(0, 0, 0, 1)">TCP
7 B- v  _% _: K, W7 r+ x    State:          Running5 E1 z/ T% s9 q2 i' `0 m! Y
      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)">7 e9 ]+ S2 J' ?5 v# Z
    Ready:          True
* O6 H1 H' L3 t; e$ J+ f    Restart Count:  </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">8 x% }$ b( d1 [/ D$ N3 A8 R
    Environment:    </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">7 \$ ^/ [! V9 x
    Mounts:
. d2 ~, K3 N# }/ _* X+ q( ?: Z, g      </span>/tmp from webapp-<span style="color: rgba(0, 0, 0, 1)">logs (rw)
7 y2 u% M3 M) r) ?" J  z      </span>/var/run/secrets/kubernetes.io/serviceaccount from default-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h (ro)
4 [& H" \# T1 {/ s* N0 b+ N/ r  busybox:- |/ M2 ?9 z+ v, G' M, @1 s  r1 x
    Container ID:  docker:</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">6a6a35a628a782fc643af3dd49986bbc77c23de1ae4726bc521c77f61abbbf5d</span>
' W* U& {) }# X5 Q- V, d6 a7 Y( M: Y<span style="color: rgba(0, 0, 0, 1)">    Image:         busybox
9 X: w7 \& \/ f: Z" I    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>  }) j/ A* o- G( H- J3 g8 X
    Port:          &lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
8 Q8 l" h" j. a& a0 E# t$ Z, Z+ X    Host Port:     </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
) g( U+ L( m: r, q    Command:
- v- N" E2 \+ P. S0 I- k, W& I      </span><span style="color: rgba(0, 0, 255, 1)">sh</span>% ]" p. u: L; l9 a
      -<span style="color: rgba(0, 0, 0, 1)">c
" l, S1 u/ m3 J' h! e& J# u2 d7 n      </span><span style="color: rgba(0, 0, 255, 1)">tail</span> -f /logs/<span style="color: rgba(0, 0, 0, 1)">log.out9 U  b4 d& @. \( U1 ~& O5 L
    State:          Running- @% u! ~- X: X1 k" _) ]
      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)">
* M& G$ M7 L" U  S" A4 x    Ready:          True
7 m8 v3 H" P' w- O. f0 W* @" K    Restart Count:  </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">
+ f+ q+ g' |3 i/ B1 A    Environment:    </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
* j. I% W8 o+ @& W    Mounts:
- X: c% S, Y; r1 ~      </span>/logs from webapp-<span style="color: rgba(0, 0, 0, 1)">logs (rw), z0 k$ H* p4 z) R1 ?1 C7 a( r
      </span>/var/run/secrets/kubernetes.io/serviceaccount from default-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h (ro)
5 J/ m2 ^4 R% i0 v0 D. ~( YConditions:
6 r: t1 m0 g% t& T  n' r  Type              Status
# P4 l8 N0 H" l- i5 Z% [" t  Initialized       True+ j! ^/ u6 W1 y. f0 W) ~/ \
  Ready             True
7 {4 T% L% J0 V" [% V  ContainersReady   True
6 ~' g+ l+ m0 e3 @+ C5 A  PodScheduled      True
/ J/ t9 U3 V0 @; K  X! lVolumes:1 k) ?/ ?& L9 f/ _* X
  webapp</span>-<span style="color: rgba(0, 0, 0, 1)">logs:
" {: K  ]( V# @7 N& F; b    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>1 |& m# l' m2 |! U
<span style="color: rgba(0, 0, 0, 1)">    Medium:
& Z& b" k$ j9 h8 e0 K    SizeLimit:  </span>&lt;unset&gt;<span style="color: rgba(0, 0, 0, 1)">
" `' C, R1 f- g7 c4 j( r8 v  default</span>-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h:
: Q2 o6 E8 r0 e$ f    Type:        Secret (a volume populated by a Secret)
+ {0 m, n* {; L0 X; o1 A    SecretName:  default</span>-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h& V& V. M/ ^% Y& k, y" |" ^4 {3 v
    Optional:    </span><span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)">
* h+ `* S7 U9 c6 L  _# yQoS Class:       BestEffort5 d, @1 G: D+ b1 w$ F
Node</span>-Selectors:  &lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
7 z1 _/ M% d, rTolerations:     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& V: A/ Z1 Y6 ^3 F% s4 H* R
                 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)"> 300s! P; y0 i+ G: u5 i, X3 P
Events:
" P& ^$ [7 f  f# I" M4 _. u  Type    Reason     Age    From               Message7 _6 C. A8 ~' J9 C5 _
  </span>----    ------     ----   ----               -------<span style="color: rgba(0, 0, 0, 1)">
" I9 _7 X5 C; H/ L1 s$ V5 f% p+ R0 R  Normal  Scheduled  2m23s  default</span>-scheduler  Successfully assigned default/<span style="color: rgba(0, 0, 0, 1)">webapp to ayato
3 q0 i& f! \2 S7 P3 c  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
& R; c  m* x$ Y3 ?  Normal  Created    2m21s  kubelet            Created container webapp
, k5 A6 S2 X/ y9 v5 a6 f! U; ^( b  Normal  Started    2m21s  kubelet            Started container webapp5 N# C' R$ ~7 _% J8 _1 `( Y( ~) K
  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)">% K1 @$ b3 U  F2 t
  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)">.633078305s
) ^8 J; @4 R3 ~1 l+ o  Normal  Created    15s    kubelet            Created container busybox
: I  @0 ?+ B" d! r) `: K: Z  Normal  Started    14s    kubelet            Started container busybox</span></pre>* i/ r0 e6 q, Y3 [- b0 P9 U  x
</div>4 H% G' A0 V1 S* L1 m
<p>真的是飞一般的感觉!!!</p>0 |, i0 ^' T  x3 W1 k3 R: x# u2 i3 B- z
<p>&nbsp;</p>4 u* D# |3 A3 y0 d7 w% z
<p>三、Context和Namespace切换</p>+ i4 x6 n/ u. K) b4 H: @5 ^3 {: U
<p>我们在公司的容器平台上使用kubectl时,经常需要切换context和namespace,导致命令非常繁琐,那有没有简便的方式呢?—— kubectx</p>
$ E) h* \- `; n+ g/ Z7 d* y: M<p>kubectx安装</p>
/ A6 ]* u) k) _<div class="cnblogs_code">, {9 V. Y! ?3 H- T
<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>
. j2 _7 Q7 ~3 g$ m& _  d) ~Cloning 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)">...2 s3 [( Q, ~8 p
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)">./ I. L5 k# K* Z* G& i
remote: 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)">.
$ a( |8 z) Q- u* R& }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)">.+ O4 f3 q) @8 I/ n& k0 ]* c+ `
remote: 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)">2 \* |4 }! Y' e- ^9 n( {
Receiving 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)">.
9 a4 L) u. S& ?3 I5 H) sResolving 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)">.0 T$ z/ G; ^+ I% `8 ?
$ </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
6 B- p; M7 R; P+ v5 I$ </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>
! J% \/ O  N, ]# L! |* [' w</div>
9 W; F3 z/ v( V4 c2 A<p>我们来看一下效果:</p>
$ C4 h, ^! z, V: g$ ?* B<div class="cnblogs_code">
# G( I, X, {- x5 {5 C- Z( A7 z<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ctx
, B# L8 r' X+ G& @9 ?minikube
" d& V: w9 S- v9 L! i$ z$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ctx minikube9 J2 n% Z' q7 L" Z# y6 F# x# [
Switched 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 f; N' B. f/ }5 |' y2 n. `$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ns: R* T* E& n. ~9 ?7 r' i
default6 R/ ]7 v0 V' l* R
kube</span>-node-<span style="color: rgba(0, 0, 0, 1)">lease* N) I, \3 A7 ?5 W
kube</span>-<span style="color: rgba(0, 0, 0, 1)">public
! f* u$ s8 F5 L" U. Pkube</span>-<span style="color: rgba(0, 0, 0, 1)">system
$ W) ]: `2 k2 X" F0 K2 E5 gkubernetes</span>-<span style="color: rgba(0, 0, 0, 1)">dashboard' {# i% n  ~* l' ]
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span> k ns kube-<span style="color: rgba(0, 0, 0, 1)">public& @" C4 }  ^0 ?
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.# ~5 |, ~6 H: N1 V
Active 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)">.8 l5 x2 i6 _4 \: C5 P4 O% e8 \3 L" H
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ns default
: }5 r; s, V, C4 p9 B) `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.
  I# V8 I! n' a# [( [7 z3 AActive 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>% R; Y: _5 }% E* k& g" q0 D0 o
</div>7 m; t  F  v" N0 D/ H+ z6 N
<p>&nbsp;</p>+ N, b7 z; f( R
<p>四、跟踪查看多个Pod的日志</p>& \2 s2 Q& u: T" {6 b
<p>我们一般使用kubectl logs命令查看Pod日志,但是它不能通过-f参数同时跟踪查看多个Pod日志,这就不方便了,毕竟实际生产环境中每个服务都会有多个Pod,这时我们可以使用stern这个工具,它具备如下能力:</p>
% s4 a" |( x1 L/ g<ul class="list-paddingleft-2">
$ {0 b( E$ G& A. ~6 [* N8 A<li>
" g" ^% e; }6 c5 W7 D5 b<p>允许使用正则表达式来选择需要查看的PodName</p>
" [8 d% i) e3 i) c: G  d</li>
1 z6 B% m% x: R/ v' J<li>2 P* f/ S& @  t" T' h8 X) A6 {: M
<p>为不同 Pod 的日志展示不同的颜色</p>- R/ a  s; [6 _( R0 P# i
</li>
7 ^6 O# p; p" v% O<li>
) C0 D2 _5 G' h<p>跟踪日志过程中假如有符合规则的新 Pod 被创建, 那么会自动添加到输出中</p>( i: \; U; Y& t4 d) ^2 E3 q+ G
</li>6 d( `' |0 [' O# J) D( W; Y
</ul>
: K8 z) ?+ `( ?0 R+ G& {, M<p>首先安装stern(下载stern时可能较慢可以多试几次):</p>6 R- ^: ^* B$ ]/ G  \1 j+ d
<div class="cnblogs_code">* Y& o$ ~7 z  q! u$ H
<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>2 y* a& d" l  ^- E* c5 {8 c' b
<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 [# f* C& n! [6 w5 k- p. o( J
<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>
. I, F1 f3 A/ ?* L</div>! i3 w# j9 n0 J& @7 z
<p>安装完毕后让我一起感受一下stern的魅力吧,我的Pod里面有两个容器:webapp和busybox,如果使用kubectl logs 还得指定具体的容器,而使用stern就没有这样的限制。</p># @; {4 [& W0 K/ f) c& c
<div class="cnblogs_code">
. t' Q$ p* K9 z- H2 |4 z. Y0 F* G, l<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)"> .
6 E" c7 Z/ z9 |% Z- K; o! M: |$ @- g* U</span>+<span style="color: rgba(0, 0, 0, 1)"> webapp › busybox
2 o% s7 Q. i1 d8 h</span>+<span style="color: rgba(0, 0, 0, 1)"> webapp › webapp' `/ d# N# f" D1 @4 _, R: j
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.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)">]
7 t: Y8 R# J7 W: 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]
2 }  ^( o& n; z  J* q. I- xwebapp 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)">]
+ l3 o$ J: g. U* ]& j$ g1 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
' |- i4 T- |) I/ y. Cwebapp 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) {  V& s9 e' k% R. [2 a' z
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)">
* P) [  [0 O+ o& C8 j4 C8 x! ?6 ]- p4 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)">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 Y; A7 `: n( X2 m  S
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)">]
5 z! Y" L1 n$ i( v1 ^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)">' w6 |* Z: ~  X, ?8 e! g; O* 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.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)">)
% K; g. m+ H0 R0 |( v2 y+ o+ hwebapp webapp
& k! V* R& h6 m  R. Dwebapp webapp   .   ____          _            __ _ _
, T" |2 c5 x& Z; n& twebapp webapp  </span>/\\ / ___<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">_ __ _ _(_)_ __  __ _ \ \ \ \</span>
2 T& j+ S6 V: r  q$ J0 i7 vwebapp 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>  h& R2 G5 x4 `3 w5 \
webapp webapp  \\/  ___)| |_)| | | | | || (_| |<span style="color: rgba(0, 0, 0, 1)">  ) ) ) )! s3 F- ~8 z/ X4 x
webapp webapp   </span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">  |____| .__|_| |_|_| |_\__, | / / / /</span>
+ B* O) a+ s: i8 awebapp webapp  =========|_|==============|___/=/_/_/_/<span style="color: rgba(0, 0, 0, 1)">7 |: S0 G& f$ v! s: Q
webapp webapp  :: Spring Boot ::                (v2.</span><span style="color: rgba(128, 0, 128, 1)">4.2</span><span style="color: rgba(0, 0, 0, 1)">)
! j+ r+ ~/ d- N+ x- d$ Jwebapp webapp8 ^2 e9 F! f4 r0 r
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)
8 Q  f$ a0 W5 w9 e+ Mwebapp 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
5 w+ \6 Q8 M+ t3 ?& Rwebapp 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)
6 Q1 h, P1 Q, F" j3 ~1 G! m6 E7 Ywebapp 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)">]
  Q- B: d% G8 G' R( ]6 A/ K& |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]* F  H8 o* r& \: N
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)">], y$ F/ d1 B4 E4 G0 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
1 F8 N- s$ x5 [$ K: ]1 N4 Iwebapp 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( y3 H+ n% T$ `4 Y3 {3 ]2 `& u& r, Z
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.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)">
: S5 J. L& n" H+ a6 ^" rwebapp 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)+ |! w, E* ^; e& ]: l
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.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)">]0 M( K7 U7 }& s! |, ^, F0 E- K
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.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)">" R0 c2 w( A4 M! h) q+ _" t7 j2 `
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>! K0 t! O* h0 v1 h" |8 a- n, O
</div>
! k$ O% s3 e) ]4 h# `* @<p>&nbsp;</p>. o; M* P3 j5 ]6 [3 c2 c
回复

使用道具 举报

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

本版积分规则

手机版|飞雪团队

GMT+8, 2026-4-17 01:02 , Processed in 0.068826 second(s), 21 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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