飞雪团队

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

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

[复制链接]

6861

主题

6949

帖子

2万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
22913
发表于 2022-2-12 14:35:42 | 显示全部楼层 |阅读模式
8 i3 _, W' @+ o- n4 a
<p>kubectl作为我们主要的操作K8S的工具,其具备非常丰富的功能,但是如果不经过打磨,使用起来还是存在诸多不便,今天我们来看看如何将我们的kubectl打磨的更加易用。</p>  a  v4 w% G7 G+ J' \- X" r& E, n4 b% ?
<p>&nbsp;</p># |2 h& T& }# ^8 ^- N# E
<p>一、命令自动补全</p>
3 Z! n" N1 v# e/ }. e% d/ N<p>kubectl中提供非常多的命令,如果每一次都要手动一个字符一个字符的敲未免太累了,那么如何配置自动补全呢?这里以ubuntu系统为例:</p>, H! h! ~8 P) W+ T: e
<p>1、安装auto-completion工具</p>
) p- i/ i4 j+ h; D- _# D' L<div class="cnblogs_code">
1 v' T. P) v& c# x/ A$ y<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> apt update
  G0 U" K1 R0 `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>
' S8 [$ P" j* E8 PHit:<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>) n) U7 v8 L9 k& j+ s! ^
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>
$ h, i6 U* F5 m* q4 y% _  F2 FHit:<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>& n" Z6 X7 \$ C
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>) ]; E3 X3 T! \1 `* W. ^
<span style="color: rgba(0, 0, 0, 1)">Reading package lists... Done
, p' z, f/ \" Y  b9 n' fBuilding dependency tree
5 v9 b: x4 n9 c5 lReading state information... Done2 [" s4 ?3 _8 m
</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.
. ?$ a% r# z# |; ~; Q, ]( `- f* H$ </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)">completion7 R: d* q4 T: K8 a2 Z" |
Reading package lists... Done" l5 ^% t$ @9 [
Building dependency tree
9 n/ d  c0 y- m% HReading state information... Done/ k) N# [. q! N
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).
% z7 G+ R% {) x8 L</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>
/ a4 [8 L: ?( u% ]) Q</div>  c& P" e3 R3 r' d9 b
<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>* t8 `. ]/ e) p' N
<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>- Y- }; A1 o# B% f- 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>
% @+ \3 I# G* X7 L2 Z8 f$ W3 G<div class="cnblogs_code">8 b) b1 Y" \2 t
<pre>source &lt;<span style="color: rgba(0, 0, 0, 1)">(kubectl completion bash)
+ P. G- |: f% M2 G3 B* c" V' J</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>! `- }' G& B6 ?' ~' }% C# \
</div>: i/ j; |; A6 X" `, T
<p><strong>Zsh</strong>:</p>/ s: \4 r# l4 @  f" B% o
<div class="cnblogs_code">' P; N6 A) f, N8 @. P& {
<pre>source &lt;<span style="color: rgba(0, 0, 0, 1)">(kubectl completion zsh)
) `7 j0 T( y$ @0 z# C* e$ p: k</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>5 ?' w; H# L$ ?) W# t: h) Q4 n; M4 S
</div>
, o) r7 Q8 N* H; w! M- J<p>配置后就可以通过Tab键自动补全命令啦!</p>
9 W8 e/ ?7 m- o8 `  k9 A; `, a& j<p>&nbsp;</p>" ~3 I. C4 k* ~$ l' V
<p>二、配置kubectl别名</p>
3 d, |5 {4 v0 g+ B6 x<p>我们可以通过设置别名简化kubectl命令,编辑.bashrc文件,添加如下内容:</p># ^8 y- Y1 l# }& U7 s/ A
<div class="cnblogs_code">  m6 `2 E; ?( e( V1 O3 |6 c3 W
<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)">
, i! _9 A( X/ E! Ualias 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)">
8 W3 |. j, e8 d/ d" valias 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)">8 z- d/ h# m# Z% f1 e
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)">1 I8 n! Q  [, e: B& R( L) |3 m
alias 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)">+ L3 R- U3 C3 m- t
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)">
5 D" o9 s9 A# s$ @1 R" e7 z+ Falias 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>+ F+ S6 }& i: x. b
</div>! F" @: Y; {0 @
<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>1 Z  y& {+ G% H& m1 K( {
<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>
9 q8 D* T, L* U* D<div class="cnblogs_code">
$ r1 o/ ]: a; A4 c( l<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> ka webapp_pod.yaml, `- N" A6 \9 B9 R( t; X- q# o& D' G
pod</span>/<span style="color: rgba(0, 0, 0, 1)">webapp created
3 t  v& |- D$ D+ v$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> kg pods7 T" }1 y8 L9 k& W
NAME     READY   STATUS              RESTARTS   AGE" f) L" A  }0 Z- ^5 l2 L
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)">          7s
$ X& @% @5 @* [9 n9 f( f3 `. I$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> kd pod webapp) _  P6 s& ?, I+ X/ ~2 T6 ]4 l
Name:         webapp
' j  D( y& v: R% [( G8 B, X3 w* sNamespace:    default/ M4 A! G6 y7 D. p' ?
Priority:     </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">: L$ L# g. p" M, ?7 V) }
Node:         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)">. s+ Q+ _5 q: P/ N( O
Start 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)">
! q6 E& U8 M* e/ Z# n! P/ |7 WLabels:       app</span>=<span style="color: rgba(0, 0, 0, 1)">webapp& i3 p9 P: `" ^% l6 }
Annotations:  </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">: y, F8 |" ^* m# o2 N$ ]
Status:       Running* F0 f$ D* i* Q$ k6 D8 Z2 K
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)">  w2 T9 u" P: G* z6 R0 ]) n" x
IPs:, B/ n3 s) i6 M4 j7 }
  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)">
) N+ O8 c- P! P4 v! ]$ dContainers:: i9 B* b3 `; S( G0 i, f
  webapp:
: J) w. B4 s5 @$ U$ b    Container ID:   docker:</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">d9ddf9dd47de12b53f2119bf75df6706bee2e7711509638ad52adc9addeda704</span>
5 `* J* g3 V/ S( Q7 y    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)">6 ]& O1 f7 R* T+ Q7 T
    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>
1 c5 R3 G+ ^3 i& L% A4 [8 q) O    Port:           <span style="color: rgba(128, 0, 128, 1)">5000</span>/<span style="color: rgba(0, 0, 0, 1)">TCP
* b3 q; o% s3 [- ~% W& |    Host Port:      </span><span style="color: rgba(128, 0, 128, 1)">0</span>/<span style="color: rgba(0, 0, 0, 1)">TCP
+ m) m8 a3 V( G# I/ f7 b0 ]" [    State:          Running
8 }, e: i# u2 G: y$ b) t      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)">6 L+ P7 \8 p! S+ s! o
    Ready:          True
3 [, q# N& Q) N: C( T% F    Restart Count:  </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">
- _) W+ X, K/ }8 n    Environment:    </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">! X' M, X4 V- s# g2 x* @
    Mounts:/ e' T3 ^! [9 W! S4 {3 |0 g
      </span>/tmp from webapp-<span style="color: rgba(0, 0, 0, 1)">logs (rw): R$ d- o4 c* R# v7 @1 C! f
      </span>/var/run/secrets/kubernetes.io/serviceaccount from default-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h (ro)
8 [; C  |/ N3 n; y* a  busybox:3 E& E8 E" H) p" P# A
    Container ID:  docker:</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">6a6a35a628a782fc643af3dd49986bbc77c23de1ae4726bc521c77f61abbbf5d</span>
) \4 W; l2 \. j1 w; H5 u2 K<span style="color: rgba(0, 0, 0, 1)">    Image:         busybox
& ]( C3 J- N5 M+ c$ E0 X6 l* X    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>
' }  J3 O* |  Z    Port:          &lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
( p* V- X" I$ S# L& _    Host Port:     </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">3 @( k, k" o9 S! }# g
    Command:
& s& a( o9 v" h( N" `      </span><span style="color: rgba(0, 0, 255, 1)">sh</span>
& V$ s5 L$ r: _. c6 t, k      -<span style="color: rgba(0, 0, 0, 1)">c. }$ n9 s: o8 |% W; n
      </span><span style="color: rgba(0, 0, 255, 1)">tail</span> -f /logs/<span style="color: rgba(0, 0, 0, 1)">log.out) B6 y" u* l' Q" S
    State:          Running
3 c' ^* i- i* N1 F      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)">3 Y/ n) m1 ^9 |) u; T
    Ready:          True: v. }. u- Y5 g' R' ^
    Restart Count:  </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">
( T! [" X' \8 |4 a; G- R    Environment:    </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">$ @( m/ g) ?4 a. I+ Y
    Mounts:
3 p: O" t" W+ `+ g! {" p, n) H/ U      </span>/logs from webapp-<span style="color: rgba(0, 0, 0, 1)">logs (rw)7 X- d6 U/ F( E
      </span>/var/run/secrets/kubernetes.io/serviceaccount from default-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h (ro)# W% Y6 Q  ?( J4 C
Conditions:
+ F4 f5 d) |5 f7 ?& ~2 i8 }3 \$ w  Type              Status) m9 F. G8 e# Z
  Initialized       True
. f: |, ^* A5 G  Ready             True% |) P1 r' J; Y2 V& i
  ContainersReady   True, K# I0 F& m9 ~- x0 y
  PodScheduled      True
: {. j, z2 r. A1 L  D5 wVolumes:; U5 m' v2 |5 [0 W/ w* i) s+ D5 r
  webapp</span>-<span style="color: rgba(0, 0, 0, 1)">logs:. `% Y8 }7 A9 x/ R. C& W
    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>
7 g. e' Q! ^) k0 J* ^<span style="color: rgba(0, 0, 0, 1)">    Medium:
! P& ?" o4 n+ u/ p) `    SizeLimit:  </span>&lt;unset&gt;<span style="color: rgba(0, 0, 0, 1)">& U# N- r- T# I0 n1 v
  default</span>-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h:
0 g2 j) P9 W3 W    Type:        Secret (a volume populated by a Secret)- t8 G2 h6 f9 q2 i& Y! ^
    SecretName:  default</span>-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h$ L' Q. Q0 S4 m' G7 S; X8 K4 W* z
    Optional:    </span><span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)">
  a0 D! c4 z6 }; X: N; rQoS Class:       BestEffort1 V, t: L, A  c0 \
Node</span>-Selectors:  &lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
( `3 \% r$ }4 j( d& H7 W& `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
0 W% |) x; ~. N' _- H                 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
8 f- D" I8 s7 y" s8 A  C6 `% d0 AEvents:/ K9 p# g$ U1 Y. W+ X' J! C' b
  Type    Reason     Age    From               Message2 F7 t8 ?1 H, B; F* L9 o7 |
  </span>----    ------     ----   ----               -------<span style="color: rgba(0, 0, 0, 1)">/ S* c& Y( d5 ~. L6 f8 F- t4 e" h' Q
  Normal  Scheduled  2m23s  default</span>-scheduler  Successfully assigned default/<span style="color: rgba(0, 0, 0, 1)">webapp to ayato( \. I7 h" `2 \( 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& H  x4 p/ M! Z  [7 H' z( V8 U
  Normal  Created    2m21s  kubelet            Created container webapp' A0 [# }7 a' V6 b
  Normal  Started    2m21s  kubelet            Started container webapp
, Q* s8 X, i0 `6 U  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)">; q0 u9 m# a- f9 ~! z+ D
  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)">.633078305s7 K; p; ]& ]2 |- H
  Normal  Created    15s    kubelet            Created container busybox
& L& Z6 C* N4 ?% W9 @- \/ M. D7 v  p4 U  Normal  Started    14s    kubelet            Started container busybox</span></pre>
% n! e) r7 ~. m5 H8 w+ w</div>
# ?. O5 n8 B) E% m<p>真的是飞一般的感觉!!!</p>0 |9 N1 f' c  Z
<p>&nbsp;</p>
7 g+ e4 p  c7 t<p>三、Context和Namespace切换</p>/ K; j# q; E5 @  Y: D3 g
<p>我们在公司的容器平台上使用kubectl时,经常需要切换context和namespace,导致命令非常繁琐,那有没有简便的方式呢?—— kubectx</p>/ ?. U* ?1 u7 u0 C5 ]$ J& o3 B
<p>kubectx安装</p>
9 v4 \0 s' M7 }; s9 l; W9 S5 R<div class="cnblogs_code">
. g5 m9 Y. B4 k; ~& G<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>
# m/ o8 U% n7 ?6 ?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)">...+ L  {/ I& y1 O. Q8 d( b4 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)">.
7 g( q. i; G$ ]3 S3 Z# \/ k1 K& `" U! Eremote: 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)">.
7 r' C; ]& A: p+ b8 `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)">.  H, U1 Y) a% a. \+ g
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)">( l! s# l2 d  d2 b% T
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 i0 y. W9 T/ R0 q# ~' @
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)">." U& P3 Z4 d+ i: k3 ^/ o
$ </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)">ns3 S# j$ f3 N; f# i8 A% U& L
$ </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>* C3 V8 V) k( {3 G
</div>8 i9 r. C1 [% V) Q: {
<p>我们来看一下效果:</p>
7 r1 m, j, q$ J2 \- \8 o<div class="cnblogs_code">
) C/ m5 Z5 i0 Q$ ~# g& V  |<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ctx
& E) p# Z) e% c# q- B) d, Q( Bminikube
* P' s9 }0 n$ @8 O! a, w  S) L$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ctx minikube
8 r% p# h" D. t* ]5 o; i( NSwitched 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)">.* B, k. v' M9 n" a; O' ^3 r  \
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ns
' G9 K0 \! S+ |6 J* ~$ pdefault: o8 ^4 }! z4 J  Y' [' L" H7 |
kube</span>-node-<span style="color: rgba(0, 0, 0, 1)">lease1 l' f" L: j$ y" B/ u% K
kube</span>-<span style="color: rgba(0, 0, 0, 1)">public
/ D) [) M- R1 t+ hkube</span>-<span style="color: rgba(0, 0, 0, 1)">system
3 ^7 o$ y: f' \5 okubernetes</span>-<span style="color: rgba(0, 0, 0, 1)">dashboard+ i( ?! t+ ~& D! V
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span> k ns kube-<span style="color: rgba(0, 0, 0, 1)">public
3 N5 G8 }0 o4 p* M# C" ^/ ^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.
7 i/ _2 c& E. ]  U& @8 l. @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)">.
1 u' I+ {( D/ j% W. t/ }' M$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ns default0 x; r" b- D8 Y/ s
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.( t6 t$ Q5 ~; f* R+ L
Active 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>! \4 q- a" w/ x+ g
</div>
) x% q% f* E* Q/ P<p>&nbsp;</p>
2 ]! n6 N) P7 Q- ~. W<p>四、跟踪查看多个Pod的日志</p>
1 F- ^- C* Y2 ?  {' j' K<p>我们一般使用kubectl logs命令查看Pod日志,但是它不能通过-f参数同时跟踪查看多个Pod日志,这就不方便了,毕竟实际生产环境中每个服务都会有多个Pod,这时我们可以使用stern这个工具,它具备如下能力:</p>
8 I$ `2 P& ^6 ~) h+ M1 `2 h: s( P<ul class="list-paddingleft-2">
% d1 A* I/ r( g1 e<li>
) f( A9 j' q' |4 r9 E6 b<p>允许使用正则表达式来选择需要查看的PodName</p>' Y- {9 e! q. o; ~' F0 _8 j7 Z$ g
</li>0 J$ q. s; ?: k7 o8 U# P
<li>
8 c' J/ \" Y% Z# X<p>为不同 Pod 的日志展示不同的颜色</p>& M* b$ c) |8 X9 N3 m$ P4 d
</li>
( V" b* x# H9 }! D4 N. v<li>. \$ g5 ~5 `5 Q" c# f
<p>跟踪日志过程中假如有符合规则的新 Pod 被创建, 那么会自动添加到输出中</p>
( G. b. e+ {8 q</li>
+ x( |5 R+ ?  S/ ?</ul>
$ B7 ^: e2 [! Z5 e5 P3 j2 ?, G/ y<p>首先安装stern(下载stern时可能较慢可以多试几次):</p>
. F5 l. B/ C0 f, N3 `4 P<div class="cnblogs_code">
1 a: \. ]+ M8 ^/ i* i/ X- K<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>
' o2 _3 w. ]9 k# {, E% `<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 {7 ~7 e8 b, O; Z" U( s4 I
<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>' Q" ~* z, u" l7 x( P, P- b% J
</div>
0 f3 o# t% w. J% f  w2 y$ ?<p>安装完毕后让我一起感受一下stern的魅力吧,我的Pod里面有两个容器:webapp和busybox,如果使用kubectl logs 还得指定具体的容器,而使用stern就没有这样的限制。</p>1 z2 L. G  w/ D$ v5 o
<div class="cnblogs_code">$ h; a) }7 O7 {& U
<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)"> .
; i8 g5 Q( ^- ^( |  m. D0 ~' M</span>+<span style="color: rgba(0, 0, 0, 1)"> webapp › busybox* s# k, ^- D+ @
</span>+<span style="color: rgba(0, 0, 0, 1)"> webapp › webapp% Z. _8 L# }: Y: X! |0 G
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)">]
: w- F5 _% P8 ~8 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.200</span><span style="color: rgba(0, 0, 0, 1)"> [INFO ] [main] [org.apache.catalina.core.StandardService] Starting service [Tomcat]
: H4 j" @( Y/ U' {' S: F$ |; K* L, Jwebapp 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)">]
+ G8 n( U3 n8 E' Kwebapp 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* L* v  X0 I+ Y( {4 X1 ^/ ?. v
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.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
* V3 l! F( @$ e& l/ Ywebapp 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)">
) V9 V# V/ p6 v% ^) a5 Y$ p" G! Y! Dwebapp 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)# u0 a$ \5 }# C0 ?6 j/ {) b; P
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)">]
1 O  r0 o% I, C# E7 h9 e& z! 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)">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)">- m; {- Q& ]0 W' E
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)">)! a! V% E- I, u# M% R
webapp webapp
6 F2 T" u" ~9 y: w, uwebapp webapp   .   ____          _            __ _ _! N; C5 g' x9 x; @# |+ u* a% O
webapp webapp  </span>/\\ / ___<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">_ __ _ _(_)_ __  __ _ \ \ \ \</span>
) Y0 H, v- P3 ]2 h/ b  owebapp 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>
# x+ g7 q# e& b+ f: a5 z* owebapp webapp  \\/  ___)| |_)| | | | | || (_| |<span style="color: rgba(0, 0, 0, 1)">  ) ) ) )8 o: q$ p7 A, b+ U6 q' M
webapp webapp   </span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">  |____| .__|_| |_|_| |_\__, | / / / /</span>
( L$ B: f5 g. q2 y* k# l- B' ^/ Ywebapp webapp  =========|_|==============|___/=/_/_/_/<span style="color: rgba(0, 0, 0, 1)">1 [% E% w- S+ ?
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)">); b  E3 }# \* L2 [7 l, ^* a  v
webapp webapp
* c3 r/ a3 j+ H" I, lwebapp 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)
" L3 F% F1 u/ w3 @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.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
: i# y8 U1 z5 m1 H' ]/ 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.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)" T2 f. y# w. m+ P: _  \* D4 z8 A
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.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)">]
9 s9 ?- ]6 ]  h; Xwebapp 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]
$ v- z" O! ~4 A5 b* W7 j- ?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) w  J# \1 a+ H1 w
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
3 U/ }  i& A' r- ?3 dwebapp 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! p" N- p, i2 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.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)">
7 E3 f' ?4 Z, P2 y+ e6 `; Y- Swebapp 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)
; [8 S+ _, Z+ C: n. q# Z6 V2 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.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)">]
- _* J* \/ k" \# I' S- \5 {" 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)">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)">+ R/ x2 s: Y+ V7 \) }6 p% H5 x
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>
5 U" J" f' J) J+ a</div>
* _/ J6 g( D2 b  w<p>&nbsp;</p>- W1 r1 l0 K* p4 {: f1 B& ?2 j8 C3 s
回复

使用道具 举报

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

本版积分规则

手机版|飞雪团队

GMT+8, 2025-7-3 10:51 , Processed in 0.068685 second(s), 22 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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