飞雪团队

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

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

[复制链接]

9171

主题

9259

帖子

2万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
29843
发表于 2022-2-12 14:35:42 | 显示全部楼层 |阅读模式
) z. Y# j' R* [2 c3 o. ~# G: P
<p>kubectl作为我们主要的操作K8S的工具,其具备非常丰富的功能,但是如果不经过打磨,使用起来还是存在诸多不便,今天我们来看看如何将我们的kubectl打磨的更加易用。</p>
) G  X' k4 Y$ A<p>&nbsp;</p>
8 X; a+ i% o' A1 Q<p>一、命令自动补全</p>
; n& w  m3 m9 C7 c& A% `<p>kubectl中提供非常多的命令,如果每一次都要手动一个字符一个字符的敲未免太累了,那么如何配置自动补全呢?这里以ubuntu系统为例:</p>
+ V* t. _. o& ]5 _7 {<p>1、安装auto-completion工具</p>  J/ {6 q' ?1 @/ ~8 H: \, L, [
<div class="cnblogs_code">
! K) @1 }) D# X1 M3 J  f# t) B$ Z- C. P<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> apt update& T) ^* W. q- t% b. Y& c% w6 s# U' y4 [
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 Y2 E; ]7 W: t3 ~4 I. n
Hit:<span style="color: rgba(128, 0, 128, 1)">2</span> http:<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">security.ubuntu.com/ubuntu bionic-security InRelease</span>9 }- y  a" }9 i2 j4 }$ [# d( m4 n
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>
. I3 ^( M0 u' B) ~# \* `$ ]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>
1 r- D# q5 s9 `1 |3 iHit:<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>
5 Z  C& W2 @( J5 B( @# \<span style="color: rgba(0, 0, 0, 1)">Reading package lists... Done
) E+ N% @7 W' X0 SBuilding dependency tree* k' k' _9 E4 T; E2 ~6 g. C4 @
Reading state information... Done
* b: u/ c2 {$ d7 J</span><span style="color: rgba(128, 0, 128, 1)">144</span> packages can be upgraded. Run <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">apt list --upgradable</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)"> to see them.
9 ]& O( ?0 I, T. X; G+ d$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span> apt <span style="color: rgba(0, 0, 255, 1)">install</span> bash-<span style="color: rgba(0, 0, 0, 1)">completion; U9 P( y1 e$ Q' f# Z% R: K
Reading package lists... Done' T) L  b2 m- J1 R' U; p/ w* n
Building dependency tree- N( ^$ B! j  n& P0 f  M# Y
Reading state information... Done
0 @1 s* Z! e( G) Ubash</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 O/ {9 ?1 ]1 K" G( `</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>- Q+ G- _# ^, H
</div>
- z, m' z/ G/ F( u1 }, w<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>
( N, j/ Y; H0 R  {) [<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>+ J" r# k* c" i- u5 |" a) w( M
<p><span class="js_darkmode__2" data-darkmode-color-16446330660319="rgb(163, 163, 163)" data-darkmode-original-color-16446330660319="#fff|rgb(0, 0, 0)" data-style="color: rgb(0, 0, 0);"><strong data-darkmode-color-16446330660319="rgb(163, 163, 163)" data-darkmode-original-color-16446330660319="#fff|rgb(0, 0, 0)">Bash</strong>:</span></p>0 {# x5 b# a5 n4 C, F
<div class="cnblogs_code">% G: R/ N7 o) N- k5 s* i/ [! H( d+ b' {
<pre>source &lt;<span style="color: rgba(0, 0, 0, 1)">(kubectl completion bash)3 E1 K) ?4 K, [/ w
</span><span style="color: rgba(0, 0, 255, 1)">echo</span> <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">source &lt;(kubectl completion bash)</span><span style="color: rgba(128, 0, 0, 1)">"</span> &gt;&gt; ~/.bashrc</pre>* n- k/ S3 m+ b( L# X) D4 A% R/ `; R
</div>
6 ~. |8 p2 ?8 W% c2 k% ^! Q<p><strong>Zsh</strong>:</p>
$ B+ K( U& E5 l$ J- w$ t<div class="cnblogs_code">, L! O* {4 Q* H4 e; y! \0 m
<pre>source &lt;<span style="color: rgba(0, 0, 0, 1)">(kubectl completion zsh)
9 Z6 E; p0 `" E$ l0 L</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>4 f) h1 q- R" L7 x
</div>
- s( q2 M# Y9 V<p>配置后就可以通过Tab键自动补全命令啦!</p>$ D3 W8 V9 }5 V, r
<p>&nbsp;</p>
* r) N/ J3 N8 ]8 W8 Y<p>二、配置kubectl别名</p>
, W1 F6 O- g5 v<p>我们可以通过设置别名简化kubectl命令,编辑.bashrc文件,添加如下内容:</p>
* |$ P4 o, X* d' R! F<div class="cnblogs_code">
% a3 U: e! |0 @! v/ U/ G2 L2 h: g9 ~<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)">: M8 |3 e9 {' }7 H2 P" {2 H$ `
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 p5 E( w0 u0 _/ G; Ealias 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)">
( A* o6 A( K& y/ p1 I* Qalias 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)">
# E* b' d& \3 s% J  r% E4 I: Xalias 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)">
" ^& Q. B. w6 p2 e' Calias kg</span>=<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">kubectl get</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">0 y5 G& M* e& I4 S. A4 R
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>5 r: s* Y5 V+ w% V5 d
</div>, c5 T3 [6 p! M" B; Y* ^6 u" m4 z3 V
<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>
0 Q% Y7 B0 L9 ^: ~. g& Z9 v. T<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>. q5 ?0 O! K/ `- j1 Q* Q$ h
<div class="cnblogs_code">
! `  O5 }+ f# z6 k+ x<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> ka webapp_pod.yaml* Y3 Z+ O+ k* R3 ]5 |
pod</span>/<span style="color: rgba(0, 0, 0, 1)">webapp created" v) [" T& I: T" v1 \; a# I
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> kg pods. j; r0 m7 q  s# k: M, f
NAME     READY   STATUS              RESTARTS   AGE/ D/ l! r3 J. o% t9 X8 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
! P9 h2 S& e5 ?1 Q$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> kd pod webapp
0 m! \+ `- L4 I0 ]  g& kName:         webapp
9 V! B% W! o/ d6 X: GNamespace:    default
" _5 M" ~( w# x) m$ yPriority:     </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">) ]: D8 Y& y( x; E# ^2 }7 F
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)">5 \. u" O: c2 k% u
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. R% P2 y0 ?5 b# z2 G7 _* f7 pLabels:       app</span>=<span style="color: rgba(0, 0, 0, 1)">webapp
% Z. x7 s* @8 x4 i6 d8 u: b/ kAnnotations:  </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">! l4 m; R  h3 s  O
Status:       Running
9 ]( I& t" H9 e7 g0 OIP:           </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)">, d5 {1 s: E- t$ P4 B% `# T6 s
IPs:
6 u0 [* Q  K/ k' N% p0 v% I  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 P4 l2 X3 `% Y9 W+ \; {) @0 B; WContainers:7 t& \9 n& }, S  y
  webapp:8 q+ P; T( S5 F
    Container ID:   docker:</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">d9ddf9dd47de12b53f2119bf75df6706bee2e7711509638ad52adc9addeda704</span>6 s" k( D; ^- Z' r8 e0 \
    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)">
* J* L* o8 [, l) m& o$ N$ L3 j3 l    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>' Y5 ~: m% `+ D7 ^* v7 o
    Port:           <span style="color: rgba(128, 0, 128, 1)">5000</span>/<span style="color: rgba(0, 0, 0, 1)">TCP
! ]% r0 V/ n3 w  y    Host Port:      </span><span style="color: rgba(128, 0, 128, 1)">0</span>/<span style="color: rgba(0, 0, 0, 1)">TCP
" {% W! |( W1 O% `( j    State:          Running/ a$ R6 F6 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)">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)">. R8 e3 H$ D: D  l+ W
    Ready:          True% q6 W& z2 E+ P5 U6 [. ?0 p  n% o
    Restart Count:  </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">3 a5 g% i* U7 N3 C
    Environment:    </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">" Q# r; s0 u- f; \# @) C( q- G+ `
    Mounts:
8 b% ^& @7 g# j: Z: p. @/ G      </span>/tmp from webapp-<span style="color: rgba(0, 0, 0, 1)">logs (rw)) c$ W2 A, f" s3 W' o2 Q' E
      </span>/var/run/secrets/kubernetes.io/serviceaccount from default-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h (ro)
, I) b; v2 x# V% z& O8 o  busybox:: i$ o& @3 a$ A! L. E7 z& f
    Container ID:  docker:</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">6a6a35a628a782fc643af3dd49986bbc77c23de1ae4726bc521c77f61abbbf5d</span>; p4 n+ `. x1 V0 z* T2 |/ C* v' y
<span style="color: rgba(0, 0, 0, 1)">    Image:         busybox
# ~5 W+ c! g4 v    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>' W6 c; u. K% I
    Port:          &lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
5 B8 b, U+ C! ?' z8 u    Host Port:     </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
& G+ c$ u! n( q% c' C' O  y    Command:
" q# [* i# I7 C# }      </span><span style="color: rgba(0, 0, 255, 1)">sh</span>
3 n( T( \; M9 U/ g      -<span style="color: rgba(0, 0, 0, 1)">c
$ G& q/ ?1 h; l; {% `" U/ F/ k      </span><span style="color: rgba(0, 0, 255, 1)">tail</span> -f /logs/<span style="color: rgba(0, 0, 0, 1)">log.out
# v; @: ]/ S, A- B( f& D6 m) z    State:          Running
2 g2 ]8 p3 x8 \8 |+ d: W      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)">/ B6 p" ?9 L9 ~8 G
    Ready:          True
8 d* v! |1 m: \0 R/ D  O    Restart Count:  </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">
6 a9 ]$ J0 m: ?% ], J    Environment:    </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">$ k4 j' B5 \8 [
    Mounts:$ B& a6 p0 \! {' n
      </span>/logs from webapp-<span style="color: rgba(0, 0, 0, 1)">logs (rw): P) `3 s* Z+ L% M/ G  a# F
      </span>/var/run/secrets/kubernetes.io/serviceaccount from default-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h (ro)
4 W. ?" p7 ]' D: z$ YConditions:+ i! z; l1 i3 |- Y! P
  Type              Status% L: N& V0 c# s% s6 o
  Initialized       True6 R) D/ c, N, l. E( G
  Ready             True0 c& @$ y( H, o8 b
  ContainersReady   True
9 [' y( ]4 O/ S& g7 y  PodScheduled      True; E* J( D* A+ B: d2 t
Volumes:4 g( V. X1 r8 d, J/ [5 V) k# K
  webapp</span>-<span style="color: rgba(0, 0, 0, 1)">logs:. D5 s3 O: r" Y( y! J
    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>
' w) _# n. e* v/ t6 ~6 X: r: ~<span style="color: rgba(0, 0, 0, 1)">    Medium:5 B- R+ y& |3 i) ], z+ h- k
    SizeLimit:  </span>&lt;unset&gt;<span style="color: rgba(0, 0, 0, 1)">& o) l# M- i# ?1 _8 u
  default</span>-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h:5 d! @" F8 ]9 k9 |" @
    Type:        Secret (a volume populated by a Secret)
2 I2 Q8 d5 q9 M0 s0 d5 \$ e- Q( Z8 s    SecretName:  default</span>-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h
: Z& T/ b9 l1 X# S    Optional:    </span><span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)">8 V9 h! `7 M* x+ ^, h
QoS Class:       BestEffort
$ P) A5 m$ w+ l- y7 _Node</span>-Selectors:  &lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">- I$ {9 g: X* R* Y9 l. U& V
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
3 ~+ t. [9 z- 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)"> 300s2 j6 d9 e  O( W/ t: X
Events:2 t8 r  M4 {0 L, j3 c' S) [6 p: S
  Type    Reason     Age    From               Message/ v  v& f. U5 K# Y
  </span>----    ------     ----   ----               -------<span style="color: rgba(0, 0, 0, 1)">: E* t5 A" L  x2 Q
  Normal  Scheduled  2m23s  default</span>-scheduler  Successfully assigned default/<span style="color: rgba(0, 0, 0, 1)">webapp to ayato% i& H. W; T! n: Y3 Q# I
  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
2 S" d2 r) x1 N& d$ w  Normal  Created    2m21s  kubelet            Created container webapp/ _% t1 ?: X& ^9 r7 G" ^/ D' N
  Normal  Started    2m21s  kubelet            Started container webapp( G+ y  v6 r- b
  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)">
& E6 L  H$ B9 J4 U3 {  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' B" m% `; `  S7 D# w* Q: S- e
  Normal  Created    15s    kubelet            Created container busybox
+ t& _  Q% Y4 S- ?  Normal  Started    14s    kubelet            Started container busybox</span></pre>
- P5 {0 g6 l4 q$ Y7 |1 u! @</div>- V: U  |! j; _' t8 g4 y
<p>真的是飞一般的感觉!!!</p>
1 U% u8 x7 U- X* c% s9 W4 d8 G<p>&nbsp;</p>1 Z/ l: M& E0 l) n. g" ]! ]
<p>三、Context和Namespace切换</p>1 c1 u5 r7 j( G- G% N
<p>我们在公司的容器平台上使用kubectl时,经常需要切换context和namespace,导致命令非常繁琐,那有没有简便的方式呢?—— kubectx</p>
& l/ ?+ X1 E* l<p>kubectx安装</p>
& s( R% ?7 [' o- O<div class="cnblogs_code">  j+ d3 C" T1 a1 V7 Z9 e9 p
<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>( V1 b) z4 ?5 |: U9 A
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)">...
, n# n" ]7 G+ c- z5 Z5 oremote: 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)">.3 ^/ q2 b0 ?$ l: I8 t, b
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)">.
! Y3 j5 ^) f9 W) T2 dremote: 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)">.) G# b- f' ~/ Q6 h4 S4 ~# o% h7 ^) J' \
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)">
! D/ g, \6 e4 e) p! P0 O7 w! zReceiving 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)">.
- U4 ]+ G% I( y8 ~2 e8 O* ?, wResolving 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)">.% v4 b0 s  f) m! 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)">ns4 g, M7 h. b2 ^6 R8 y8 _+ l7 o0 S
$ </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>
% g9 [- y" J$ x1 t8 E9 V2 p</div>! J, u& q3 v. Q
<p>我们来看一下效果:</p>
- L$ q' ^* N9 L7 F* c<div class="cnblogs_code">
9 r0 m2 K$ r- {0 |9 T/ l$ X5 u<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ctx
2 w/ V; ^; R: r( j+ ~' x$ Aminikube. U! n$ N, x3 O" `& F  m7 i4 y
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ctx minikube. l( `/ k' A% D5 e
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)">." P+ x9 S# b( `, Z: M0 E
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ns
; C; {  y, C* Z4 L! B+ Ddefault5 i# X- W4 W& H' g1 S
kube</span>-node-<span style="color: rgba(0, 0, 0, 1)">lease
( @/ m2 h2 n; @5 t( X, c4 {" Y$ x- |kube</span>-<span style="color: rgba(0, 0, 0, 1)">public8 M* \/ K1 [2 U$ K( h. ~9 q
kube</span>-<span style="color: rgba(0, 0, 0, 1)">system
/ g/ S+ @# h% nkubernetes</span>-<span style="color: rgba(0, 0, 0, 1)">dashboard
* b* @$ h3 l' {+ l6 f% K7 e$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span> k ns kube-<span style="color: rgba(0, 0, 0, 1)">public( A- x7 _' E$ y7 ^
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./ w9 L9 Z5 ^& c8 e
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)">.6 }1 r. p- d% q# B+ }
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ns default6 K/ g# {) F5 W, B, M' K
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.6 U; q7 n/ V; b1 b$ Z/ X% c  J! z8 w
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>
( A, y+ j1 _$ j3 q& _</div>
% x, f( z% ?8 _0 J+ z4 f<p>&nbsp;</p>) ~* r* ?: o5 |% h) h
<p>四、跟踪查看多个Pod的日志</p>, @7 Y7 v) {0 o7 S
<p>我们一般使用kubectl logs命令查看Pod日志,但是它不能通过-f参数同时跟踪查看多个Pod日志,这就不方便了,毕竟实际生产环境中每个服务都会有多个Pod,这时我们可以使用stern这个工具,它具备如下能力:</p>  O  ~5 N& L9 ?: O2 T: c
<ul class="list-paddingleft-2">
5 g8 }, g- O1 Y) {<li>
  `: U% w2 S. I$ I9 G<p>允许使用正则表达式来选择需要查看的PodName</p>0 B1 t- L, O6 P/ `4 Y8 \! N2 G
</li>
! S! [! s- q1 E<li>
9 ?& E0 h  w- g9 ?5 y$ t9 w3 t<p>为不同 Pod 的日志展示不同的颜色</p>. k$ P! J. @/ T1 j1 Z
</li>
- T6 V3 |7 e- r8 ]. H<li>
9 ^3 X  j( `8 e& D<p>跟踪日志过程中假如有符合规则的新 Pod 被创建, 那么会自动添加到输出中</p>
0 X# e7 o2 M/ f' u</li>
2 r* n  ~0 `" J% M* A; ^</ul>8 N( e+ V. e9 U5 E& u
<p>首先安装stern(下载stern时可能较慢可以多试几次):</p>
8 ]5 ]1 }  }" N<div class="cnblogs_code">
- m; ]/ T2 U; c! _8 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>9 v' t+ H, x3 ^! 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>% V- m! E( B1 K8 Z
<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>
; g! m0 D* N% b8 y/ e; a3 U& a( J' r</div>; H; O) q3 U( ~
<p>安装完毕后让我一起感受一下stern的魅力吧,我的Pod里面有两个容器:webapp和busybox,如果使用kubectl logs 还得指定具体的容器,而使用stern就没有这样的限制。</p>; @0 F; T% d) x6 k. ?
<div class="cnblogs_code">* x2 f4 q- V, ~3 K3 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)"> .: X# e1 \- r& [; k; p2 I
</span>+<span style="color: rgba(0, 0, 0, 1)"> webapp › busybox
: I  G8 K' M, I+ C3 T; \' Y( g- b# h</span>+<span style="color: rgba(0, 0, 0, 1)"> webapp › webapp
4 m  |6 L( S" hwebapp 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)">]; A4 i' d+ \$ [2 K- M/ u
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], Q5 c1 d+ c8 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)">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)">]
) I" q$ v- J8 [! n6 S) lwebapp busybox </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.324</span> [INFO ] [main] [org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/<span style="color: rgba(0, 0, 0, 1)">]] Initializing Spring embedded WebApplicationContext+ `2 N; n. O! Y9 \
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)"> ms2 Q, p- U7 n- z7 o
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)">+ o5 a5 s& c6 Y! d
webapp busybox </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">54.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)' i" Y2 f+ F' d( o' {! `! ^6 M9 N
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)">]
' D# ]0 V: n6 ^& z( Zwebapp 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)">" p5 E5 x2 h! |; I, w
webapp busybox </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">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)">)
0 C$ `) b( ]6 h& u9 R; Ywebapp webapp. E# |  `, P# z5 k# B. m, E4 [. V% s
webapp webapp   .   ____          _            __ _ _: Q  D: L3 U% h9 s
webapp webapp  </span>/\\ / ___<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">_ __ _ _(_)_ __  __ _ \ \ \ \</span>+ N/ z, n! h' j; B/ A( {
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>
. t! ?) A! u% Awebapp webapp  \\/  ___)| |_)| | | | | || (_| |<span style="color: rgba(0, 0, 0, 1)">  ) ) ) )0 X0 g. k  p7 G
webapp webapp   </span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">  |____| .__|_| |_|_| |_\__, | / / / /</span>
  T) \8 o  M: A9 j2 v) j/ nwebapp webapp  =========|_|==============|___/=/_/_/_/<span style="color: rgba(0, 0, 0, 1)">& Q8 `7 T  t1 m8 i- u( G9 q
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)">)
3 B# ?8 d; Z2 U# _4 f7 ?webapp webapp
% d- M( I# S/ v0 Fwebapp 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)
% B2 z$ O6 ^" D8 B1 [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
4 S, z9 X4 P- t& y7 @0 I7 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)
+ E  i" E! Q5 Awebapp 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)">]
  e( T/ P7 S7 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.200</span><span style="color: rgba(0, 0, 0, 1)"> [INFO ] [main] [org.apache.catalina.core.StandardService] Starting service [Tomcat]0 x2 P6 r1 m6 w% A' 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)">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)">]4 i9 t$ k; y# J7 x
webapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">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, V& T0 E7 P& Y5 o' z; \$ hwebapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">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
. h% y2 ^+ V2 V2 _# U3 ~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)">
! Y  B" m  v( H4 O6 n0 x: lwebapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">54.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 Z4 y( \: S: @: m3 Lwebapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">54.377</span> [INFO ] [main] [org.apache.coyote.http11.Http11NioProtocol] Starting ProtocolHandler [<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">http-nio-4567</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">]
9 g) d3 R6 e3 n& i  Zwebapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">54.481</span> [INFO ] [main] [org.springframework.boot.web.embedded.tomcat.TomcatWebServer] Tomcat started on port(s): <span style="color: rgba(128, 0, 128, 1)">4567</span> (http) with context path <span style="color: rgba(128, 0, 0, 1)">''</span><span style="color: rgba(0, 0, 0, 1)">% ~0 J# c" ~/ 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.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>* y3 }* w4 q1 U0 _% f3 i
</div>
$ Q9 ]" @5 ?5 P0 t! C<p>&nbsp;</p>4 v% _! z  W' l( p! S# T) o
回复

使用道具 举报

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

本版积分规则

手机版|飞雪团队

GMT+8, 2026-9-2 23:52 , Processed in 0.296457 second(s), 22 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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