飞雪团队

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

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

[复制链接]

9180

主题

9268

帖子

2万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
29870
发表于 2022-2-12 14:35:42 | 显示全部楼层 |阅读模式
, T# i( P( I' C9 b2 f- H9 _$ Z
<p>kubectl作为我们主要的操作K8S的工具,其具备非常丰富的功能,但是如果不经过打磨,使用起来还是存在诸多不便,今天我们来看看如何将我们的kubectl打磨的更加易用。</p>
! V! h5 d9 B. T; J; j+ ^<p>&nbsp;</p>) ~( g( q6 J$ m7 c  D' g: z( i3 V! e3 q! d
<p>一、命令自动补全</p>0 e: D+ i4 ]& t8 j; G% q
<p>kubectl中提供非常多的命令,如果每一次都要手动一个字符一个字符的敲未免太累了,那么如何配置自动补全呢?这里以ubuntu系统为例:</p>
# v& Q6 H) X0 [  y# i4 d- i<p>1、安装auto-completion工具</p>
1 N3 d6 [4 h: v) u. b, H) p) T6 i' h& w<div class="cnblogs_code">
8 C! e" d( ]: ]7 y<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> apt update$ I' k5 M; W+ H8 ?9 D
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>- G! Q2 X  r7 b0 ?
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>
3 U+ B" ~# h" _3 sHit:<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>' |; {- Y- v7 [8 c8 z- T* `: i
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 s7 ?( a- [+ v6 g7 B
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>
" [0 q: o3 {* z7 k4 g, Z- f' D<span style="color: rgba(0, 0, 0, 1)">Reading package lists... Done
/ Q# K( o  G( D0 P  A6 a! V, tBuilding dependency tree6 z* k- R, g- u8 w* Z5 M  n: x
Reading state information... Done/ w: Q5 I7 g# A) d0 L; W
</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.' j, W8 H2 E( 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
2 i; k" e# Y! F1 HReading package lists... Done  D4 z6 N( G8 P' k
Building dependency tree% B! c7 e' A6 y# b3 h
Reading state information... Done
3 S; f7 U: r. q4 K7 V1 kbash</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).  N3 V4 \& B6 K2 ?% u( W) s5 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># `% B% t6 P2 t5 O' x
</div>
0 T% J/ ~0 E6 u- K/ {/ f  Q5 {<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>
& d8 h2 D, N: t% J& F, o! n1 V! U) 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>
; i$ {$ w, X7 W, A' v<p><span class="js_darkmode__2" data-darkmode-color-16446330660319="rgb(163, 163, 163)" data-darkmode-original-color-16446330660319="#fff|rgb(0, 0, 0)" data-style="color: rgb(0, 0, 0);"><strong data-darkmode-color-16446330660319="rgb(163, 163, 163)" data-darkmode-original-color-16446330660319="#fff|rgb(0, 0, 0)">Bash</strong>:</span></p>
: s: J; N" C! f/ L& |& \: l, u2 G<div class="cnblogs_code">1 C2 B5 v; C6 x2 p9 p+ G
<pre>source &lt;<span style="color: rgba(0, 0, 0, 1)">(kubectl completion bash)- G2 S3 P) e+ H/ f
</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>
) c# R  Y* \8 k4 z; o1 s</div>
- J+ ]+ x+ |, U' I8 H<p><strong>Zsh</strong>:</p>
4 s, l# f/ Q0 ?<div class="cnblogs_code">
9 @) t) \- M8 E* w<pre>source &lt;<span style="color: rgba(0, 0, 0, 1)">(kubectl completion zsh)& I7 Y8 F( }2 R5 R& N1 [
</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>
; y* K& S. z; W8 M3 X. K# h2 @</div>3 {. S; J; b+ P0 k( O; N
<p>配置后就可以通过Tab键自动补全命令啦!</p>2 F" p5 r2 }, a6 d
<p>&nbsp;</p>& [" u6 H% Z' [6 t7 K
<p>二、配置kubectl别名</p>
! M1 m! Q$ w+ \* t5 _6 V% j<p>我们可以通过设置别名简化kubectl命令,编辑.bashrc文件,添加如下内容:</p>) c, D5 e+ x: D
<div class="cnblogs_code">
5 ], K  |% @8 m% P<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)">* ?6 n) A- t: F
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)">
# p( X+ h, N1 H- g6 G6 i. [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)">
! V- I$ i( l# g" 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)">
( L2 r* E/ b6 \% `) n) V# c, yalias 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)">
, Z1 E  D9 ~" W4 D2 Kalias 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)">
2 p, l0 s0 K  [5 X2 zalias 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>2 \. T% j6 W  r) R  A) r
</div>7 v9 c  i# r; E  j( r! x- b- h5 c$ 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>
9 Q' @9 E9 y: k$ x2 b7 M<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 ^' i- B6 [% j& a, G1 \
<div class="cnblogs_code">
, m2 W6 _) d1 m$ t+ g0 f" E' W, A<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> ka webapp_pod.yaml* W9 g6 @& W1 j  W/ x* J
pod</span>/<span style="color: rgba(0, 0, 0, 1)">webapp created$ h  s; Q6 g% U" |6 X
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> kg pods
9 e6 o# p$ i8 K3 D+ ]+ YNAME     READY   STATUS              RESTARTS   AGE
" F( W, p+ j' M. `" owebapp   </span><span style="color: rgba(128, 0, 128, 1)">0</span>/<span style="color: rgba(128, 0, 128, 1)">2</span>     ContainerCreating   <span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">          7s( b% g0 D  Q9 N' v8 H+ W
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> kd pod webapp7 c, d. e9 s+ h8 N7 ?
Name:         webapp# U6 |0 x) x1 c0 q- }; n# n
Namespace:    default
4 j5 I4 u8 W" s# k' zPriority:     </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">1 Z6 P- ^. ]0 P% G
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)">
" c& f; i8 F1 Q  nStart 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)">0 d5 H) R1 G8 F( M
Labels:       app</span>=<span style="color: rgba(0, 0, 0, 1)">webapp/ H- |' v$ b: U1 o
Annotations:  </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
( _% @8 a( i/ Y0 R! f* V2 G, G4 QStatus:       Running1 L; h1 [7 m9 X5 Y  {! V& ]0 E
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)">
$ t3 D! M0 d  s- Y" @8 i2 U5 A' eIPs:8 R- {/ G8 U' e' v
  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)">
' f6 f) |$ ]0 {5 ?5 A! I9 E8 SContainers:
$ Y7 O' g5 j! n" s: u+ C4 C+ I  webapp:
& x9 q% i! h. N: p. C1 \1 _    Container ID:   docker:</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">d9ddf9dd47de12b53f2119bf75df6706bee2e7711509638ad52adc9addeda704</span>
$ z; U) R7 A/ C3 x; A! W3 k5 s    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)">& s. f" v& \! g5 d9 C7 w: |/ y# A
    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>
9 P8 x$ M" U& f- A    Port:           <span style="color: rgba(128, 0, 128, 1)">5000</span>/<span style="color: rgba(0, 0, 0, 1)">TCP8 J5 r/ V3 c: ]1 j2 m
    Host Port:      </span><span style="color: rgba(128, 0, 128, 1)">0</span>/<span style="color: rgba(0, 0, 0, 1)">TCP
: R. A) W$ ^# d6 a    State:          Running% V3 g/ @  ]7 N! z4 F2 t4 X
      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)">
0 z' n3 y' O  r% s    Ready:          True) W* B9 o# I; S1 Q7 O7 C9 j
    Restart Count:  </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">' Z  p; t4 I, U" e
    Environment:    </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
) G$ F7 |* e) M* a8 m    Mounts:4 m9 K6 f' Q2 t9 j7 \! L5 @
      </span>/tmp from webapp-<span style="color: rgba(0, 0, 0, 1)">logs (rw)
6 t2 D3 q$ J) j2 G7 a' v4 R8 `5 k3 U      </span>/var/run/secrets/kubernetes.io/serviceaccount from default-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h (ro)
, c9 B8 E' j7 w# p1 |& n, W  busybox:/ h( f: z' b9 x) }; M+ ?2 j
    Container ID:  docker:</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">6a6a35a628a782fc643af3dd49986bbc77c23de1ae4726bc521c77f61abbbf5d</span>  C+ b) `$ X& {+ t. U8 Y8 W) j
<span style="color: rgba(0, 0, 0, 1)">    Image:         busybox+ [8 `# [& z2 m1 t
    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>
2 r" w' d- c. l    Port:          &lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
; W; ^, u' O9 ~    Host Port:     </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">8 P# N) i) W: l% Z
    Command:+ m  h' G! H8 i0 i
      </span><span style="color: rgba(0, 0, 255, 1)">sh</span>7 D) V& W5 i" D& r: u9 N) Z* t; e: G
      -<span style="color: rgba(0, 0, 0, 1)">c
+ w& Z# g# Z. l5 [* t0 ?. z; ]% `7 s      </span><span style="color: rgba(0, 0, 255, 1)">tail</span> -f /logs/<span style="color: rgba(0, 0, 0, 1)">log.out
, k3 t3 b8 G3 X    State:          Running
1 O& L; n/ N0 ?: K- b( t) b# R0 L      Started:      Wed, </span><span style="color: rgba(128, 0, 128, 1)">09</span> Feb <span style="color: rgba(128, 0, 128, 1)">2022</span> <span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">06</span>:<span style="color: rgba(128, 0, 128, 1)">53</span> +<span style="color: rgba(128, 0, 128, 1)">0000</span><span style="color: rgba(0, 0, 0, 1)">* m9 [- X4 N- I
    Ready:          True/ ]3 c' G! ^4 T- v
    Restart Count:  </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">' O% s' g! H% L: L; a6 O+ r
    Environment:    </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
7 a2 z+ B7 c8 }4 U3 ~0 e    Mounts:: Z' n1 S0 g0 g9 E6 u4 h) P% I
      </span>/logs from webapp-<span style="color: rgba(0, 0, 0, 1)">logs (rw)
' M/ a$ Z+ g$ E" ^/ t      </span>/var/run/secrets/kubernetes.io/serviceaccount from default-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h (ro)
  J1 v1 U6 m0 ^- nConditions:1 {% K8 F4 @2 W3 M- S) x" A
  Type              Status
  ^- T5 D9 |/ R+ }% H7 h. ~0 c  Initialized       True
5 s+ O- r" q& g; y$ X+ b  Ready             True2 z/ K1 S7 Q* r0 P
  ContainersReady   True# t# [: O2 s) ?  E* r' s
  PodScheduled      True& h( u+ R& u7 Z4 K$ z
Volumes:2 L! K8 Y& y) _; z- ~. n
  webapp</span>-<span style="color: rgba(0, 0, 0, 1)">logs:
% t/ a0 V# J# m: j9 o( C) k/ p& v    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>5 O* j/ p% s% J& ^2 j7 ~4 D' l
<span style="color: rgba(0, 0, 0, 1)">    Medium:; f( D- O* _1 {3 r& r# b+ ?) t3 J) [
    SizeLimit:  </span>&lt;unset&gt;<span style="color: rgba(0, 0, 0, 1)">/ ]8 S) C+ V6 w
  default</span>-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h:5 D7 x7 V  K* X9 m$ W  t7 G
    Type:        Secret (a volume populated by a Secret)
( q1 d, C5 V# W    SecretName:  default</span>-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h( x8 b1 L$ {" W+ J
    Optional:    </span><span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)">+ g7 N/ d: P4 q/ P% ]( J- ~$ K
QoS Class:       BestEffort. Q! J, V; F( t) N" W4 i4 j- W
Node</span>-Selectors:  &lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">3 ^: i& w6 `- p# a
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
$ E2 x0 k$ n* \5 n6 ]4 D                 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
" b1 w# b% Q' Z: B7 C/ ^! P# X! REvents:. i$ n* u. Y' b. O1 i2 x# g2 H
  Type    Reason     Age    From               Message( a, t: u- y1 Z) [/ T3 B
  </span>----    ------     ----   ----               -------<span style="color: rgba(0, 0, 0, 1)">
6 ]# J6 P- G8 ~# \6 w. K  Normal  Scheduled  2m23s  default</span>-scheduler  Successfully assigned default/<span style="color: rgba(0, 0, 0, 1)">webapp to ayato
6 ~2 \! ]$ M  a. e; |6 ~8 \  Normal  Pulled     2m22s  kubelet            Container image </span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">172.16.194.135:5000/webapp:1.0</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)"> already present on machine
& |+ e* v$ x. _2 T7 P  Normal  Created    2m21s  kubelet            Created container webapp" d3 w, ]' b* K6 v, d+ C0 q( B; ]6 j
  Normal  Started    2m21s  kubelet            Started container webapp
4 F. P! r7 X( f, G, A! w  x7 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)">% }1 i$ c+ ~! s
  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
1 M3 j: Z: y6 U4 A  Normal  Created    15s    kubelet            Created container busybox
( E& ^1 |6 g. i1 g  Normal  Started    14s    kubelet            Started container busybox</span></pre>
- e) ^, I- W3 U2 k: P</div>+ a5 }( Q! g# K$ u
<p>真的是飞一般的感觉!!!</p>+ x) R& q1 M/ _( ?
<p>&nbsp;</p>
$ T5 [% s1 |' f# H" `- a0 Y1 o2 p) Z<p>三、Context和Namespace切换</p>
  ^& B; j( V# O" f6 I0 [<p>我们在公司的容器平台上使用kubectl时,经常需要切换context和namespace,导致命令非常繁琐,那有没有简便的方式呢?—— kubectx</p>! C, k. s$ y2 {. v; ?5 w
<p>kubectx安装</p>' P6 P7 d6 h9 @8 w) L/ P
<div class="cnblogs_code">8 u1 e( ]% I+ d' q+ @$ u
<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" s" d5 n, W7 g5 C. jCloning into <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">/opt/kubectx</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">...
- y7 `) p0 T, A% z# {4 y( @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)">.
* _7 c' _. Z9 C9 j- J( Cremote: 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)">.# I$ G* C6 A% H1 F9 S( Y; K" s% E5 w
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)">.
0 P, C/ ^9 r: |8 U9 \# A$ @0 z4 }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)">1 Z3 A. h+ h) G3 m6 b: L+ G' ?
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)">.$ y( C! B" ^! I& q
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)">.
3 ~- o: w7 u9 N' M; p. R, R$ </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 k2 y- d# W" W/ K' v) g" e, j
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span> <span style="color: rgba(0, 0, 255, 1)">ln</span> -s /opt/kubectx/kubectx /usr/local/bin/kubectl-ctx</pre>
' t  D% y: _4 {1 B( t1 n</div>
4 ?, X! }  O. \3 G1 H<p>我们来看一下效果:</p>/ ?/ }& b* C# d' c8 [7 E: L  t
<div class="cnblogs_code">3 n* [5 y; M+ t
<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ctx* }7 r% ]$ P# w  ~, K7 T7 c
minikube3 R; y  G+ Q/ I/ A& Z8 C
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ctx minikube
2 q) x0 f  K# U, eSwitched 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)">.7 o$ G: T( o/ q% v% e
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ns
; |6 ]! A: X, p, {- [$ x! Adefault
6 l- k2 c# L0 ]" h5 C# Lkube</span>-node-<span style="color: rgba(0, 0, 0, 1)">lease
, ]  A5 a! Q  C% t, Ukube</span>-<span style="color: rgba(0, 0, 0, 1)">public
  w6 ]( L+ G1 ?* B( @% J  Tkube</span>-<span style="color: rgba(0, 0, 0, 1)">system% O, b" m' |2 z7 j. ^$ Q& J1 e8 c
kubernetes</span>-<span style="color: rgba(0, 0, 0, 1)">dashboard" Y0 Y* ~! P, ?6 K
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span> k ns kube-<span style="color: rgba(0, 0, 0, 1)">public
- y( u8 q5 v  O: ~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.
$ H5 x" h& f/ F1 _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)">.. @5 U. s/ i3 \# X2 k0 b' F: P
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ns default
, U" Q7 ^8 {% N6 J5 r" D2 AContext </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.' X0 L; f' y" ~1 K& U
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>
6 |7 ?* T6 H8 b6 t9 U7 q</div>
4 Z( _4 ?5 W# _% ^( u! @) o$ j: S<p>&nbsp;</p>
, W1 `# Z1 o' A) `6 f* A<p>四、跟踪查看多个Pod的日志</p>
2 n" y$ I3 Q, U3 T8 v* o<p>我们一般使用kubectl logs命令查看Pod日志,但是它不能通过-f参数同时跟踪查看多个Pod日志,这就不方便了,毕竟实际生产环境中每个服务都会有多个Pod,这时我们可以使用stern这个工具,它具备如下能力:</p>* m# H9 {6 K/ h" j; Q
<ul class="list-paddingleft-2">; F5 I) K! ]' D4 h, N6 |( B
<li>
8 G. `) j; g' C# P$ O<p>允许使用正则表达式来选择需要查看的PodName</p>
$ P+ s. `! ]: p; E& V/ d6 G$ V</li>
, X) I& B3 M' Y<li>2 @+ d  J1 B( g- ?7 k- m$ ?
<p>为不同 Pod 的日志展示不同的颜色</p>- n" g- t8 ]7 o! ~/ w9 ^
</li>
) l* ]; ]" t+ H<li>3 y2 u/ n/ a# H
<p>跟踪日志过程中假如有符合规则的新 Pod 被创建, 那么会自动添加到输出中</p>
& x  C1 N- X5 D$ r" H/ C" [. w</li>
6 f: [5 Y; v: p7 a; n</ul>" B5 G( e3 ~& N) Z+ f- o+ a" A4 H2 ?
<p>首先安装stern(下载stern时可能较慢可以多试几次):</p>& q: W, W2 k/ p, o4 G
<div class="cnblogs_code">
6 |. V1 Y/ h0 g4 S1 o: _) L, 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>& H: O: O! y1 s7 |( G
<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>
+ ~& N6 @1 l( }( K. @<span style="color: rgba(0, 0, 255, 1)">sudo</span> chomd +x /usr/local/bin/kubectl-<span style="color: rgba(0, 0, 255, 1)">tail</span></pre>
& ~7 ~, M5 j' t+ d0 V5 ^</div>" {! ^! w2 L6 I' `6 D/ W1 v
<p>安装完毕后让我一起感受一下stern的魅力吧,我的Pod里面有两个容器:webapp和busybox,如果使用kubectl logs 还得指定具体的容器,而使用stern就没有这样的限制。</p>
" _% @9 U' z' h) b+ a$ L: W<div class="cnblogs_code">
& Y5 H' E4 t! E<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)"> .
+ D4 m  O3 P  d- y</span>+<span style="color: rgba(0, 0, 0, 1)"> webapp › busybox: b3 J& t, p5 O. a. ]) X& B+ Y: N
</span>+<span style="color: rgba(0, 0, 0, 1)"> webapp › webapp  v" n6 @3 D8 e2 a1 g. e  t4 @+ g
webapp busybox </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.197</span> [INFO ] [main] [org.apache.coyote.http11.Http11NioProtocol] Initializing ProtocolHandler [<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">http-nio-4567</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">]
7 d: h7 w) S8 L8 s- ~: b4 O- Dwebapp busybox </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.200</span><span style="color: rgba(0, 0, 0, 1)"> [INFO ] [main] [org.apache.catalina.core.StandardService] Starting service [Tomcat]+ N# g6 O  @, V6 a
webapp busybox </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.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)">]
; ~" g1 N1 h$ `2 v6 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)">53.324</span> [INFO ] [main] [org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/<span style="color: rgba(0, 0, 0, 1)">]] Initializing Spring embedded WebApplicationContext
  v6 n  l) d, @6 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.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; A! Q4 Q/ |, b7 r  J+ V$ 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.801</span> [INFO ] [main] [org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor] Initializing ExecutorService <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">applicationTaskExecutor</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">
2 Y3 [; G/ [, H2 Z5 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)">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)
5 d$ z  K, k: 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)">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)">]
  _+ X) v8 W$ e5 W1 P  _/ Kwebapp busybox </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">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)">
) y7 e! g0 g3 F' J* ywebapp 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 ~# M' ^4 `( xwebapp webapp1 w5 {& @. B- B
webapp webapp   .   ____          _            __ _ _
% z: o. X6 W* F2 e5 w4 x  _webapp webapp  </span>/\\ / ___<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">_ __ _ _(_)_ __  __ _ \ \ \ \</span>
' v. L5 y, ]7 I, u2 Pwebapp webapp ( ( )\___ | <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">_ | </span><span style="color: rgba(128, 0, 0, 1)">'</span>_| | <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">_ \/ _` | \ \ \ \</span>
& M# s! T. r4 {# uwebapp webapp  \\/  ___)| |_)| | | | | || (_| |<span style="color: rgba(0, 0, 0, 1)">  ) ) ) )
! O, [$ w) i+ y% N4 ^  k- C; H" {webapp webapp   </span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">  |____| .__|_| |_|_| |_\__, | / / / /</span>' Q9 e1 O) [/ u
webapp webapp  =========|_|==============|___/=/_/_/_/<span style="color: rgba(0, 0, 0, 1)">7 |  {8 o1 [. B" K  ~" 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)">)
/ k- p  O/ E: _7 H5 |webapp webapp% q: n% E4 {# v" W7 ~, 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)">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)% C7 |- N1 v0 W. 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)">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
; G) b4 J3 U8 ^webapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.158</span> [INFO ] [main] [org.springframework.boot.web.embedded.tomcat.TomcatWebServer] Tomcat initialized with port(s): <span style="color: rgba(128, 0, 128, 1)">4567</span><span style="color: rgba(0, 0, 0, 1)"> (http)' C2 R4 _6 Z5 K- I& v
webapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">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)">]
- z8 C8 d, W9 `5 ]# ~- 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.200</span><span style="color: rgba(0, 0, 0, 1)"> [INFO ] [main] [org.apache.catalina.core.StandardService] Starting service [Tomcat]9 C' i4 a+ q6 b% 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.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)">]
; W' x+ Z; J1 M! r: 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)">53.324</span> [INFO ] [main] [org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/<span style="color: rgba(0, 0, 0, 1)">]] Initializing Spring embedded WebApplicationContext
) E6 r& A6 B/ j( j( h3 iwebapp 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
4 c' o. y: m% B8 _2 F+ i5 u- 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)">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)">
3 K' I! s8 Z9 z& N2 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)">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)
: E0 R, L7 _  x' @, c1 q  qwebapp 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)">]
  x% C8 N; `: `4 P7 L4 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.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 |% w$ ]# B$ d9 D* E6 f4 s
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>( _- ?2 u. F8 x  R
</div>8 {/ F6 @- p" W. T! I3 |
<p>&nbsp;</p>
0 q5 b. i8 Q0 n" r/ `
回复

使用道具 举报

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

本版积分规则

手机版|飞雪团队

GMT+8, 2026-9-9 11:45 , Processed in 0.067741 second(s), 21 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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