飞雪团队

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

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

[复制链接]

8574

主题

8662

帖子

2万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
28052
发表于 2022-2-12 14:35:42 | 显示全部楼层 |阅读模式
) W5 R, e2 U7 {2 q/ C) e9 A+ W! k
<p>kubectl作为我们主要的操作K8S的工具,其具备非常丰富的功能,但是如果不经过打磨,使用起来还是存在诸多不便,今天我们来看看如何将我们的kubectl打磨的更加易用。</p>
( g' y" |. }$ _5 K<p>&nbsp;</p>' f. v6 l% g4 b7 N! m) c. c
<p>一、命令自动补全</p>* c' _+ S9 T5 w0 r7 v
<p>kubectl中提供非常多的命令,如果每一次都要手动一个字符一个字符的敲未免太累了,那么如何配置自动补全呢?这里以ubuntu系统为例:</p>
- m- _) H+ M  C, U3 E6 Z<p>1、安装auto-completion工具</p>9 O+ n. [7 N9 ~! L$ d/ _* [
<div class="cnblogs_code">
5 z$ e* _0 I1 [; b# `# k0 S<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> apt update
! M) k& P* b% B' |& I( C+ J; G/ jHit:</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>
' z" T; o5 f. c8 L& q9 x7 bHit:<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>
0 X2 n- f+ t, z0 }) I* qHit:<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># j2 s& J9 G  d( b+ b# H  }; `) L
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>0 S+ w' S2 A; K/ E! \- g
Hit:<span style="color: rgba(128, 0, 128, 1)">5</span> http:<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">archive.ubuntu.com/ubuntu bionic-backports InRelease</span>
, M  q$ o& V8 p2 U9 p9 B( `& N<span style="color: rgba(0, 0, 0, 1)">Reading package lists... Done2 Y. f/ ]) k; P; f$ g
Building dependency tree
& g1 L5 D' p9 ~( Q, |Reading state information... Done5 u, m" Z5 V9 A- G( x4 t
</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.# F' Z. @& U2 g6 g
$ </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)">completion8 A* d' S1 k7 `  N+ j/ n
Reading package lists... Done$ r2 B! m. A$ {. w9 L" |3 u
Building dependency tree+ _& E# v" ]: }1 S7 y
Reading state information... Done
. N; B! c( X: u' a& Ebash</span>-completion is already the newest version (<span style="color: rgba(128, 0, 128, 1)">1</span>:<span style="color: rgba(128, 0, 128, 1)">2.8</span>-<span style="color: rgba(0, 0, 0, 1)">1ubuntu1).
7 v1 \4 J" R% G& ]% D" }  R* T</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>
, G- \, p1 E3 b; L" Y</div>! f+ J- K; S( P5 l! s
<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>
! }  e- h, [0 e" Y% Y. X3 D/ n- q  K# P<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>  f' R, j% y& s" Z
<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>& F/ H4 [& J( _1 J1 o& k3 h  {4 G
<div class="cnblogs_code">
) y6 h% f0 Y" T+ @& m9 {' [% I<pre>source &lt;<span style="color: rgba(0, 0, 0, 1)">(kubectl completion bash)
+ i$ ?+ c, j/ h. C</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>9 @5 A3 o$ _2 J
</div>
6 J3 O' c9 c9 {% Z8 |4 \<p><strong>Zsh</strong>:</p>% i% `- w! ]* m4 [- [# w1 a  r
<div class="cnblogs_code">
- z. v9 k- x" o4 t<pre>source &lt;<span style="color: rgba(0, 0, 0, 1)">(kubectl completion zsh)9 A8 q5 R1 g6 ~8 R- Z0 L" I( V
</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 l% s/ G9 N
</div>9 p+ o+ Y3 q6 _  G3 d
<p>配置后就可以通过Tab键自动补全命令啦!</p>
9 i5 R" l8 y. w( y# G<p>&nbsp;</p>
1 _* ?" @3 u3 O" Y! F* b% z1 i<p>二、配置kubectl别名</p>! W1 {) {0 Q5 `9 d* v! j! W
<p>我们可以通过设置别名简化kubectl命令,编辑.bashrc文件,添加如下内容:</p>$ u7 {; D; `8 a& d6 P1 n
<div class="cnblogs_code">
6 @9 i+ v8 w7 u0 F( j. k<pre>alias <span style="color: rgba(0, 0, 255, 1)">sudo</span>=<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">sudo </span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">
: i; p; R4 j5 p/ k5 Lalias 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)">. C" B- e! y% t( r- u  e* p; g
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)">( \" c; \. S- {
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)">
) W2 i- u( Y# T! v% E$ halias 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)">) J  O5 s1 x: A0 H+ t' w. Y
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)">* f! w' c! V  g$ F' }
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>: h2 R2 q; h- o' {3 b( `& x
</div>+ E$ t. g* I% K1 t9 d- ]2 D/ K1 A
<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>( m4 E2 S/ u2 t4 Y+ n
<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>3 v2 E, }+ C3 a/ Z6 d; W! D
<div class="cnblogs_code">
# x3 T, W6 V- S; G* c, y  Z<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> ka webapp_pod.yaml" B. J3 U+ h% Q9 O
pod</span>/<span style="color: rgba(0, 0, 0, 1)">webapp created; ^0 b' p: f+ B4 d
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> kg pods( l, D" y: l& P  h5 \
NAME     READY   STATUS              RESTARTS   AGE
$ d# G5 y) \" X3 i% Z3 C/ Pwebapp   </span><span style="color: rgba(128, 0, 128, 1)">0</span>/<span style="color: rgba(128, 0, 128, 1)">2</span>     ContainerCreating   <span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">          7s# X. K, p# ]& P) [
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> kd pod webapp
' b  n( `) W( p# YName:         webapp, U& ]5 J- E$ ~4 p: q
Namespace:    default
9 s7 w* h( H, H! b) g8 MPriority:     </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">+ M( M9 j  Q& F& q$ |4 r4 O
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 b) T* Y1 E$ h( b. L! f
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)">
  o. R1 {% E+ G: h$ KLabels:       app</span>=<span style="color: rgba(0, 0, 0, 1)">webapp8 F& p' j& J4 [9 \
Annotations:  </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">" I- k. ^1 h. C/ U
Status:       Running* m: e% H0 ?+ J) B' C
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)">, c: S5 l1 ?, w; `
IPs:
, W( @% C: S  C; h  U  M, q  IP:  </span><span style="color: rgba(128, 0, 128, 1)">172.17</span>.<span style="color: rgba(128, 0, 128, 1)">0.6</span><span style="color: rgba(0, 0, 0, 1)">
& @$ Y* n' W$ rContainers:
) F$ e: W8 ?* \: k3 ]  webapp:
3 |1 Y, y: C% X    Container ID:   docker:</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">d9ddf9dd47de12b53f2119bf75df6706bee2e7711509638ad52adc9addeda704</span>6 d6 F5 V* R" D" [/ h4 r: J5 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)">
  H8 g/ }* H: `' L+ V# }    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 f3 E# ^  ^+ `7 l1 g9 d    Port:           <span style="color: rgba(128, 0, 128, 1)">5000</span>/<span style="color: rgba(0, 0, 0, 1)">TCP
2 a5 T) A9 D3 {" a) G    Host Port:      </span><span style="color: rgba(128, 0, 128, 1)">0</span>/<span style="color: rgba(0, 0, 0, 1)">TCP. d# a) O# ?, A, b0 V9 K
    State:          Running0 J# K% r5 i, q, l. F
      Started:      Wed, </span><span style="color: rgba(128, 0, 128, 1)">09</span> Feb <span style="color: rgba(128, 0, 128, 1)">2022</span> <span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">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)">
/ K0 N/ ?# Y1 e2 o4 b, o    Ready:          True! w% _  Z; b2 j
    Restart Count:  </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">
# }3 M) ]& k* v/ U" j: Q6 o    Environment:    </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">0 P- n* M4 F  j8 a
    Mounts:
8 C1 n8 D9 I1 Z/ ^+ m      </span>/tmp from webapp-<span style="color: rgba(0, 0, 0, 1)">logs (rw)
/ }4 t# L9 V0 m5 B/ p      </span>/var/run/secrets/kubernetes.io/serviceaccount from default-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h (ro)( ~, Y1 M5 `; e- U! V
  busybox:
  ~( c3 ?6 z0 i& ^* C3 ~    Container ID:  docker:</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">6a6a35a628a782fc643af3dd49986bbc77c23de1ae4726bc521c77f61abbbf5d</span>
+ y$ U9 E( u) f* L" m& J; y<span style="color: rgba(0, 0, 0, 1)">    Image:         busybox
5 E! n  h8 k% w: R    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>" S9 G. z& u* p, P1 l
    Port:          &lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
+ v8 q5 W' e# E7 e/ l7 ?3 d; J9 T    Host Port:     </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
: L; V; ^1 A3 b    Command:
$ O6 f$ w# a& z: R7 Y      </span><span style="color: rgba(0, 0, 255, 1)">sh</span>
. N# k' B* h* |      -<span style="color: rgba(0, 0, 0, 1)">c# ?" r! O5 y# h1 X3 s2 [
      </span><span style="color: rgba(0, 0, 255, 1)">tail</span> -f /logs/<span style="color: rgba(0, 0, 0, 1)">log.out
6 s2 T' k6 L: C' u( R) H    State:          Running% }( X$ }% a: a7 `+ 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)">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)">; Y8 P0 {6 f4 Q! q3 F
    Ready:          True
  C! A2 T+ Z; g    Restart Count:  </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">
# E( v% A0 S) Y    Environment:    </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">6 T/ Z- K4 D  Y- r! i8 ^" u" [
    Mounts:
! c2 h0 c- d  o  m' \( K      </span>/logs from webapp-<span style="color: rgba(0, 0, 0, 1)">logs (rw)
( q5 F/ _; h! {      </span>/var/run/secrets/kubernetes.io/serviceaccount from default-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h (ro)8 d8 L3 H2 F: \, H
Conditions:
2 T4 {/ k: j! M! p  Type              Status6 f6 |) L/ `8 Y
  Initialized       True0 T8 \! q$ z' w0 {# n' I8 _
  Ready             True) i2 b1 g7 C% ~0 d. c; u
  ContainersReady   True9 K7 X( E8 R9 |/ `+ \$ ^
  PodScheduled      True/ P8 h1 a" U- F0 @# l+ I$ t/ h
Volumes:
- O$ l' k9 ?. [  l1 Z$ O  webapp</span>-<span style="color: rgba(0, 0, 0, 1)">logs:) Q8 E8 R2 [) e; X3 n8 H
    Type:       EmptyDir (a temporary directory that shares a pod</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">s lifetime)</span>
+ |1 j: P) m: _& \+ ~<span style="color: rgba(0, 0, 0, 1)">    Medium:; }0 O4 ?7 \1 S2 D( q2 m; c
    SizeLimit:  </span>&lt;unset&gt;<span style="color: rgba(0, 0, 0, 1)">
5 h5 P+ m$ @) c% d, Y% j3 Z  default</span>-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h:
# \" S1 w( t+ G# A# H% C3 M    Type:        Secret (a volume populated by a Secret)
6 H% i7 @% c- L! Z    SecretName:  default</span>-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h
+ N4 V4 v! F3 e) }! c    Optional:    </span><span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)">" c- d& B+ j$ X( m
QoS Class:       BestEffort
2 p  Q/ {3 q" v) v1 DNode</span>-Selectors:  &lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">2 E7 T% w2 d7 N: q0 t
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)"> 300s9 g2 {# J2 h! W! f5 m: O
                 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% y$ Y- U2 @* T
Events:3 Y1 l$ G: U! q! |9 m' U; f
  Type    Reason     Age    From               Message
0 z6 q) z( x- m# |! f/ m5 Y  </span>----    ------     ----   ----               -------<span style="color: rgba(0, 0, 0, 1)">
. y2 y* n  _9 @8 R& L# j  Normal  Scheduled  2m23s  default</span>-scheduler  Successfully assigned default/<span style="color: rgba(0, 0, 0, 1)">webapp to ayato! `! l5 _( f8 n* m+ E
  Normal  Pulled     2m22s  kubelet            Container image </span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">172.16.194.135:5000/webapp:1.0</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)"> already present on machine! R) w! s! Q& N/ ^  g$ ?
  Normal  Created    2m21s  kubelet            Created container webapp% k' l( }1 p3 `* A) P+ I1 L) ]
  Normal  Started    2m21s  kubelet            Started container webapp
$ l  b8 d2 v7 a  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)">
' e; A" Y4 ~; x/ D5 E" K7 K) 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
7 f. ^. i; H, U* ~' W! U  Normal  Created    15s    kubelet            Created container busybox
4 m( E- P0 k+ `& E  Normal  Started    14s    kubelet            Started container busybox</span></pre>3 w) W4 a/ B& C$ Q6 L9 `4 E
</div>2 v! U* M) D* ~% z( ~
<p>真的是飞一般的感觉!!!</p>; e* `/ ], b; K/ @$ _7 ?% K) a
<p>&nbsp;</p>. V+ ?* b. {& N. M# h
<p>三、Context和Namespace切换</p>& ^( \) R3 j& a; n
<p>我们在公司的容器平台上使用kubectl时,经常需要切换context和namespace,导致命令非常繁琐,那有没有简便的方式呢?—— kubectx</p>
+ z' j- B# E; A  M  c! Y<p>kubectx安装</p>
; s: G3 ^6 q5 N' E# `- Y9 y<div class="cnblogs_code"># r- K$ _% O5 K9 x8 v
<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>; w! v* m) ^$ ]8 [* ]; s
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)">...
, j1 P1 n6 }  ]( a, Y9 \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)">.! R/ J% g3 U! N# j( Q2 O. M+ N
remote: Counting objects: </span><span style="color: rgba(128, 0, 128, 1)">100</span>% (<span style="color: rgba(128, 0, 128, 1)">172</span>/<span style="color: rgba(128, 0, 128, 1)">172</span>), <span style="color: rgba(0, 0, 255, 1)">done</span><span style="color: rgba(0, 0, 0, 1)">.' m9 E- n- q* A6 s) O# z  `
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)">.
" |9 ]1 V- K$ |2 _remote: Total </span><span style="color: rgba(128, 0, 128, 1)">1457</span> (delta <span style="color: rgba(128, 0, 128, 1)">85</span>), reused <span style="color: rgba(128, 0, 128, 1)">97</span> (delta <span style="color: rgba(128, 0, 128, 1)">51</span>), pack-reused <span style="color: rgba(128, 0, 128, 1)">1285</span><span style="color: rgba(0, 0, 0, 1)">, l/ m4 L. g- J$ F( q
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)">.
1 E* ]" U: z7 \! N* t! r( eResolving 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)">.
: y/ D" i" b8 [) `- y. K" P$ </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; e# T, n  g  W  Y  d
$ </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>6 ?5 q& }7 t- k" x" U0 B- u& G
</div>& S/ _+ M" L1 a# s+ `  ?" v% x
<p>我们来看一下效果:</p>
* L  i6 @6 k/ V# R* a& G2 K* d<div class="cnblogs_code">
" m0 f% _+ o& n8 g" K0 ^( }<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ctx+ ^9 \5 R, E1 m% @9 r: I; R9 h
minikube
- u1 ?9 D% `* q9 p$ V( D# ~$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ctx minikube/ z" B% }8 m5 o6 Q% o0 {
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)">.- J: c9 K( l) ^4 V  c
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ns
* e# ^+ f/ Q6 Y% l! g" a0 _default: x& W7 }* D( J: r+ v- G# N6 P% N; b
kube</span>-node-<span style="color: rgba(0, 0, 0, 1)">lease/ [/ v. M% ?! P2 Y( K
kube</span>-<span style="color: rgba(0, 0, 0, 1)">public
/ u: M9 {9 `% D3 C7 ?kube</span>-<span style="color: rgba(0, 0, 0, 1)">system
; K) S& Y3 E6 J7 z8 i- v& D0 Z1 mkubernetes</span>-<span style="color: rgba(0, 0, 0, 1)">dashboard
8 {, Z& m# T4 l' c" a. g$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span> k ns kube-<span style="color: rgba(0, 0, 0, 1)">public1 s/ ?# z+ N  q& C( P8 M
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.
# u$ h. a& V; N1 A9 c/ uActive 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)">.
* y9 y! `0 w$ L  Q% T' G$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ns default
7 ?" B% l. J$ D/ ~2 O9 rContext </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.1 y$ x' a9 S2 b" {+ F8 a
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>
8 ?- p1 C7 x) v2 Q0 ?2 w# H</div>
! I6 L9 S$ |8 }8 N( T" A<p>&nbsp;</p># n, g& m! }$ A, O: J! X
<p>四、跟踪查看多个Pod的日志</p>: v; h% T( m( @3 A$ D
<p>我们一般使用kubectl logs命令查看Pod日志,但是它不能通过-f参数同时跟踪查看多个Pod日志,这就不方便了,毕竟实际生产环境中每个服务都会有多个Pod,这时我们可以使用stern这个工具,它具备如下能力:</p>
/ J* i# f+ l# Z/ U2 b2 x<ul class="list-paddingleft-2">
7 O7 U# c$ h; H# I0 q2 m5 A' \<li>, m4 \0 m+ R2 v, |
<p>允许使用正则表达式来选择需要查看的PodName</p>
- q6 y( n8 i' X9 b, Q, L. q" S</li>4 z. [% I& Y+ k) z% q; \
<li>
2 e) `- p0 P5 ?' R/ i% x<p>为不同 Pod 的日志展示不同的颜色</p>: O0 }6 l8 n% h) f9 F
</li>
  e, Y9 g; O$ R0 m8 \1 Z<li>
3 t7 w% y2 T8 C' y# P" _<p>跟踪日志过程中假如有符合规则的新 Pod 被创建, 那么会自动添加到输出中</p>" J. B5 P& Q* _2 Q" P2 u! M
</li>
9 @  y% k9 }8 {( I</ul>
" V/ o4 s+ i) K( @5 g# R, G& U<p>首先安装stern(下载stern时可能较慢可以多试几次):</p>5 ~# u9 ~) |0 A$ S1 Z5 V7 X
<div class="cnblogs_code">
5 L2 \+ a( u7 A8 Y, q: f( P6 U$ Z<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>" g3 u/ ~) O, p" E* _4 B( e
<span style="color: rgba(0, 0, 255, 1)">sudo</span> <span style="color: rgba(0, 0, 255, 1)">mv</span> stern_linux_amd64 /usr/local/bin/kubectl-<span style="color: rgba(0, 0, 255, 1)">tail</span>4 K  N. b* m+ b0 A8 r8 S) w" l
<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>
/ Y3 C! f9 Q; c- S* k</div>$ i5 L  U2 v0 R4 ]+ D
<p>安装完毕后让我一起感受一下stern的魅力吧,我的Pod里面有两个容器:webapp和busybox,如果使用kubectl logs 还得指定具体的容器,而使用stern就没有这样的限制。</p>
7 [1 q* @" t) d7 k0 ]3 U<div class="cnblogs_code">
- X' f& b$ f. _; z+ i  T- 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)"> .- N, t* P* c3 \: G4 S$ E
</span>+<span style="color: rgba(0, 0, 0, 1)"> webapp › busybox
5 ^. e4 b/ t% m0 L$ ~. m" c6 |+ |  |</span>+<span style="color: rgba(0, 0, 0, 1)"> webapp › webapp* s% B6 r% ]7 T5 `% G5 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)">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)">]
. T( p6 x9 y' w( L9 h, D! Q# xwebapp busybox </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.200</span><span style="color: rgba(0, 0, 0, 1)"> [INFO ] [main] [org.apache.catalina.core.StandardService] Starting service [Tomcat]
& C0 a4 }' R* |% v  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)">]. [) e8 M& ]) z( `8 N- i7 m% o) h
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$ t, U. G. L* [8 _! S8 T; ]$ j
webapp busybox </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.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 C. P" f: i4 O* {' D% d: A" 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.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)">, K; g3 e  d8 n  X: b) 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)">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 i. u2 b) [+ r4 f& `- R! j9 c  L
webapp busybox </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">54.377</span> [INFO ] [main] [org.apache.coyote.http11.Http11NioProtocol] Starting ProtocolHandler [<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">http-nio-4567</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">]
1 p. c7 d3 X6 g5 o% 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)">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 _1 g6 n) k0 l
webapp busybox </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">54.509</span> [INFO ] [main] [org.demo.webapp.todolist.TodoListApplication] Started TodoListApplication <span style="color: rgba(0, 0, 255, 1)">in</span> <span style="color: rgba(128, 0, 128, 1)">6.235</span> seconds (JVM running <span style="color: rgba(0, 0, 255, 1)">for</span> <span style="color: rgba(128, 0, 128, 1)">8.074</span><span style="color: rgba(0, 0, 0, 1)">)' `- a% p& i/ D" D/ L* I+ Z7 }
webapp webapp
8 {( R; Q# C' }& e) b9 L* kwebapp webapp   .   ____          _            __ _ _
3 o+ D+ ~& }8 P& O/ M/ z( y( Uwebapp webapp  </span>/\\ / ___<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">_ __ _ _(_)_ __  __ _ \ \ \ \</span>
& i& r% @7 ~9 W2 k; b: wwebapp 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>
5 a* e3 @, [# S! i1 T; I7 zwebapp webapp  \\/  ___)| |_)| | | | | || (_| |<span style="color: rgba(0, 0, 0, 1)">  ) ) ) ), S+ J7 m  ~4 m
webapp webapp   </span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">  |____| .__|_| |_|_| |_\__, | / / / /</span>
3 t* T# m* d4 b+ a4 X! j; h3 dwebapp webapp  =========|_|==============|___/=/_/_/_/<span style="color: rgba(0, 0, 0, 1)">+ T  _1 W; w+ u% l
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)">)9 z3 U  w! L, h
webapp webapp
3 \% B# O. N5 z# l4 o7 mwebapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">50.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)
7 R0 ~5 A8 k+ L7 @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
& K, i# x% S- Rwebapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.158</span> [INFO ] [main] [org.springframework.boot.web.embedded.tomcat.TomcatWebServer] Tomcat initialized with port(s): <span style="color: rgba(128, 0, 128, 1)">4567</span><span style="color: rgba(0, 0, 0, 1)"> (http)& }' g( x+ I  M1 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.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)">]* w5 q! T' n) }8 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.200</span><span style="color: rgba(0, 0, 0, 1)"> [INFO ] [main] [org.apache.catalina.core.StandardService] Starting service [Tomcat]% V3 h# T) j9 U6 a3 b
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)">]! ]* B4 @. J( q0 I0 d/ `
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
) Y* [. {: U* p# m8 }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)"> ms6 G! ?# O) s/ o
webapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.801</span> [INFO ] [main] [org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor] Initializing ExecutorService <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">applicationTaskExecutor</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">& ]* Q# b! T, _; q8 |: j: p5 z
webapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">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)
* q# \- Y$ u: E/ O7 Vwebapp 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)">], D3 r* C' W8 B0 @
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)">
5 S3 q: \) j' C3 o  _9 Z+ @- _7 \9 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.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>9 d  R7 P4 t; E+ E9 n1 s* r/ T
</div>
; w( l6 a% d; ~% k; b5 t) r# ^& j, x<p>&nbsp;</p>
9 y9 k1 h" w, t5 @" }9 ]( Q5 l4 r
回复

使用道具 举报

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

本版积分规则

手机版|飞雪团队

GMT+8, 2026-4-20 14:23 , Processed in 0.069115 second(s), 21 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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