飞雪团队

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

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

[复制链接]

8061

主题

8149

帖子

2万

积分

管理员

Rank: 9Rank: 9Rank: 9

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

! F7 W3 r$ O- Q6 q: p, L<p>kubectl作为我们主要的操作K8S的工具,其具备非常丰富的功能,但是如果不经过打磨,使用起来还是存在诸多不便,今天我们来看看如何将我们的kubectl打磨的更加易用。</p>$ f& \% W- J  a* A8 A
<p>&nbsp;</p>
7 M4 Y' i. m: l<p>一、命令自动补全</p>
0 H* M$ y4 N9 D" U& `! @, A- ^<p>kubectl中提供非常多的命令,如果每一次都要手动一个字符一个字符的敲未免太累了,那么如何配置自动补全呢?这里以ubuntu系统为例:</p>
$ E; _6 b+ ]# Z) l1 T2 `7 }% i# e+ }<p>1、安装auto-completion工具</p>
4 T$ p( r( V1 o- r<div class="cnblogs_code">
2 ~/ y8 w- d9 t% p5 \8 X<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> apt update
4 S/ d, u8 J9 S8 g  j5 j; ~/ gHit:</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>* [* M8 Z! p6 Q. ~0 r5 g* W+ @
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>" W# \7 x, |. ~) H6 x0 z9 l
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>& i6 x% G/ j; F, B9 t
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>
2 [4 N- g$ M( T5 }0 I+ A" N0 M3 eHit:<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>
" b# _5 F1 h2 h; B& [3 Q  ?  c<span style="color: rgba(0, 0, 0, 1)">Reading package lists... Done+ D8 ~* ~& Z! Z, t: k# j" ]
Building dependency tree
+ m* W. d4 s& D3 D$ R% _Reading state information... Done+ b2 |6 B) P7 y) i0 I( _& j
</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# `" V% j& P  J: d
$ </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, S* g' D1 S/ P- `
Reading package lists... Done1 p6 @5 v1 O4 G% J$ W9 }  V4 T
Building dependency tree# V  N5 J3 d. m0 }0 _- Z: O
Reading state information... Done
: p- G% R" ?5 w- `* c& Nbash</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).
0 S& _% t5 ~8 F+ b: s3 u& 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>2 Y; M, d( I, |& |
</div>
$ W( y# A/ l. Q- a/ Q' T6 d5 M, P<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>! X- m4 @& z1 L/ |
<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>7 k# i+ I1 b0 `2 v
<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>$ `; d% i( F6 v. e  D
<div class="cnblogs_code">- P5 Q# y) ~/ f8 g+ i
<pre>source &lt;<span style="color: rgba(0, 0, 0, 1)">(kubectl completion bash)6 b! z4 ^+ Y* c  }' E7 |+ l( T' ]
</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>
( T; Z8 z7 c  f. o' u" Y</div>
7 X# Y  W1 s$ W$ t; Q# Q2 l<p><strong>Zsh</strong>:</p>! W* I7 L4 L6 p( W. a( F
<div class="cnblogs_code">5 z3 b& o  X3 R9 r
<pre>source &lt;<span style="color: rgba(0, 0, 0, 1)">(kubectl completion zsh)
; U; s5 _  [+ ~# O1 W</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>8 j, R+ A+ `; }# G7 ^
</div>
9 _0 a' Y& l" J; ^9 X1 e<p>配置后就可以通过Tab键自动补全命令啦!</p>
+ C$ c2 n7 S/ D! q9 A<p>&nbsp;</p>
$ [# p* U3 g' w% F<p>二、配置kubectl别名</p>7 @. T9 T8 p" V9 J2 e; R
<p>我们可以通过设置别名简化kubectl命令,编辑.bashrc文件,添加如下内容:</p>% ^% B4 u$ V# w) [8 e! J, W" C' T
<div class="cnblogs_code">2 h% [+ o1 _* N) ~) W- v# {
<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)">
: e( l  H4 s* C; @! M  ^  \# Q" c- salias 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)">4 P! h, u; W) v8 ?3 s( y
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)">
( ]1 g: e5 L4 Ealias 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)">; k* A% L$ p& J6 T0 s' p
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)">
' b7 {5 ^3 ^& s! [3 K6 \, Calias 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: v  O8 y* B% n, q. ]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>
+ U! f2 G4 G& J$ Q5 I</div>
* o% c$ V8 o; W<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>' _/ g% h& ^0 ], w0 u
<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>
# c( @% I" D% h; }0 s4 `6 V; F<div class="cnblogs_code">
: o+ t) i' _: ?' n<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> ka webapp_pod.yaml# Q; I  G; Z; b1 F7 _" `
pod</span>/<span style="color: rgba(0, 0, 0, 1)">webapp created
7 ]+ W3 W9 W$ S( t( q$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> kg pods' S- ^- O3 w& ?9 N
NAME     READY   STATUS              RESTARTS   AGE
  T, a& w7 T* e! b. q7 P* `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' L7 _& @: e/ ]5 [$ `$ C% z7 A
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> kd pod webapp2 h5 c3 ^! e8 P2 {9 g
Name:         webapp
8 V# q! E$ ~" W4 Y3 xNamespace:    default' h4 j' n1 F8 n9 n4 t9 w
Priority:     </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">, z5 X  H+ a% y7 i7 F# t
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)">
1 [% z7 u+ z& V; ~  {3 x7 sStart 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)">! b" x  S8 o. x3 X  u& _
Labels:       app</span>=<span style="color: rgba(0, 0, 0, 1)">webapp/ c& y5 A- c. R1 R' B8 Y
Annotations:  </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
9 p  T+ x* Z. i; _& I% k  cStatus:       Running1 s5 M8 Q# s7 }
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)">1 ?$ c. O4 _2 N+ I% ], w
IPs:
% w; u4 P1 j# l( ^  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)">
. H# L5 i1 \7 Q. W* G2 M4 H' B# `' KContainers:
# l# E  |. f1 [) I9 ^% ]  webapp:2 T9 k% p) S% X
    Container ID:   docker:</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">d9ddf9dd47de12b53f2119bf75df6706bee2e7711509638ad52adc9addeda704</span>$ {7 c+ ?9 P4 U$ r
    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)">
( I6 _, D; @* G8 D, q    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>
- T, p0 G; k$ b. L. O2 C4 s0 x    Port:           <span style="color: rgba(128, 0, 128, 1)">5000</span>/<span style="color: rgba(0, 0, 0, 1)">TCP6 S8 Z0 Y4 g5 n% k6 x6 ?+ J3 u/ v
    Host Port:      </span><span style="color: rgba(128, 0, 128, 1)">0</span>/<span style="color: rgba(0, 0, 0, 1)">TCP
( f- k- z1 s8 b2 w    State:          Running1 Q3 e  ~5 K! Z& J  y* L
      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 l) c* a3 l; [6 @4 m
    Ready:          True: }3 z$ y9 v0 Q/ g& v% @
    Restart Count:  </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">
! d/ n/ t4 a1 n3 `/ \    Environment:    </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">5 p5 N4 C; m* m& a* a, b
    Mounts:
0 }$ ^9 w7 V" K6 }4 @% ^      </span>/tmp from webapp-<span style="color: rgba(0, 0, 0, 1)">logs (rw)4 t/ N: {% C. u. E7 V$ l1 w
      </span>/var/run/secrets/kubernetes.io/serviceaccount from default-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h (ro)
# O- m6 ]% K  H  busybox:1 t0 ^. q7 t: J6 k
    Container ID:  docker:</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">6a6a35a628a782fc643af3dd49986bbc77c23de1ae4726bc521c77f61abbbf5d</span>$ V1 B. p3 q! b) B
<span style="color: rgba(0, 0, 0, 1)">    Image:         busybox
& E; P3 Z0 Z% E    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>3 _9 |1 q$ W4 F) n% f
    Port:          &lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">2 n# R4 _9 P8 R
    Host Port:     </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">3 }2 j4 ?( B, Y6 I
    Command:
' D& C. K+ @; f0 ~" W3 [; J! z  ~$ k      </span><span style="color: rgba(0, 0, 255, 1)">sh</span>
# S* x( B4 S& q7 l+ s" k/ @2 b      -<span style="color: rgba(0, 0, 0, 1)">c! x# r  t* f: {
      </span><span style="color: rgba(0, 0, 255, 1)">tail</span> -f /logs/<span style="color: rgba(0, 0, 0, 1)">log.out
9 |9 F8 j1 m7 k    State:          Running  u( u' U& M( J. f5 b
      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)">
+ w% W0 C+ V9 ^8 g3 P: z    Ready:          True2 A2 j6 I! @8 ]$ k5 u
    Restart Count:  </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">/ N  ]8 n2 m3 j- c
    Environment:    </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
. _$ i& Y- V2 Y& T/ k* i    Mounts:/ s' t$ d8 Y# R! _2 U
      </span>/logs from webapp-<span style="color: rgba(0, 0, 0, 1)">logs (rw)1 V5 K) I! S4 k9 K' j. C
      </span>/var/run/secrets/kubernetes.io/serviceaccount from default-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h (ro)
/ I; g, n' L; t! D! RConditions:
" G6 s. B3 e, y# V# Z% s  Type              Status+ r, v% ]9 M9 K& B: A
  Initialized       True
+ B( [; K6 _8 S+ d' k! J, ]) I  Ready             True' h) R/ [; C& R1 b
  ContainersReady   True
" c% A6 Y$ y0 K3 \  PodScheduled      True
3 W) T  @4 h! G( uVolumes:7 ]; F5 _9 R- [# b8 j+ g
  webapp</span>-<span style="color: rgba(0, 0, 0, 1)">logs:
$ v, R9 d: O7 `9 ?( c* j9 Z# M2 j2 d    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>6 X9 |) v$ y4 y: {
<span style="color: rgba(0, 0, 0, 1)">    Medium:1 z9 T$ U& [3 z! i/ g, s
    SizeLimit:  </span>&lt;unset&gt;<span style="color: rgba(0, 0, 0, 1)">/ C: ~3 y7 b, T
  default</span>-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h:! g8 U' N( i4 k; p5 q
    Type:        Secret (a volume populated by a Secret)- V" t: s; A6 H) z( H7 O  t: _# l+ C0 O
    SecretName:  default</span>-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h
$ O$ f: V, K! I2 ~3 x/ |' z    Optional:    </span><span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)">( V) m  ~2 _) P/ v. n+ E
QoS Class:       BestEffort: n! K7 T4 S  l  a; V( W& q) D
Node</span>-Selectors:  &lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
! j- ~! J4 G2 W4 v# l& tTolerations:     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  i5 m! L" [5 y5 l6 r* t- G$ S
                 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
& h, E7 c( C+ ?& oEvents:
3 H# {8 N8 \) h$ c  Type    Reason     Age    From               Message) z% l5 u" n0 i6 I; M
  </span>----    ------     ----   ----               -------<span style="color: rgba(0, 0, 0, 1)">* c* H5 F/ k$ a5 r  M7 X
  Normal  Scheduled  2m23s  default</span>-scheduler  Successfully assigned default/<span style="color: rgba(0, 0, 0, 1)">webapp to ayato
* f- v9 b2 ]8 ]  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; t$ z! y! u+ v& T
  Normal  Created    2m21s  kubelet            Created container webapp
2 l5 J& h7 @4 a# Y% h& Z8 O  Normal  Started    2m21s  kubelet            Started container webapp
2 p1 j$ T8 a' y' I  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)">
4 D$ N# Y- V7 A+ m* |4 F  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
% v8 U3 _2 C- z  Normal  Created    15s    kubelet            Created container busybox
7 F2 Y- c" _; p' T! `) P) I5 ]  Normal  Started    14s    kubelet            Started container busybox</span></pre>- l0 r/ m0 N$ E# {+ j# G( U
</div>/ f" e/ |5 }& N! y& U3 v" M& u
<p>真的是飞一般的感觉!!!</p>$ J7 [6 k# r: I# r+ p7 k$ n
<p>&nbsp;</p>5 P/ _/ x* j8 l# k
<p>三、Context和Namespace切换</p>6 y. e/ O0 l4 K  c+ X
<p>我们在公司的容器平台上使用kubectl时,经常需要切换context和namespace,导致命令非常繁琐,那有没有简便的方式呢?—— kubectx</p>1 m9 r0 d) ?, ]
<p>kubectx安装</p>1 \4 ?/ c3 U0 s1 t3 F
<div class="cnblogs_code">
/ T1 T. K9 G. A: |$ C<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>
* j8 }9 o6 I/ H4 h  I; F- G8 iCloning 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)">...& \5 R* h% G' c8 @" R
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)">.
8 V, q9 G* B4 g. X% E3 L$ wremote: 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)">.2 R) p% @6 B; _& f. a5 ]
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)">.3 B( {2 l! g3 E' y! ~
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)">
5 g/ J0 [" _. _2 h  }( d& K+ ]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 D  ]4 ^  j2 b& i. ]2 U
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)">.
1 n+ Y/ ?% }3 Q# t+ f5 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/kubens /usr/local/bin/kubectl-<span style="color: rgba(0, 0, 0, 1)">ns- G) P4 c1 o, S& Z
$ </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>5 D% o* C  l* F3 }
</div>
. `5 B* g/ F. p0 J<p>我们来看一下效果:</p>- C" @/ Z3 S3 D2 f& }
<div class="cnblogs_code">
# B) t7 |: N$ y1 A* P+ f2 }) f<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ctx8 s2 T6 h  y- L
minikube
) E4 q* P. V1 N: P2 L/ F" v$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ctx minikube
+ g& R3 q. g/ t! ^) B% K% S) z  i  rSwitched 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)">.
; S0 U7 O" K+ l: U" V* x$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ns% j# g8 r. k  S1 Y7 \/ v
default
5 w3 O2 L, ]5 r; p) L2 {kube</span>-node-<span style="color: rgba(0, 0, 0, 1)">lease
, R- D6 |+ J0 a# S5 Z& ?  H& [6 z2 w! Vkube</span>-<span style="color: rgba(0, 0, 0, 1)">public
. L/ B( A5 W' \/ Wkube</span>-<span style="color: rgba(0, 0, 0, 1)">system
: k& E0 R- ?' l6 Y3 j2 vkubernetes</span>-<span style="color: rgba(0, 0, 0, 1)">dashboard
: K. b" E0 e! _- n$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span> k ns kube-<span style="color: rgba(0, 0, 0, 1)">public
* q4 z; H9 s( v7 M; nContext </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.  W) F6 S. z- {4 ^$ {7 w- r
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)">.+ J% u1 h5 a! [6 f( E) H
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ns default
# g. }6 G0 T  s) g1 yContext </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 a; H7 @9 U! o+ I
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>1 l5 D5 u/ o/ v1 {$ l
</div>
9 L* m6 f' {4 `2 V9 i<p>&nbsp;</p>
' g/ Y7 W- X* n) [' h# @, l<p>四、跟踪查看多个Pod的日志</p>8 Z8 Q5 _; d5 l, v3 s# V0 ]6 Q
<p>我们一般使用kubectl logs命令查看Pod日志,但是它不能通过-f参数同时跟踪查看多个Pod日志,这就不方便了,毕竟实际生产环境中每个服务都会有多个Pod,这时我们可以使用stern这个工具,它具备如下能力:</p>5 K/ i# x  ^" `% F; M% w
<ul class="list-paddingleft-2">
9 o# u+ |# I, d7 f, z4 ^, t: h<li>
1 P7 }' E0 w& ^$ R: }8 j- N4 N; S8 W. B<p>允许使用正则表达式来选择需要查看的PodName</p>
. x% }2 D' q. f4 K5 P</li>
$ ~! k* n. F9 g<li>
. j+ s4 c8 }1 r; e" N, e<p>为不同 Pod 的日志展示不同的颜色</p>$ |' v6 N. f) k7 R& ?- o
</li>
9 h; c  @. I4 x  x& ?<li>& L8 `) i: m) f
<p>跟踪日志过程中假如有符合规则的新 Pod 被创建, 那么会自动添加到输出中</p>
; l$ q2 N$ i, b/ w5 w* w5 \; q</li>% P2 e' J3 O7 i2 A* z
</ul>& _# g& ~2 ~- H& \4 j3 X8 z
<p>首先安装stern(下载stern时可能较慢可以多试几次):</p>
" |) z: ^# O0 s9 f: Y, C<div class="cnblogs_code">
7 Z3 A0 l3 B6 @# 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>
3 _4 M, ]& @# [  _2 u$ t<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>
- T3 _+ }" c1 J6 n2 @+ \. B<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>
7 S% F4 t$ j* X</div>4 I% a' n9 \" _/ g- b
<p>安装完毕后让我一起感受一下stern的魅力吧,我的Pod里面有两个容器:webapp和busybox,如果使用kubectl logs 还得指定具体的容器,而使用stern就没有这样的限制。</p>
' Y* U9 [! j: u$ }4 B<div class="cnblogs_code">: v2 `1 J4 F" |, ]
<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)"> .
9 }. a, F' L# I5 h1 r2 X</span>+<span style="color: rgba(0, 0, 0, 1)"> webapp › busybox! c6 a0 G( e8 v" {/ }% D
</span>+<span style="color: rgba(0, 0, 0, 1)"> webapp › webapp
! a: @# |; b. y+ g  J7 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.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)">]4 c- L0 A7 R2 m& \1 }
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.200</span><span style="color: rgba(0, 0, 0, 1)"> [INFO ] [main] [org.apache.catalina.core.StandardService] Starting service [Tomcat]9 u5 D2 g1 Q3 W
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.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% f3 b9 j# ]$ g/ Lwebapp 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 WebApplicationContext2 \8 Q/ g7 L5 v2 A4 n' g% [) 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)">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
0 z! D& t9 O0 A0 h- 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.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)">
9 n  V4 ~9 L/ d6 J& r$ x3 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)
- Y  Y+ H& p4 Y9 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.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 A3 u% s4 Z4 j* ]& \" M
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)">9 H: @, ?) n& H1 ~9 d
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)">)/ y3 J0 N# C6 ^4 ]/ `
webapp webapp
1 _; I: `) o. Q& J* H: w( Hwebapp webapp   .   ____          _            __ _ _
  b2 Y: x. R9 g( N' K" Fwebapp webapp  </span>/\\ / ___<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">_ __ _ _(_)_ __  __ _ \ \ \ \</span>/ J, I( h. F/ l5 L
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>' M# P) B8 y2 c2 a+ W- V2 J8 u
webapp webapp  \\/  ___)| |_)| | | | | || (_| |<span style="color: rgba(0, 0, 0, 1)">  ) ) ) )  H' u6 {, {. K/ i3 G
webapp webapp   </span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">  |____| .__|_| |_|_| |_\__, | / / / /</span>
! _0 X7 F% M0 W% bwebapp webapp  =========|_|==============|___/=/_/_/_/<span style="color: rgba(0, 0, 0, 1)">
# t! b) E" f, X3 W& wwebapp webapp  :: Spring Boot ::                (v2.</span><span style="color: rgba(128, 0, 128, 1)">4.2</span><span style="color: rgba(0, 0, 0, 1)">)+ u! N2 g6 t& I! e) A6 f0 h
webapp webapp8 r( W+ m2 D! t% X4 j: U
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 G$ j( l, N6 V& 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)">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, n3 p6 o: r8 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)">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)
7 V, \6 N6 B9 D! j) H7 F- 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)">]
: X; \8 m6 Q. P. 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.200</span><span style="color: rgba(0, 0, 0, 1)"> [INFO ] [main] [org.apache.catalina.core.StandardService] Starting service [Tomcat]
7 n+ y9 `+ |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)">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)">]
, h4 I+ w6 O- m/ Z) 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.324</span> [INFO ] [main] [org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/<span style="color: rgba(0, 0, 0, 1)">]] Initializing Spring embedded WebApplicationContext4 s7 |$ U" b# F. m# k2 B5 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.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! `* \+ S9 }; o  Q) `) 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.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)">' _) d6 q  S) C5 u/ G0 N2 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)">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)
9 z( l$ K# n' o1 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)">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 E- p: E8 H0 z, 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)">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)">; ]0 M. Q3 i1 d1 @& Q
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>
6 G8 K! K1 O4 J4 s; f; U5 j$ s' _* G5 \( |</div>$ F. \1 @" [' Y  `9 V" Q
<p>&nbsp;</p>8 N* U6 O( d5 f/ u
回复

使用道具 举报

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

本版积分规则

手机版|飞雪团队

GMT+8, 2025-12-16 11:04 , Processed in 0.073104 second(s), 22 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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