飞雪团队

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

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

[复制链接]

8612

主题

8700

帖子

2万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
28166
发表于 2022-2-12 14:35:42 | 显示全部楼层 |阅读模式
4 u. Y# t8 b6 j
<p>kubectl作为我们主要的操作K8S的工具,其具备非常丰富的功能,但是如果不经过打磨,使用起来还是存在诸多不便,今天我们来看看如何将我们的kubectl打磨的更加易用。</p>/ C  J2 I8 _5 ^; o3 l
<p>&nbsp;</p>
+ M# e! z  k5 |) x1 V<p>一、命令自动补全</p>& ?+ T" d% `+ M& v3 ~2 j
<p>kubectl中提供非常多的命令,如果每一次都要手动一个字符一个字符的敲未免太累了,那么如何配置自动补全呢?这里以ubuntu系统为例:</p>1 ~8 B7 N) L5 x  o$ q
<p>1、安装auto-completion工具</p>* o% ]' N# B! s! E
<div class="cnblogs_code">" _! L5 \( f- P0 n) H5 k, q. m
<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> apt update; f4 Q* O+ W! y
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>
: b- {: [" @! C* p; O1 DHit:<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 x3 H8 T: `, h- ~# V
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>( c; \7 R% o+ P+ ~1 ~1 j* f4 A
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>
) Q. L- T$ B) qHit:<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>4 k; h; Q) k: r' \0 C6 Y
<span style="color: rgba(0, 0, 0, 1)">Reading package lists... Done1 G5 ?" Y+ B7 c
Building dependency tree# A' s- L- h! Z. y- G
Reading state information... Done# e9 z  f1 z7 G8 i2 `
</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.7 h) d8 h! q4 W# B$ ?4 A% m# f6 n
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span> apt <span style="color: rgba(0, 0, 255, 1)">install</span> bash-<span style="color: rgba(0, 0, 0, 1)">completion' |  v; c1 a' F! }+ k
Reading package lists... Done
4 F6 [9 L; B, {6 R. OBuilding dependency tree+ G6 h* v0 H- o6 n0 G( o
Reading state information... Done
0 D. _6 O+ r" y4 d6 rbash</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 h% \. L/ _# C
</span><span style="color: rgba(128, 0, 128, 1)">0</span> upgraded, <span style="color: rgba(128, 0, 128, 1)">0</span> newly installed, <span style="color: rgba(128, 0, 128, 1)">0</span> to remove and <span style="color: rgba(128, 0, 128, 1)">144</span> not upgraded.</pre>9 C! o( U* i5 r4 K- w
</div>
  J9 z5 X$ ?+ b$ 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>
; g- F" }) u; a! t! `- a& Q" _<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>$ ^( ]; ~" E( C2 \* }
<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>
; |) ]) r( Z0 T" U6 P% K( ?<div class="cnblogs_code">
1 ~$ K3 r" c3 V" c<pre>source &lt;<span style="color: rgba(0, 0, 0, 1)">(kubectl completion bash)
+ T* c2 @3 U: _& g' X, 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>" }" c4 O" f4 B  h) m
</div>
% _6 H; F4 S2 u8 D2 ]<p><strong>Zsh</strong>:</p>1 b* O* c! C3 V$ N' r
<div class="cnblogs_code">( m4 K* o$ w" B8 r! A
<pre>source &lt;<span style="color: rgba(0, 0, 0, 1)">(kubectl completion zsh)3 B  U& z% z' Z/ Q. x  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)">[[ $commands[kubectl] ]] &amp;&amp; source &lt;(kubectl completion zsh)</span><span style="color: rgba(128, 0, 0, 1)">"</span> &gt;&gt; ~/.zshrc</pre>
3 ~5 A" |5 l2 Z! k0 F</div>8 w7 Z. c% c, d3 m  ~
<p>配置后就可以通过Tab键自动补全命令啦!</p>
6 O& Z0 C. g0 i, x2 u( r<p>&nbsp;</p>" t, l) T! x; w$ J8 |# D3 E5 f
<p>二、配置kubectl别名</p># {! W% M9 i- }# j0 `; W/ z; ^# F
<p>我们可以通过设置别名简化kubectl命令,编辑.bashrc文件,添加如下内容:</p>6 }3 ~$ A3 o* m7 y& K+ y. _9 C
<div class="cnblogs_code">& K5 M: P* i% q/ y& z  D- [
<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)">) A. m4 ^  u: G- `
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)">
8 T4 \0 x3 Y, P) x0 Walias 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 L8 @  p/ P7 h7 L: kalias 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)">4 t, Q8 ]# J0 c- d. K
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)">8 y7 h: H) y4 Q3 W
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)">0 D1 K: d. J" _$ X; O
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>. d8 c2 g% X8 e$ k0 F
</div>0 a, c9 [: k9 V, u; B6 T7 G
<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>2 m* l& `# o9 K2 W. o2 q& Y
<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># k0 |& @: j9 H' w
<div class="cnblogs_code">) b' P$ O/ e" r3 R& ?/ o. P: ~, V
<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> ka webapp_pod.yaml
* W4 t. P5 X3 \4 epod</span>/<span style="color: rgba(0, 0, 0, 1)">webapp created
! j5 Q+ X. a4 v- Y+ M: d$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> kg pods
" V0 I5 Z/ z, yNAME     READY   STATUS              RESTARTS   AGE: m; P( h8 e! @& ]
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
: `$ k; q7 H7 i$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> kd pod webapp
, n: s1 z: U2 Q$ G9 c% \+ }% F- N( fName:         webapp! a9 l5 v8 P( t. O6 H% C* G) j
Namespace:    default
% Y9 m4 {2 e' I9 w- ^Priority:     </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">
0 W* l$ D' a( c' y8 A6 c& B* e; r# ?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)">0 E, A, w: }. K' {( ?
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)">
1 L$ `) k9 M- o; |& M3 ^: J+ y9 [Labels:       app</span>=<span style="color: rgba(0, 0, 0, 1)">webapp
# ^; S) t% z( @# W; P3 M$ p% GAnnotations:  </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">3 T" k( d# d* Q7 V2 H5 G* ^, I
Status:       Running/ t( t6 A. ]& C/ e8 i8 z
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)">' J) y! |5 }7 L1 \2 s
IPs:
  s/ l; q- Q9 M  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)">0 K6 l* r) W- S% m% t
Containers:
4 q5 j8 b% e2 V5 e1 ]  webapp:: N! o1 y. N8 g$ k" |! |
    Container ID:   docker:</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">d9ddf9dd47de12b53f2119bf75df6706bee2e7711509638ad52adc9addeda704</span>4 z5 [1 D9 b. c; E0 B
    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)">
4 ?' j! ]7 w. j0 m1 G% z    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>
% v. r( T" ]/ Q    Port:           <span style="color: rgba(128, 0, 128, 1)">5000</span>/<span style="color: rgba(0, 0, 0, 1)">TCP, @9 d* A8 J1 y. p/ F' p/ z; m3 f
    Host Port:      </span><span style="color: rgba(128, 0, 128, 1)">0</span>/<span style="color: rgba(0, 0, 0, 1)">TCP
# ]$ L) J3 J4 X& a$ h9 j8 U( D    State:          Running- A  B' |( D2 g
      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)">' {# W7 ~! w, l: b2 k7 F
    Ready:          True
; k1 }2 f0 |+ p9 w( K1 ?4 T    Restart Count:  </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">% B8 \$ v# h+ }6 _
    Environment:    </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
6 C  L4 r: H" a! R1 G$ _* @. Q    Mounts:
1 L, S; T! l. [3 L      </span>/tmp from webapp-<span style="color: rgba(0, 0, 0, 1)">logs (rw)
" }! w' C8 R, r( c" D; x      </span>/var/run/secrets/kubernetes.io/serviceaccount from default-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h (ro)
4 F: E4 q; ]; y: L: [& a1 z  busybox:: C4 z: u! w5 `  r
    Container ID:  docker:</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">6a6a35a628a782fc643af3dd49986bbc77c23de1ae4726bc521c77f61abbbf5d</span>
* j/ j2 ]' j# ]$ ~3 j$ f0 b) T<span style="color: rgba(0, 0, 0, 1)">    Image:         busybox
. B$ q/ G' A, p    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>
' u' W; k# M* `7 w  f$ H, I) {    Port:          &lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
) V( C9 ?$ p  t# l* h  T9 X) y    Host Port:     </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">( O, P9 |  F& X/ ~6 K4 `
    Command:/ S# y- s/ h- I5 o! Z
      </span><span style="color: rgba(0, 0, 255, 1)">sh</span>$ b' @# J; X. Z$ \0 `' _
      -<span style="color: rgba(0, 0, 0, 1)">c: R  H  h7 @3 G4 l$ h" z  y6 _
      </span><span style="color: rgba(0, 0, 255, 1)">tail</span> -f /logs/<span style="color: rgba(0, 0, 0, 1)">log.out0 s! Y+ i, Z0 h7 Z" q
    State:          Running
* [9 J# `2 R2 p$ M4 e( d      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)">( v5 |% o$ u3 e0 i- p% F3 x
    Ready:          True! V' [  w" Q1 p; h% k  }
    Restart Count:  </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">
. h5 m8 X' Q) A    Environment:    </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
/ T! Z2 t7 Z% Y    Mounts:
- ]" |! V% Y4 @      </span>/logs from webapp-<span style="color: rgba(0, 0, 0, 1)">logs (rw)
; D5 U' }7 y" A5 Z" r/ X. k# P1 [9 E3 r      </span>/var/run/secrets/kubernetes.io/serviceaccount from default-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h (ro)6 h2 p  Z! j9 e4 @! d0 z
Conditions:9 z. u& `8 [. f  D" T# B
  Type              Status
+ _* I1 ~7 s+ U0 X0 Y# D( |, Z  Initialized       True
4 v. B6 f& Z6 Z8 N6 e* P, M5 e  Ready             True
6 G* [$ a9 [' {! R0 P/ i% U  ContainersReady   True
# I8 F. y. J% b) _8 Z, D! X% U  PodScheduled      True
. |2 b) W) t8 T7 W# N" TVolumes:4 O4 K+ U' e( `8 B* D: X2 {& w
  webapp</span>-<span style="color: rgba(0, 0, 0, 1)">logs:
% L% y4 R. \+ m( u    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>
" I7 }3 \) h- A- O) P<span style="color: rgba(0, 0, 0, 1)">    Medium:
2 m/ ?1 r  X% W$ j7 C# S    SizeLimit:  </span>&lt;unset&gt;<span style="color: rgba(0, 0, 0, 1)">
" _# P/ N3 N( ~/ ^3 K3 Q  default</span>-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h:6 u) L! u  W& i* B& V' i: o; e- ~
    Type:        Secret (a volume populated by a Secret)
9 Z3 X: M( f; D5 v! B: P    SecretName:  default</span>-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h. ]) S! V, T: B& Y0 J
    Optional:    </span><span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)">
7 N/ D0 T; G; ~" e! PQoS Class:       BestEffort
2 `0 ~- ^' ^4 H3 [Node</span>-Selectors:  &lt;none&gt;<span style="color: rgba(0, 0, 0, 1)"># Z9 ~0 w( {* V0 R
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)"> 300s7 g) m) `0 O. H# @+ [5 G* T
                 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)"> 300s4 w" d  o$ H3 c$ s9 p6 W( E. I
Events:
/ D% C4 R+ D/ P4 i& e; h. @4 f  Type    Reason     Age    From               Message, c  ^5 u5 }9 ^  U& ~1 x8 p& g
  </span>----    ------     ----   ----               -------<span style="color: rgba(0, 0, 0, 1)">, J7 g$ C& S5 h5 y
  Normal  Scheduled  2m23s  default</span>-scheduler  Successfully assigned default/<span style="color: rgba(0, 0, 0, 1)">webapp to ayato, u2 L& y5 D+ m$ Q$ R4 E. U$ Y
  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* f" U( k0 k: W1 V. N) ^  X
  Normal  Created    2m21s  kubelet            Created container webapp
5 b' O" P# a- M# F% Q4 Q0 r  Normal  Started    2m21s  kubelet            Started container webapp  V4 M5 [; O2 T$ R# b6 B; W* p
  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)">+ i6 \6 F/ U3 X  O* o1 l( W0 t
  Normal  Pulled     15s    kubelet            Successfully pulled image </span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">busybox</span><span style="color: rgba(128, 0, 0, 1)">"</span> <span style="color: rgba(0, 0, 255, 1)">in</span> <span style="color: rgba(128, 0, 128, 1)">14</span><span style="color: rgba(0, 0, 0, 1)">.633078305s
8 M6 W4 `- W) k/ R$ t1 B7 |; d  Normal  Created    15s    kubelet            Created container busybox7 h1 B; F; L4 G" i) K) Z6 B8 w
  Normal  Started    14s    kubelet            Started container busybox</span></pre>
- b6 `+ @0 q; _/ y8 Q</div>- {9 W2 s& O$ p
<p>真的是飞一般的感觉!!!</p>( E/ m" `" l$ ?
<p>&nbsp;</p>/ U* s" R' F5 ]4 ]" F
<p>三、Context和Namespace切换</p>
2 g. b+ W4 @+ I. w* P" l) f<p>我们在公司的容器平台上使用kubectl时,经常需要切换context和namespace,导致命令非常繁琐,那有没有简便的方式呢?—— kubectx</p>  r4 g6 m! m. _) w
<p>kubectx安装</p>' U7 V" D" ^* x) y% J, x
<div class="cnblogs_code">2 d, o8 o; e. \3 g/ M: i- Z
<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>7 d' o8 _. \8 m+ {9 B' m! s- G! ?
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)">...0 K1 l( s. B$ {1 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 O7 n3 l( U4 m2 N6 u. hremote: 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)">.
' i3 N: y- p: \0 H: 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)">.
7 o" U/ K  m& q' ?, zremote: Total </span><span style="color: rgba(128, 0, 128, 1)">1457</span> (delta <span style="color: rgba(128, 0, 128, 1)">85</span>), reused <span style="color: rgba(128, 0, 128, 1)">97</span> (delta <span style="color: rgba(128, 0, 128, 1)">51</span>), pack-reused <span style="color: rgba(128, 0, 128, 1)">1285</span><span style="color: rgba(0, 0, 0, 1)">
2 k0 d2 n, G# T& Z3 yReceiving 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)">.1 o2 v6 z( T' j( a# k% w9 e
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)">./ b0 d) Q7 B. e0 i" 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/kubens /usr/local/bin/kubectl-<span style="color: rgba(0, 0, 0, 1)">ns
( Y# z: V: W2 z/ \; w$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span> <span style="color: rgba(0, 0, 255, 1)">ln</span> -s /opt/kubectx/kubectx /usr/local/bin/kubectl-ctx</pre>5 H% E- Q' x5 u5 `9 O6 Z
</div>* ~1 t" g5 r! g
<p>我们来看一下效果:</p>
  Z0 Z; u( R9 n<div class="cnblogs_code">
# L6 D  m, ]# G6 s0 g<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ctx5 H  X1 R5 [$ Y
minikube
/ D9 V& b& g+ p$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ctx minikube
! Y) e! ]+ Q. @4 }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)">.- K- [% G% C( _$ ~8 D
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ns1 s  ?7 t7 [, t+ ~7 ~4 s4 O
default
; ?3 D$ _; Q9 L5 ykube</span>-node-<span style="color: rgba(0, 0, 0, 1)">lease
: J& z& Z' a2 x, P; }! vkube</span>-<span style="color: rgba(0, 0, 0, 1)">public5 M8 c) B4 a) i$ i( I
kube</span>-<span style="color: rgba(0, 0, 0, 1)">system) A: i7 I& Q+ j* h
kubernetes</span>-<span style="color: rgba(0, 0, 0, 1)">dashboard6 B! k+ }6 ^* ^/ l! W
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span> k ns kube-<span style="color: rgba(0, 0, 0, 1)">public
: ^' S# J5 z: @" 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.$ N9 q: q2 U' [9 v8 m; X, F0 H. B
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)">.( o% K. h  F. P2 [/ K0 ~: Y- N
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ns default  D( b' ~& R3 I. A/ a
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.
4 M9 m7 g+ K' q6 J, E0 fActive 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>. b6 `* b$ q, P1 @, X7 U
</div>
7 q: Q1 Z& q1 c0 M: t7 K9 N) T4 m<p>&nbsp;</p>
7 ?/ r, h4 n. K/ Y4 I% G7 D<p>四、跟踪查看多个Pod的日志</p>3 D  I6 N# E6 V. k3 u; ~
<p>我们一般使用kubectl logs命令查看Pod日志,但是它不能通过-f参数同时跟踪查看多个Pod日志,这就不方便了,毕竟实际生产环境中每个服务都会有多个Pod,这时我们可以使用stern这个工具,它具备如下能力:</p>+ C" L, T. d7 U- N' L6 l5 E% y
<ul class="list-paddingleft-2">
1 m/ t( u8 ~: {- `% H0 _5 c3 X9 n<li>
6 H0 ]. U: W9 k; A4 M<p>允许使用正则表达式来选择需要查看的PodName</p>
; F% f1 R6 u# ~- J6 z</li>& H7 s7 [8 x( }6 u1 j
<li>, p5 g+ J' s% _3 O1 P
<p>为不同 Pod 的日志展示不同的颜色</p>
8 K2 F6 G- e8 f8 Y# q</li>
0 j0 p7 p1 u( B* \9 n4 V, \3 C<li>
# l. \- k7 [( b; Y& H<p>跟踪日志过程中假如有符合规则的新 Pod 被创建, 那么会自动添加到输出中</p>
* c; [, y# `1 k- {/ i</li>
! U1 o' u: k. i  S% B, U</ul>
- e+ X  a6 X; E& G# m. G2 j1 p<p>首先安装stern(下载stern时可能较慢可以多试几次):</p>
: N* H4 L% u; e, U# P  J& W6 P$ i<div class="cnblogs_code">; u6 g% o8 d( p/ 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>
! L8 ~, E0 E3 S% f3 d! [5 l<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>
. t; k) w/ g- O9 b: F7 ^<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>
( p+ Z) w$ T2 I' A, p9 ~</div>! t. t7 g% T- m
<p>安装完毕后让我一起感受一下stern的魅力吧,我的Pod里面有两个容器:webapp和busybox,如果使用kubectl logs 还得指定具体的容器,而使用stern就没有这样的限制。</p>- L5 ^9 }1 R8 `! ~8 H' H  H5 X
<div class="cnblogs_code">7 @5 C& n: H7 Z; }& k* J, G
<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)"> .
% p0 `  f3 Y% s7 S' Z) B# N. _$ U</span>+<span style="color: rgba(0, 0, 0, 1)"> webapp › busybox( L2 o9 o4 u3 A
</span>+<span style="color: rgba(0, 0, 0, 1)"> webapp › webapp
  a" ?2 C7 n: \# 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.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)">]& i( R; e& o+ i& ?2 I
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]
6 C' ^) B0 q; }! K$ u  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.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)">]
( q* X+ k0 ?  y; K& 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.324</span> [INFO ] [main] [org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/<span style="color: rgba(0, 0, 0, 1)">]] Initializing Spring embedded WebApplicationContext( r3 b- r* z4 Z) \
webapp busybox </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.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
3 O0 Z4 Y3 j) l8 R5 @webapp busybox </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.801</span> [INFO ] [main] [org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor] Initializing ExecutorService <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">applicationTaskExecutor</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">
, o9 @, {9 A/ owebapp 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)0 \$ X' h9 X. g9 f. D$ V% U# z
webapp busybox </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">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)">], l" q. \: C* u2 a" T: 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.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)">
2 y7 q8 Z3 s7 w9 n" Uwebapp busybox </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">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)">)6 E, Q% L3 Z9 Y2 p
webapp webapp' p' B1 Q+ Y; u1 p! _
webapp webapp   .   ____          _            __ _ _! \- c# X9 w) Q. l. e
webapp webapp  </span>/\\ / ___<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">_ __ _ _(_)_ __  __ _ \ \ \ \</span>; z4 v! h9 ^, p7 C3 h& [. }" P3 u
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>! B* y2 ~- N# n, Q! O6 x
webapp webapp  \\/  ___)| |_)| | | | | || (_| |<span style="color: rgba(0, 0, 0, 1)">  ) ) ) )3 d) h" E3 J) Q% j" m/ D1 q
webapp webapp   </span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">  |____| .__|_| |_|_| |_\__, | / / / /</span>
7 \: X$ j$ r4 p. Qwebapp webapp  =========|_|==============|___/=/_/_/_/<span style="color: rgba(0, 0, 0, 1)">* N) |1 b: o8 s- g2 o( a
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)">). v0 S; ~$ t: B: }+ L
webapp webapp
3 ?6 |$ {7 j5 x0 |; wwebapp 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)
' z6 v7 [' Q0 S9 g% Q7 X/ r. cwebapp 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
+ `* o9 i; |1 d5 t: [; cwebapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.158</span> [INFO ] [main] [org.springframework.boot.web.embedded.tomcat.TomcatWebServer] Tomcat initialized with port(s): <span style="color: rgba(128, 0, 128, 1)">4567</span><span style="color: rgba(0, 0, 0, 1)"> (http)
6 ^  Z0 C$ V. M9 T: pwebapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">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 O! k: m: }4 L+ _webapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.200</span><span style="color: rgba(0, 0, 0, 1)"> [INFO ] [main] [org.apache.catalina.core.StandardService] Starting service [Tomcat]
' ~1 G! E! 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.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)">]! r5 {& U! _: X0 {# q8 l% I
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
# T! S3 H. O" f6 d# x) k7 c, P1 W% Rwebapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.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 K8 X# c+ k/ N0 R9 M/ T$ q6 y
webapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">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)">
, `. J$ C% b  e8 Z" @" rwebapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">54.264</span> [WARN ] [main] [org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration$DefaultTemplateResolverConfiguration] Cannot <span style="color: rgba(0, 0, 255, 1)">find</span> template location: classpath:/templates/<span style="color: rgba(0, 0, 0, 1)"> (please add some templates or check your Thymeleaf configuration)
& s1 ?! m, A" r1 U6 }webapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">54.377</span> [INFO ] [main] [org.apache.coyote.http11.Http11NioProtocol] Starting ProtocolHandler [<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">http-nio-4567</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">]
* ]3 ]- _2 z9 @webapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">54.481</span> [INFO ] [main] [org.springframework.boot.web.embedded.tomcat.TomcatWebServer] Tomcat started on port(s): <span style="color: rgba(128, 0, 128, 1)">4567</span> (http) with context path <span style="color: rgba(128, 0, 0, 1)">''</span><span style="color: rgba(0, 0, 0, 1)">6 e. n2 u! Z( d6 h8 K: D- j) r
webapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">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>% x0 Y: }* h' V: u3 P/ l4 ^
</div>
, `0 B. f7 I1 }2 ^  e<p>&nbsp;</p>
" {( ?( {; z  r' l+ t
回复

使用道具 举报

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

本版积分规则

手机版|飞雪团队

GMT+8, 2026-5-9 23:03 , Processed in 0.070420 second(s), 21 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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