飞雪团队

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

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

[复制链接]

7903

主题

7991

帖子

2万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
26039
发表于 2022-2-12 14:35:42 | 显示全部楼层 |阅读模式
) `. K% H9 A3 I
<p>kubectl作为我们主要的操作K8S的工具,其具备非常丰富的功能,但是如果不经过打磨,使用起来还是存在诸多不便,今天我们来看看如何将我们的kubectl打磨的更加易用。</p>- `& u% ?, w& q, p* F) A
<p>&nbsp;</p>
/ c3 r3 o; C7 }2 a% J7 m<p>一、命令自动补全</p>
8 b; ?1 u$ Q  t) H4 K<p>kubectl中提供非常多的命令,如果每一次都要手动一个字符一个字符的敲未免太累了,那么如何配置自动补全呢?这里以ubuntu系统为例:</p>
) n5 u/ a8 R  A9 F, T) q<p>1、安装auto-completion工具</p>7 b9 Z2 k2 K: Y3 C2 W
<div class="cnblogs_code">
- [, d6 `1 V2 ?; I4 s2 x<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> apt update" S3 a( u4 q5 W
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>
5 L' }7 l9 g& i9 Y/ oHit:<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>( B% ?- C$ s0 q
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>
  ^; G5 P& ]& G* w# kHit:<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>
8 y+ d/ Z1 o1 a! L6 f2 P3 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>, L3 u1 F7 f3 k8 _, A1 ~% L
<span style="color: rgba(0, 0, 0, 1)">Reading package lists... Done* i* ~. @0 I5 w! ]
Building dependency tree$ f8 ~  A9 A; k% c$ ^+ N- s
Reading state information... Done0 z2 [4 f# E% X7 Z0 H" z) T* 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.
. ^) `; |; Z) f! C7 @$ </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- {* L; J) }8 m. ?- h
Reading package lists... Done
. }1 G2 i' g; `Building dependency tree# Q; g) b# \# U" Y' h; Z* \
Reading state information... Done' |5 T6 g$ l" H$ G. g
bash</span>-completion is already the newest version (<span style="color: rgba(128, 0, 128, 1)">1</span>:<span style="color: rgba(128, 0, 128, 1)">2.8</span>-<span style="color: rgba(0, 0, 0, 1)">1ubuntu1).
1 y2 k9 l8 I$ i" {' N</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>
- z9 ?; C! r% w. [5 l2 O</div>
9 e0 x+ c3 R& w% v  D9 X7 S+ G<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>
; B( \" k- ^/ t3 U" R1 i<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>& k+ j" m+ s2 O* K
<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>4 W  Z) @. ?8 x* f; d
<div class="cnblogs_code">+ e/ {- Z' g! `5 u/ s% Y' `: V2 Y
<pre>source &lt;<span style="color: rgba(0, 0, 0, 1)">(kubectl completion bash)
) [0 [4 `3 s( }" 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>
0 n* y9 y/ j; g) |$ t3 U* ]: n</div>
& |' r3 f2 N7 {6 o3 p<p><strong>Zsh</strong>:</p>
9 N, k$ R. c/ W5 A5 A# @( y<div class="cnblogs_code">/ J: ^5 A/ ?  `$ I1 v2 O' Q. b+ L
<pre>source &lt;<span style="color: rgba(0, 0, 0, 1)">(kubectl completion zsh)
* F1 L5 d/ V7 l, }. T2 q</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>  B& I( N+ G. h* A
</div>
0 @- W# B5 H3 c1 m+ q<p>配置后就可以通过Tab键自动补全命令啦!</p>
; ~5 H/ A! V/ X& f' ]<p>&nbsp;</p>) m" R( {/ U/ l9 o  q: o6 p3 w
<p>二、配置kubectl别名</p>
- f: u0 N- x4 d) v* B: Q+ R/ U<p>我们可以通过设置别名简化kubectl命令,编辑.bashrc文件,添加如下内容:</p>
: a! ~  {; Z3 R  y% _9 @8 G4 S<div class="cnblogs_code">
. r" [, A- n% b' `<pre>alias <span style="color: rgba(0, 0, 255, 1)">sudo</span>=<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">sudo </span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">: @: ~$ F: I( O; j0 b) C$ s0 n
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)">& a/ c* y3 w+ Z4 [& a/ _. A" ^
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)">$ f; D. @! m( C+ j, P1 I# C
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)">
/ E5 Y' f" R+ z2 U/ s$ ~2 p" w6 K3 y+ Lalias 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)">* ~/ p- `3 L; J
alias kg</span>=<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">kubectl get</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">
0 i. r) }9 E5 x# W/ Palias 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>
; s/ e, O! j0 Y) b: H) H: f6 P</div>
* F' h7 d5 \! f$ U2 O<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 ?" q4 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>' A; T; n; {: o" \/ K0 ?" S
<div class="cnblogs_code">
( A. e3 X- g6 o; t! V3 I<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> ka webapp_pod.yaml
3 @2 H' W  }2 ?6 n# E% L! z. p- tpod</span>/<span style="color: rgba(0, 0, 0, 1)">webapp created
( }0 H$ Q% |2 S/ u  G1 A, z$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> kg pods9 K+ k4 z; F- J7 y8 _
NAME     READY   STATUS              RESTARTS   AGE
3 d7 Q) F9 n; Mwebapp   </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
0 y5 m  G$ u$ y4 q! w0 B$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> kd pod webapp
* K$ L; j3 o( N5 s2 tName:         webapp4 L3 i$ X, }" G% n& D* n; y$ f
Namespace:    default, m) d4 Q- ]* T6 t. t! @
Priority:     </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">" d9 W* t7 w7 A$ B6 l5 R9 I
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)">
# m$ a3 j4 [& d) UStart 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)">( G. k( G3 Z! d) }1 T* Z- y: f
Labels:       app</span>=<span style="color: rgba(0, 0, 0, 1)">webapp
1 U) D* a0 ~+ r0 r- ]Annotations:  </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
4 L0 s) |. v& M, O$ fStatus:       Running
, ^; w( p2 K2 w6 F4 M2 B% yIP:           </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)">- {& ]/ N0 A* F) r/ |! r
IPs:
5 v$ p3 x8 Q; D  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)">3 ~: U$ C& `" b0 X* ?
Containers:0 |. s+ O  o$ f+ A- i
  webapp:
- o& N' x$ J2 B    Container ID:   docker:</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">d9ddf9dd47de12b53f2119bf75df6706bee2e7711509638ad52adc9addeda704</span>
& o' E% d6 W1 O1 ], \    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)">+ R- F: P$ a5 B4 h7 g- m
    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>/ Y: [* _% X, [
    Port:           <span style="color: rgba(128, 0, 128, 1)">5000</span>/<span style="color: rgba(0, 0, 0, 1)">TCP
( x8 ?4 z4 o: v  T    Host Port:      </span><span style="color: rgba(128, 0, 128, 1)">0</span>/<span style="color: rgba(0, 0, 0, 1)">TCP4 v9 U7 c6 K, K' G) C; w# a
    State:          Running
5 t( h2 ~3 y/ `" q% q      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)">6 Q4 C( g) ?5 n1 ~3 \2 F
    Ready:          True" `, d6 v& q  ^5 ]; w* Q
    Restart Count:  </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">
' }; ?- B) v& u    Environment:    </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">/ @) J, P" r& |+ V. n+ ?
    Mounts:
. i) b4 {, e/ Q% x      </span>/tmp from webapp-<span style="color: rgba(0, 0, 0, 1)">logs (rw)
' }9 ~/ w3 \: A% g4 f4 j/ D      </span>/var/run/secrets/kubernetes.io/serviceaccount from default-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h (ro)
8 @, [1 m+ K1 N  busybox:
3 C: l9 G1 Y( S' O2 j% X" J2 Z6 \    Container ID:  docker:</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">6a6a35a628a782fc643af3dd49986bbc77c23de1ae4726bc521c77f61abbbf5d</span>' {3 `0 n9 \: c5 T
<span style="color: rgba(0, 0, 0, 1)">    Image:         busybox
) S+ V7 i- A& }& K% W1 `    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>9 w( D& b+ f% n1 u8 u; {2 a% A
    Port:          &lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
) t! J5 r# v2 m3 _, G6 P, Q    Host Port:     </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
2 M5 c& q& V6 g0 J; R    Command:+ N/ m0 f' @' |' m, D+ k( a/ l/ _
      </span><span style="color: rgba(0, 0, 255, 1)">sh</span>
1 e2 Z3 U' G. B& Q      -<span style="color: rgba(0, 0, 0, 1)">c2 y# o8 ?' y/ o
      </span><span style="color: rgba(0, 0, 255, 1)">tail</span> -f /logs/<span style="color: rgba(0, 0, 0, 1)">log.out5 y. X7 h$ S5 I1 ^& _
    State:          Running
8 c# n4 H9 J* b, ~5 ~* `; 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)">' _6 h8 z# v* g% H
    Ready:          True
8 h* m& I. c0 e, U1 I    Restart Count:  </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">. e+ o( E7 u$ U- B# M8 K
    Environment:    </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">9 l% b4 N8 \  _% B; r* }5 \
    Mounts:
  T1 w  i8 p7 T8 L      </span>/logs from webapp-<span style="color: rgba(0, 0, 0, 1)">logs (rw)
4 ^4 L/ Y" b! z2 z  @) b      </span>/var/run/secrets/kubernetes.io/serviceaccount from default-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h (ro): U* n" Y7 M' C$ x+ w+ d/ T: X
Conditions:
  s& u5 F& E' h6 }3 V$ a  Type              Status
, }. ?; r7 z8 m, |* `5 @; s$ y( t  Initialized       True
# p# C2 Y8 n$ @& |+ l  Ready             True
9 P4 ?6 J/ f8 V* P2 c  ContainersReady   True8 B6 ~/ T  o% @9 F$ o; ~' X
  PodScheduled      True$ `8 s/ N+ ?) ~: [5 S) u
Volumes:
: y* ^0 O; w# t/ a" p! B4 Z' R  webapp</span>-<span style="color: rgba(0, 0, 0, 1)">logs:! G9 O$ p2 B( F( I% D* a# ~7 o
    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>! f, V" G% P* H; x, {1 ?
<span style="color: rgba(0, 0, 0, 1)">    Medium:
/ _- F$ F$ @6 S" r6 _% ^3 Z+ b    SizeLimit:  </span>&lt;unset&gt;<span style="color: rgba(0, 0, 0, 1)">/ W; G- e- j8 B$ U, l& j. o1 Q
  default</span>-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h:
, Y, H" T  ~  T% P& g    Type:        Secret (a volume populated by a Secret)
9 \5 `. \- h1 l/ A& |    SecretName:  default</span>-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h0 F) E: d% |' s0 I/ w. V
    Optional:    </span><span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)">
- T- R+ ]0 W1 ?QoS Class:       BestEffort# s$ i2 j  _& \. ?1 S4 y" q
Node</span>-Selectors:  &lt;none&gt;<span style="color: rgba(0, 0, 0, 1)"># f, S3 x1 d' w; C3 E/ @7 k+ g* 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)"> 300s0 t, c+ R* L+ j. F) S$ K
                 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) a9 J) s$ ?, ?
Events:
3 S+ Y$ E- ?9 f" W' S  Type    Reason     Age    From               Message+ X2 x" t& c7 z% N
  </span>----    ------     ----   ----               -------<span style="color: rgba(0, 0, 0, 1)">
* ?3 I+ @$ ^  H; s; [0 w  Normal  Scheduled  2m23s  default</span>-scheduler  Successfully assigned default/<span style="color: rgba(0, 0, 0, 1)">webapp to ayato; i) }! l  @9 h, |% b. p
  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. D7 ]: L' R, V3 ^- n9 O9 s1 c- b
  Normal  Created    2m21s  kubelet            Created container webapp9 A8 j1 z4 S0 _$ D4 S
  Normal  Started    2m21s  kubelet            Started container webapp
9 i9 F! Y6 r5 P% G1 F4 o  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)">
) F" y' ^6 v8 p$ P9 S# v  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
% W' Q0 N9 y% |+ o1 ?  Normal  Created    15s    kubelet            Created container busybox. Z. L2 d" G: m! f, L9 U
  Normal  Started    14s    kubelet            Started container busybox</span></pre>3 b1 ?( s# `& x; x
</div>
9 @) w! g  k+ |( x+ w2 i$ j+ w; {<p>真的是飞一般的感觉!!!</p>
) N) B) G7 N  P( J  K" i<p>&nbsp;</p>( \! o! l1 W! D. O' x
<p>三、Context和Namespace切换</p>* K; X& v/ s* j% T; t! j' ?; v
<p>我们在公司的容器平台上使用kubectl时,经常需要切换context和namespace,导致命令非常繁琐,那有没有简便的方式呢?—— kubectx</p>+ K' P( h, j  _9 K/ L5 `
<p>kubectx安装</p>: T  z! ]0 t0 }" K+ S
<div class="cnblogs_code">
4 o% H! ?  M1 c7 Q" U# Z8 r" w( Q<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>$ B3 s: X+ _2 {9 t* b* L
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)">...
1 W; i, v. Q6 c9 ?5 D: ~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)">.2 H1 b3 b+ Y7 `& m( T0 }" p. I
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)">.
/ H3 S  e9 i9 d, E: ?+ p# cremote: 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)">.
" v% X; y5 U9 a; o3 Gremote: 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)">
) n- ~+ M7 j0 G9 H) nReceiving 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)">.
6 V! u3 Q" }. D! Q( U% VResolving 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)">.1 L& I- h6 H( ^) a" V
$ </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
+ w7 g; q7 t0 u4 [9 i3 v$ </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>, a* K, u+ g- C. k9 X% ?" V  T
</div>
) Q$ }8 ]# U! t4 w$ C, g<p>我们来看一下效果:</p>
0 g2 f; F# y6 [: L% l$ L<div class="cnblogs_code">
% d8 X; d0 Y) h8 f  p, N: M; ]<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ctx$ N: r, X3 c# p
minikube* @* A+ f6 j, \
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ctx minikube
5 Z8 w, K3 `9 E$ H1 nSwitched 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)">.+ W" |/ F. m# p7 L
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ns
/ b+ I) V2 a# z& m1 }, K# q4 a% N0 }& Tdefault% X2 ^8 q0 K2 X. c! Z3 y% ]3 |
kube</span>-node-<span style="color: rgba(0, 0, 0, 1)">lease
+ e& q( t% K+ C! Bkube</span>-<span style="color: rgba(0, 0, 0, 1)">public- R% R, g: ~3 z4 n  ?- S6 t
kube</span>-<span style="color: rgba(0, 0, 0, 1)">system
0 T8 E/ N5 I+ c; M. skubernetes</span>-<span style="color: rgba(0, 0, 0, 1)">dashboard$ N  k% `3 x% H  H: u  U4 h- e
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span> k ns kube-<span style="color: rgba(0, 0, 0, 1)">public9 `4 P2 }9 d% Z  k* Z
Context </span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">minikube</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)"> modified.9 b! m* P$ W0 g* W- Z0 `/ |0 R
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)">.- d1 ^' N! G$ N7 U8 u& M9 H
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ns default
$ f: O9 C0 b1 kContext </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.
: _9 G6 S, p- W- J9 XActive 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>
/ S, `( w& d. W. ]& A3 w</div>6 r7 h" V. f* m$ Y$ |8 D3 Z, X- t, e
<p>&nbsp;</p>' e9 o1 v2 u5 P5 X
<p>四、跟踪查看多个Pod的日志</p>
2 c% I- \) ]& A' i<p>我们一般使用kubectl logs命令查看Pod日志,但是它不能通过-f参数同时跟踪查看多个Pod日志,这就不方便了,毕竟实际生产环境中每个服务都会有多个Pod,这时我们可以使用stern这个工具,它具备如下能力:</p>
- s# V8 z) s7 J<ul class="list-paddingleft-2">
6 K: P7 Y# H5 n<li>1 P) V6 S/ ]7 S" i
<p>允许使用正则表达式来选择需要查看的PodName</p>
1 Q1 @/ y' K9 l, @, P3 V. V: ~! ?2 S</li>
$ \3 {3 H+ f; y+ J: s3 t' t<li>
3 Q* p4 X6 b* Z. I* E- D<p>为不同 Pod 的日志展示不同的颜色</p>: _2 t. s& N  b9 b$ Y( v- |
</li>6 e: j6 P7 P# r
<li>
5 }1 [! |) q  B8 N) q9 z( ^, d9 H<p>跟踪日志过程中假如有符合规则的新 Pod 被创建, 那么会自动添加到输出中</p>8 c/ j5 A5 |$ R4 L. h3 \
</li>8 L) y; s* f4 z2 n+ u4 o
</ul>1 f7 E- W& S1 a0 ?
<p>首先安装stern(下载stern时可能较慢可以多试几次):</p>
8 ~' b1 \0 H* G<div class="cnblogs_code">
6 l; i+ z/ k( w! `1 e! X<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>
& d4 O  @" \6 E+ \  |, D: x<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>
7 y/ d' r0 l6 D! E: p<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>1 X1 l$ S& A% ?/ {% z1 X5 x8 r/ {
</div>
4 s, q0 f# f# z- F<p>安装完毕后让我一起感受一下stern的魅力吧,我的Pod里面有两个容器:webapp和busybox,如果使用kubectl logs 还得指定具体的容器,而使用stern就没有这样的限制。</p>
$ e- F, Q7 @3 \% p<div class="cnblogs_code">
! d6 i$ F; T  ^8 z4 f4 F5 ^" ^<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)"> .
- ~! L  G* [! ~</span>+<span style="color: rgba(0, 0, 0, 1)"> webapp › busybox
2 D$ X* g  b& n$ e* |</span>+<span style="color: rgba(0, 0, 0, 1)"> webapp › webapp
7 \7 ?* H0 X7 jwebapp busybox </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.197</span> [INFO ] [main] [org.apache.coyote.http11.Http11NioProtocol] Initializing ProtocolHandler [<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">http-nio-4567</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">]# J, e. U' i% ]4 o# M4 F, Q
webapp busybox </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.200</span><span style="color: rgba(0, 0, 0, 1)"> [INFO ] [main] [org.apache.catalina.core.StandardService] Starting service [Tomcat]
* q$ E+ y  j* H4 q  f  t  b; pwebapp 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)">]% x# `5 @6 a5 s1 M
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
( i% }" B( O5 v. I) Nwebapp 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# X2 v6 H: g* m" X3 R  \
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)">4 J2 M' D0 F6 k; D$ S% {
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)
/ O7 @* W& c. g4 M3 n2 ?3 \$ _4 ]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)">]  C3 r. B2 d( l6 N) A5 x( 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.481</span> [INFO ] [main] [org.springframework.boot.web.embedded.tomcat.TomcatWebServer] Tomcat started on port(s): <span style="color: rgba(128, 0, 128, 1)">4567</span> (http) with context path <span style="color: rgba(128, 0, 0, 1)">''</span><span style="color: rgba(0, 0, 0, 1)">
6 P' X+ X) ^- k( bwebapp 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 m" W$ }4 G9 r  J; h. Qwebapp webapp
+ j8 k  L' R* U7 s2 Z: v2 o& ~webapp webapp   .   ____          _            __ _ _
1 v4 \9 x0 V1 u* Z& l% Jwebapp webapp  </span>/\\ / ___<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">_ __ _ _(_)_ __  __ _ \ \ \ \</span>) g  V" @2 e2 l* z7 ?! z
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>( \  J1 J& U/ q
webapp webapp  \\/  ___)| |_)| | | | | || (_| |<span style="color: rgba(0, 0, 0, 1)">  ) ) ) )
0 ]. v* w# ]: [% f& t. B0 Ywebapp webapp   </span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">  |____| .__|_| |_|_| |_\__, | / / / /</span>
  y# ?: k' I% H6 o; B7 x6 wwebapp webapp  =========|_|==============|___/=/_/_/_/<span style="color: rgba(0, 0, 0, 1)">
/ }  A! k" @7 @# @* X5 Q! C6 kwebapp webapp  :: Spring Boot ::                (v2.</span><span style="color: rgba(128, 0, 128, 1)">4.2</span><span style="color: rgba(0, 0, 0, 1)">)
! C* V$ x5 O% }webapp webapp
1 t6 ^. }* Y  ?) }& M7 @+ 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.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)& B, [" J# M# T& D$ |% 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)">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+ E8 K3 e1 g, ]9 j; n6 {. 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.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)
% d  I+ |. }# g6 a) L, w/ X1 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.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)">]
! a* i' ~# A- j$ j2 A0 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.200</span><span style="color: rgba(0, 0, 0, 1)"> [INFO ] [main] [org.apache.catalina.core.StandardService] Starting service [Tomcat]
# C# g4 ?9 y0 z- f$ \, F7 O$ bwebapp 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)">]3 ^" ?2 T7 T' z0 ], W  y2 s* v7 p
webapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.324</span> [INFO ] [main] [org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/<span style="color: rgba(0, 0, 0, 1)">]] Initializing Spring embedded WebApplicationContext
# g; J8 O$ t/ \8 Q, o. ywebapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">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 G' x+ q. N' T( u3 B& 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)">53.801</span> [INFO ] [main] [org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor] Initializing ExecutorService <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">applicationTaskExecutor</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">9 J; ]* ?7 W9 X; _2 ]* `5 H( t
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)
* L8 T* h4 r, }& ], Y* i  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)">]
/ c  S6 ~; n/ p& J% O! 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)">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)">
. R- A7 }' l1 R% T" 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.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>. i" D+ K; e: Y
</div>
$ D, f/ }. S: m' Q( _3 o& l<p>&nbsp;</p>
5 k- e! W+ v! L. c' f9 ^
回复

使用道具 举报

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

本版积分规则

手机版|飞雪团队

GMT+8, 2025-11-21 12:31 , Processed in 0.069692 second(s), 21 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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