飞雪团队

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

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

[复制链接]

7249

主题

7337

帖子

2万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
24077
发表于 2022-2-12 14:35:42 | 显示全部楼层 |阅读模式
1 S) {3 Z1 E$ o1 l2 @
<p>kubectl作为我们主要的操作K8S的工具,其具备非常丰富的功能,但是如果不经过打磨,使用起来还是存在诸多不便,今天我们来看看如何将我们的kubectl打磨的更加易用。</p>
* i+ D* D9 b- h<p>&nbsp;</p>
% K( X4 a( s4 W<p>一、命令自动补全</p>4 M: P; g# o& Y) V
<p>kubectl中提供非常多的命令,如果每一次都要手动一个字符一个字符的敲未免太累了,那么如何配置自动补全呢?这里以ubuntu系统为例:</p>
" O* ~$ e- {4 D$ t& `" t<p>1、安装auto-completion工具</p>% Y+ i0 o2 @, X' A
<div class="cnblogs_code">
7 O# W2 `' L, F4 y+ K" T& ]# i<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> apt update
7 k3 P: T! ]! b, [& K, }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>
4 h. e/ Y7 X; g( ~7 C9 d! wHit:<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>4 x0 h" \+ ^5 M5 t$ p8 T9 F8 B
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>$ |2 I: d0 ~3 D, a( o$ y
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>
) o( }. x0 f) `' E" ], O. gHit:<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>0 `) L. v: H$ S* R8 I
<span style="color: rgba(0, 0, 0, 1)">Reading package lists... Done& l. X$ l( C  V+ `
Building dependency tree. J# Y8 ?& t& ]" ^/ e% y
Reading state information... Done6 v( x$ Y* J/ G4 V
</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.
2 J4 I$ K, D( A) d; j' L$ </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) b( @; N/ A. u
Reading package lists... Done
8 f- N! A' t' i( S: dBuilding dependency tree
0 V  e, H, u* CReading state information... Done  Q8 E8 @" g) F0 E: e+ o, G$ U
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).
9 _, b! M' S  O2 v/ W5 L) 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>
/ F' V, `" @' Z; E</div>! H& z  f8 ~* U( r' Q
<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>0 W9 f7 C( M! x: a3 W
<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>, m' Z! d% J+ N2 u
<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>% ^* @+ H( ~. k% X* b" O: n( r
<div class="cnblogs_code">1 w4 F$ N! h+ n2 m) k% s
<pre>source &lt;<span style="color: rgba(0, 0, 0, 1)">(kubectl completion bash)
1 [, h5 r, U4 h' @</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- M) a5 _+ v! J  D
</div>+ T8 {( R6 Z, I( w+ ~
<p><strong>Zsh</strong>:</p>
( _7 v' l' W; ^2 q7 y" Y<div class="cnblogs_code">& {: I- E, H# X$ B8 q
<pre>source &lt;<span style="color: rgba(0, 0, 0, 1)">(kubectl completion zsh)7 O2 }1 K+ H/ n' E7 \1 U, a
</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>! h* x1 a1 D6 d5 X9 C  e8 q! b5 f
</div>& T/ u) V! r( g/ Y
<p>配置后就可以通过Tab键自动补全命令啦!</p>& x7 c( j! w. z  d1 v$ C
<p>&nbsp;</p>. \( r9 T( j7 O7 J
<p>二、配置kubectl别名</p>& W$ E" C& N2 h0 `2 @! H
<p>我们可以通过设置别名简化kubectl命令,编辑.bashrc文件,添加如下内容:</p>" Y. u$ O# Y+ L+ m0 @2 r4 L: n
<div class="cnblogs_code">
# k$ f5 ~+ x' g  O/ w' W& n3 x<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)">' F- c$ {- h* R6 @( K+ t3 `- ]2 [+ D& @6 e
alias k</span>=<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">kubectl</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">4 \0 `0 B5 \6 e& H0 }
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)">
# `9 b! d5 z2 [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)">' q3 \8 r, y- m8 ^- J
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)">) y( c# `, h8 h$ G# q) a
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 y2 j5 J. q3 X. T/ U' N: J
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>
" `+ p0 G5 S7 i5 L2 M2 X</div>- L+ W, w/ i  Y; R' O& n( w3 {
<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>6 ]- @1 y) E2 q/ P
<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>
8 U2 D, _/ D' D<div class="cnblogs_code">
3 p' W) m- ?7 h<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> ka webapp_pod.yaml
/ h' H9 ]* b3 E; D; B' z$ H: Wpod</span>/<span style="color: rgba(0, 0, 0, 1)">webapp created, X% ^* ~; t( {. I, v) A3 G* l
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> kg pods* n) [- j- }+ U6 V1 }5 z1 i
NAME     READY   STATUS              RESTARTS   AGE
" C* v0 [  f& i- D6 A  owebapp   </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
% L8 n. \2 N* @9 v$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> kd pod webapp* o9 A- f: R! K+ ]1 q9 `9 J0 _
Name:         webapp( e/ s- n6 |( K: r& g
Namespace:    default+ T* ]0 M) F& j, G$ S
Priority:     </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">% t* m+ o) j" a, h! h! ^. A+ C
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 G" s! ^! T& i% {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)">
) ?3 ?% m! w! T* R# o& Y- ]& E0 A  S( jLabels:       app</span>=<span style="color: rgba(0, 0, 0, 1)">webapp
% p' b" [  L9 s' U: B. A: O; s2 BAnnotations:  </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">' C7 R; @/ J6 B5 u' L/ l1 B
Status:       Running
( v% c1 D6 L2 M1 GIP:           </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)">+ A$ m0 v3 z, k3 L: c
IPs:) J1 s! X, p0 R
  IP:  </span><span style="color: rgba(128, 0, 128, 1)">172.17</span>.<span style="color: rgba(128, 0, 128, 1)">0.6</span><span style="color: rgba(0, 0, 0, 1)">
9 z) ?. C% y/ P; ^" q" B( \Containers:/ I: R: g& X9 ^2 S, B. U
  webapp:
( O! y/ Q; u+ O, ]- H6 u    Container ID:   docker:</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">d9ddf9dd47de12b53f2119bf75df6706bee2e7711509638ad52adc9addeda704</span>
5 ^) O6 l) ]. e9 m+ p    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 t$ d  `) l6 P9 z: [; S    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>8 W0 N# I! `3 |) r" }  c; M
    Port:           <span style="color: rgba(128, 0, 128, 1)">5000</span>/<span style="color: rgba(0, 0, 0, 1)">TCP+ r. N5 W1 d' F: A
    Host Port:      </span><span style="color: rgba(128, 0, 128, 1)">0</span>/<span style="color: rgba(0, 0, 0, 1)">TCP: q; q! }& B* c% c7 c' I
    State:          Running( r; E1 i6 ~; u# Z8 ]
      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)">
* P8 O* u! U9 B1 h% F, f0 m" C0 N    Ready:          True4 H& r- V% W# }
    Restart Count:  </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">
+ V, a" B% ^8 C  c5 `: y6 ]8 L    Environment:    </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
! {3 s' L  o) W" M& ]2 E    Mounts:
7 T2 D8 Q# R2 R! m" }      </span>/tmp from webapp-<span style="color: rgba(0, 0, 0, 1)">logs (rw)
: a$ }, L' I2 h. ?      </span>/var/run/secrets/kubernetes.io/serviceaccount from default-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h (ro)
+ ]/ R' w" v, y0 p! U/ v  busybox:& K9 g0 C* |* O) P
    Container ID:  docker:</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">6a6a35a628a782fc643af3dd49986bbc77c23de1ae4726bc521c77f61abbbf5d</span>7 n: H; A0 O. H! c; ]# i7 n
<span style="color: rgba(0, 0, 0, 1)">    Image:         busybox
* b+ r# l8 R$ Q: u# x! B    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>
" S$ ?; P6 p# {- d% {$ C    Port:          &lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
' v$ ~; B) `. ~# C) \    Host Port:     </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
* h! }  _7 }6 t    Command:
8 w/ Y8 n9 B+ R  v      </span><span style="color: rgba(0, 0, 255, 1)">sh</span>
& \8 P/ O9 b4 [  `      -<span style="color: rgba(0, 0, 0, 1)">c3 e/ A, C% @1 B: H" }8 j
      </span><span style="color: rgba(0, 0, 255, 1)">tail</span> -f /logs/<span style="color: rgba(0, 0, 0, 1)">log.out4 ^& m; ~4 n6 E7 e& x* W
    State:          Running$ Z) }$ E/ {' ]( M6 m0 \3 r2 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)">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)">* z: v( d. e  P9 S' X/ V' u" b
    Ready:          True% p0 \2 x8 ]/ C" A* q: x1 V" r
    Restart Count:  </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">
* f/ d8 O  R* v$ L% m    Environment:    </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">7 ~! @# d  G0 t! a/ w1 s
    Mounts:
8 K2 B9 s8 [" q! @      </span>/logs from webapp-<span style="color: rgba(0, 0, 0, 1)">logs (rw)
" M/ H" C# k1 C/ \% U      </span>/var/run/secrets/kubernetes.io/serviceaccount from default-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h (ro)1 D4 g9 d/ j7 p+ Z3 s! k6 f; B
Conditions:; T. [8 h! a6 }+ M2 E6 l
  Type              Status3 ~* c! p/ \* M) @5 ~
  Initialized       True
0 r8 `! v+ ~! ?- w  Ready             True! ^( z# J" U, t# V  Z* T- Y3 V) c: y
  ContainersReady   True5 e0 M5 v( {# Q: m  ]
  PodScheduled      True- K! P/ I3 U! h9 u9 l6 q
Volumes:
& Y9 `1 K& _- b. t, U9 C% \8 v  webapp</span>-<span style="color: rgba(0, 0, 0, 1)">logs:
4 T% P- d, s0 m  D  u9 G    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>) s2 J3 D# ?1 g% I1 g+ J. p' x
<span style="color: rgba(0, 0, 0, 1)">    Medium:
) q8 C8 ~, M  c    SizeLimit:  </span>&lt;unset&gt;<span style="color: rgba(0, 0, 0, 1)">0 V8 g1 ^3 ?& u$ f4 e% t
  default</span>-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h:: y7 M$ h% S' K3 l
    Type:        Secret (a volume populated by a Secret)' F5 g( x$ |: `. B# k
    SecretName:  default</span>-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h
! B$ J, Y/ J  d0 Z9 q. N9 O! U: K    Optional:    </span><span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)">
1 P9 W, K2 R0 }  S0 iQoS Class:       BestEffort& d' [' G" D& T9 [$ `
Node</span>-Selectors:  &lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">* N% V  N+ B: a* r! m8 O* `
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
) |+ e% C* B1 U, G* A1 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
$ @$ g* i9 A/ W  P  A- {& wEvents:
7 {1 Y4 E* F  _: r  Type    Reason     Age    From               Message9 N  z) u& k. l3 D- z1 v
  </span>----    ------     ----   ----               -------<span style="color: rgba(0, 0, 0, 1)">
  T6 ?' k4 e: J2 e. w9 J  Normal  Scheduled  2m23s  default</span>-scheduler  Successfully assigned default/<span style="color: rgba(0, 0, 0, 1)">webapp to ayato7 F5 M! A! \  z2 h5 }6 t
  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' ~( x" ~5 b3 m8 I3 u6 w& _' ~
  Normal  Created    2m21s  kubelet            Created container webapp
- P3 `) p! Z0 q- x5 }+ |8 m  Normal  Started    2m21s  kubelet            Started container webapp7 n) c# E4 o  ^; }: p# H$ t
  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)">$ g' Z6 _& \4 k" z5 b3 h* [
  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& M2 L; R6 M& B# {
  Normal  Created    15s    kubelet            Created container busybox
/ _! l# h1 G1 z# T; m7 m  Normal  Started    14s    kubelet            Started container busybox</span></pre># d' K& x; O7 S
</div>; m( @% G& G) x
<p>真的是飞一般的感觉!!!</p>
. I5 A% }5 N+ @+ \0 m<p>&nbsp;</p>
8 K0 w& l/ Y+ T0 y/ D. ^<p>三、Context和Namespace切换</p>
( l$ u$ h' w, ?$ E( V) F6 }' q4 g<p>我们在公司的容器平台上使用kubectl时,经常需要切换context和namespace,导致命令非常繁琐,那有没有简便的方式呢?—— kubectx</p>
: A3 R& o  t" u# w8 Z9 T8 z4 p<p>kubectx安装</p>$ }( t, d0 J% h4 W6 s
<div class="cnblogs_code">
+ L5 D9 k9 h6 [$ X<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span> git clone https:<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">github.com/ahmetb/kubectx /opt/kubectx</span>
5 t% E$ e, i; D4 i) M5 `9 y2 E: jCloning 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)">...
8 b3 J* C' ?% Y+ Wremote: 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)">.
* \" v+ ~8 j. U8 n8 tremote: 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)">.
' y- c: ^; @: V; {- wremote: 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)">.: p+ i, N2 I7 `: e2 e1 M
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)">
8 L* P) U' H- j5 ^% ~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)">.
% ]5 t) P/ [) g/ _' lResolving deltas: </span><span style="color: rgba(128, 0, 128, 1)">100</span>% (<span style="color: rgba(128, 0, 128, 1)">817</span>/<span style="color: rgba(128, 0, 128, 1)">817</span>), <span style="color: rgba(0, 0, 255, 1)">done</span><span style="color: rgba(0, 0, 0, 1)">.& R  E+ w% ^7 g
$ </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
8 ^9 a4 P: X( k, z/ j$ </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>
; |/ }& M* J* M4 ]6 y# r  z2 B</div>
6 W4 o6 w/ D! l! @$ K/ `<p>我们来看一下效果:</p>
4 m/ n; K8 u+ ^) b$ y6 G<div class="cnblogs_code">
1 V; m" Z, g- y# j$ v6 s5 S<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ctx
- C; w2 k- Q0 p5 cminikube3 I6 M9 J/ v% c4 E8 u
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ctx minikube/ [6 a1 @: d$ \5 w9 h
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)">.8 ]1 c- N* b+ b
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ns
6 \9 @5 o. O: r' Y; O  r( fdefault
) U6 O! T5 O, E; Ykube</span>-node-<span style="color: rgba(0, 0, 0, 1)">lease
- Q) c1 s1 r  W1 l( tkube</span>-<span style="color: rgba(0, 0, 0, 1)">public, Q9 q4 m9 c! K+ k+ u" u: r1 x
kube</span>-<span style="color: rgba(0, 0, 0, 1)">system
$ m% R3 j! v' Z5 U4 o6 N# @( hkubernetes</span>-<span style="color: rgba(0, 0, 0, 1)">dashboard' Q6 k$ x5 ?, u5 s5 I* |$ @/ F
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span> k ns kube-<span style="color: rgba(0, 0, 0, 1)">public
% _% o6 {' I4 b, W5 MContext </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.
* F" }$ p/ N) P* H) ~7 P) j4 w% jActive 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)">.5 V4 I* u, k  N" W2 y
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ns default/ f. D% v+ v: Z& ~
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., n. C7 I5 L8 {$ S
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>
  r6 W( R, O! @# a  ]</div>+ Q" _# \8 y! C& @/ o4 W
<p>&nbsp;</p>6 x. g$ Z4 S( O: l1 n# \$ b
<p>四、跟踪查看多个Pod的日志</p>: t" y7 k4 g; D5 E
<p>我们一般使用kubectl logs命令查看Pod日志,但是它不能通过-f参数同时跟踪查看多个Pod日志,这就不方便了,毕竟实际生产环境中每个服务都会有多个Pod,这时我们可以使用stern这个工具,它具备如下能力:</p>+ ~! I$ t: n( s% v# g
<ul class="list-paddingleft-2">/ q. o: d, Z2 e" b1 F' `6 b: _3 _
<li>  @. j$ t+ s, \4 e1 [
<p>允许使用正则表达式来选择需要查看的PodName</p>
; W  R7 g; t' S9 H9 Z( S# [</li>- e( _+ w/ O! d4 x
<li>
2 Y. B- ^' ^! M6 h% g<p>为不同 Pod 的日志展示不同的颜色</p>
( t7 [/ x" }: ^' n</li>. w3 f$ s; M: h; P/ \* g! Q
<li>+ o5 Q8 V9 o) r" m: K7 f
<p>跟踪日志过程中假如有符合规则的新 Pod 被创建, 那么会自动添加到输出中</p>. s; u# d8 y3 N# p2 k2 e9 D# k
</li>- n5 e! ~4 d3 d4 V. a$ b* k
</ul>
& H" C9 K  C* g7 U/ }. Z/ b/ i  X* _<p>首先安装stern(下载stern时可能较慢可以多试几次):</p>
9 w: g( J5 |2 v& \" O- o6 w' l" p; B: n<div class="cnblogs_code">, l* M8 V- l/ j6 o6 H; H% r8 t. l
<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 A3 s5 M2 D: Q  J$ [. R) ]3 }<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>
8 a. a2 i- d/ z4 D- @- H<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>. r" T5 u( i. x8 k/ R. Q! ]5 ~$ W
</div>9 w) c+ W8 @6 W! p/ J
<p>安装完毕后让我一起感受一下stern的魅力吧,我的Pod里面有两个容器:webapp和busybox,如果使用kubectl logs 还得指定具体的容器,而使用stern就没有这样的限制。</p>
! K! F5 v. p2 ]# L+ C+ Q* ]<div class="cnblogs_code">
) o3 Y' v& E" C6 K- x<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)"> .( l2 j  M$ G& E0 I7 x
</span>+<span style="color: rgba(0, 0, 0, 1)"> webapp › busybox
9 j; V, R5 d# h2 b</span>+<span style="color: rgba(0, 0, 0, 1)"> webapp › webapp, q+ M4 Z* i* o; g0 c
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 S7 A( J, ]' _7 Ewebapp 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]
0 c* ]8 `, d& 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.201</span> [INFO ] [main] [org.apache.catalina.core.StandardEngine] Starting Servlet engine: [Apache Tomcat/<span style="color: rgba(128, 0, 128, 1)">9.0</span>.<span style="color: rgba(128, 0, 128, 1)">41</span><span style="color: rgba(0, 0, 0, 1)">]2 x7 ?4 K) N' Y$ O, i4 o" c
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.324</span> [INFO ] [main] [org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/<span style="color: rgba(0, 0, 0, 1)">]] Initializing Spring embedded WebApplicationContext- ]+ H, w! X. `% \- [7 W  a& a
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
  w+ N( \+ I7 Q% K: J# f8 twebapp 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)">
2 v; s4 e* x7 I$ P" 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)& E( c7 G5 ]3 V, f4 T
webapp busybox </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">54.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)">]: t# f5 x4 k  K
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)">& A4 m* K8 L; u6 O: [/ }. S# S: Q
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)">)
! M( C8 J# c8 S. jwebapp webapp
" R" r/ _( Q7 nwebapp webapp   .   ____          _            __ _ _
) K* ]1 }2 A) S+ gwebapp webapp  </span>/\\ / ___<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">_ __ _ _(_)_ __  __ _ \ \ \ \</span>
" A8 n% T: e' o2 ?1 R5 dwebapp 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>
0 W0 w8 a* f1 }6 A# n* jwebapp webapp  \\/  ___)| |_)| | | | | || (_| |<span style="color: rgba(0, 0, 0, 1)">  ) ) ) )
* x! R2 a7 z4 Hwebapp webapp   </span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">  |____| .__|_| |_|_| |_\__, | / / / /</span>4 Q# B/ J' P: T' i9 R
webapp webapp  =========|_|==============|___/=/_/_/_/<span style="color: rgba(0, 0, 0, 1)">+ w4 t. k! S3 m+ O* K
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)">)
1 E- w7 t, d8 J$ Uwebapp webapp5 J3 d8 x& g- j8 j. O6 v
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)% U1 E# [( h; D' y- Z$ e" 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)">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
, f3 |" e3 Z: c+ l) |) P9 jwebapp 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)
0 V0 q0 p$ j5 K! W- x" 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.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)">]: k# i8 i- M& N! G
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]7 i3 E5 b/ x7 }
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)">]
& E* A# g1 X6 v# ]. a% U( 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)">53.324</span> [INFO ] [main] [org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/<span style="color: rgba(0, 0, 0, 1)">]] Initializing Spring embedded WebApplicationContext
9 ~: M( t* Q* @) g9 K  ]% ~" ]4 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)">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+ K$ H: C3 _' h$ r% O3 N6 C7 z% G9 Z: w* p
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)">
9 l1 u8 ]! K% b5 ^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)
) S5 R$ \, I3 A( N, p/ A' 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)">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)">]
' o3 L$ ?# F, Ewebapp 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)">  x& J  L0 z% p, M( [9 k. 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.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>
8 B) ~5 ]; R/ K- C+ G8 O</div>
0 s, t8 s" w. v<p>&nbsp;</p>
# L1 c0 N/ m4 d) O
回复

使用道具 举报

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

本版积分规则

手机版|飞雪团队

GMT+8, 2025-8-16 13:30 , Processed in 0.074243 second(s), 22 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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