飞雪团队

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

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

[复制链接]

9292

主题

9380

帖子

3万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
30206
发表于 2022-2-12 14:35:42 | 显示全部楼层 |阅读模式
/ r3 J2 E# s& p. T: [
<p>kubectl作为我们主要的操作K8S的工具,其具备非常丰富的功能,但是如果不经过打磨,使用起来还是存在诸多不便,今天我们来看看如何将我们的kubectl打磨的更加易用。</p>
" m9 I" a8 Y; }  p5 w<p>&nbsp;</p>
. X4 x! {5 j9 U3 p9 h<p>一、命令自动补全</p>
8 ^) u" ]: h0 T* S$ E; {: O& d2 f4 t<p>kubectl中提供非常多的命令,如果每一次都要手动一个字符一个字符的敲未免太累了,那么如何配置自动补全呢?这里以ubuntu系统为例:</p>8 ^) k; n: p/ J& {; g0 ^# s
<p>1、安装auto-completion工具</p>7 w! U' ]% V! W( H$ ^1 ^: V
<div class="cnblogs_code">
* x  E5 f) u# W7 G2 Q<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> apt update$ l7 P  o+ j3 q6 N- V  M5 C4 a
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>! v: z$ q- h5 O! ]0 n& j
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>8 _# n6 \2 N9 F, {. _- {
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>- o0 V$ V0 g" E$ N
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>
/ x0 G$ k& M( e; J$ S2 J# N$ yHit:<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>* o' ]4 g: Z3 P0 t
<span style="color: rgba(0, 0, 0, 1)">Reading package lists... Done- {" B8 z! K! |" q5 I
Building dependency tree
# @% M( X; p- `) t# A7 l/ ^( ZReading state information... Done
  e2 F. G! M  h6 x" X* _: K</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.1 }; h$ t/ `8 f- y  R7 F. N8 ^
$ </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
' W  F% T1 Y! N0 J* |9 hReading package lists... Done
: r1 E) m7 |9 N' G; q3 T" H& d5 UBuilding dependency tree- J1 b& B7 X* w
Reading state information... Done
( e/ z* [2 ^& v! H/ Rbash</span>-completion is already the newest version (<span style="color: rgba(128, 0, 128, 1)">1</span>:<span style="color: rgba(128, 0, 128, 1)">2.8</span>-<span style="color: rgba(0, 0, 0, 1)">1ubuntu1).
* @% B; P3 ], p3 {</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>
$ T! y% g* W( V</div>6 C3 X; F5 b' ]! m3 o' T
<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>
6 a6 r& M7 N3 r, L" `/ m<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>6 z6 b( n: A- S9 O# }: V6 g
<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>" ~: t4 @& q4 ~( m3 w1 Z- e" U' O
<div class="cnblogs_code">, P) |9 p8 G) \3 b5 S) k
<pre>source &lt;<span style="color: rgba(0, 0, 0, 1)">(kubectl completion bash), l7 W% Q4 S1 d
</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>
( K# [7 l% Z$ b7 ?$ S7 X</div>
. d! o2 [) b5 h  k* m! z<p><strong>Zsh</strong>:</p>
# Y$ h4 y  u" {8 e. ]' A5 m2 [<div class="cnblogs_code">
0 o* Q3 x5 s1 Z2 _! K<pre>source &lt;<span style="color: rgba(0, 0, 0, 1)">(kubectl completion zsh)
. H3 X- R( ^5 ?) y</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>
2 u3 _* V3 g( i) F$ P  r/ Q</div>
8 D8 z/ S+ l! ~5 P0 `! ]; x$ c<p>配置后就可以通过Tab键自动补全命令啦!</p>( _7 F4 g8 j7 ?2 C+ A
<p>&nbsp;</p>
7 R- e4 A0 J0 {% Y<p>二、配置kubectl别名</p>
+ W5 W+ _: `" r0 ~2 m$ [$ q" O  O<p>我们可以通过设置别名简化kubectl命令,编辑.bashrc文件,添加如下内容:</p>% y! K. Q* Q# R* Y
<div class="cnblogs_code">7 {, ^1 A6 P) 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)">
1 r3 {. L- W% S5 r* Oalias 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)">, s. [5 t# A% F; b' u7 c
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)">
3 v8 x$ e4 ~, c" F* Valias 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)">, |! s$ r) b, P( a
alias klo</span>=<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">kubectl logs -f</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">
5 t+ F, F% X) B- W" i; T8 k; |; Ialias 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)">6 v& G% ]  G. F# {0 y# Z# n" K
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>
4 T7 t" q7 C1 Z</div>
7 a( V) q' a7 p* @9 H0 c# T<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>  q' ^  z3 M3 y2 B
<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>
5 k2 X1 d' T/ g1 T1 M; L" n! u" G<div class="cnblogs_code">
- V: {, c) o4 j/ `1 t<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> ka webapp_pod.yaml
. Z. D1 j! g; }8 D& z7 I& i( K. bpod</span>/<span style="color: rgba(0, 0, 0, 1)">webapp created
2 W5 s  b7 W" x" Q" m/ I$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> kg pods! D4 f$ J* f9 Q; o1 ?
NAME     READY   STATUS              RESTARTS   AGE
6 q* z) e6 j  {% Gwebapp   </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
/ f+ T, h2 x$ O7 D: q$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> kd pod webapp. w; o( k1 F4 Y
Name:         webapp
1 @0 G% j; A7 cNamespace:    default
6 ]9 j% J& l3 x% A( g, A, xPriority:     </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">
9 W$ F: l6 A' RNode:         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)">
& O6 \( {- b# J  @4 m, jStart 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)">3 J, Q7 C  p8 k" k
Labels:       app</span>=<span style="color: rgba(0, 0, 0, 1)">webapp
& F% f$ S' W7 L6 |Annotations:  </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">* _& Q0 @! X7 N7 Q' Q" |; x: H
Status:       Running: G" x' e0 L; P* }" }; s5 g. r
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)">8 ^' s/ a6 ~+ s* N
IPs:$ s5 m+ e% B. m
  IP:  </span><span style="color: rgba(128, 0, 128, 1)">172.17</span>.<span style="color: rgba(128, 0, 128, 1)">0.6</span><span style="color: rgba(0, 0, 0, 1)">
" j7 L+ ]2 z/ x3 o1 @) c; KContainers:$ b, P! c1 ?1 F- E
  webapp:
* _6 f/ j# J6 F    Container ID:   docker:</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">d9ddf9dd47de12b53f2119bf75df6706bee2e7711509638ad52adc9addeda704</span>
2 j# T; b8 ?4 J    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)">
* z2 L* ?; E2 l; g+ \    Image ID:       docker</span>-pullable:<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">172.16.194.135:5000/webapp@sha256:df3a447a013ada0642dec67bb31976f42f1a0699a68873d0452f514fa24e5c77</span>8 I' N* p/ t4 f0 b; h
    Port:           <span style="color: rgba(128, 0, 128, 1)">5000</span>/<span style="color: rgba(0, 0, 0, 1)">TCP4 ~. Q- M. I0 m8 v6 c% y% \
    Host Port:      </span><span style="color: rgba(128, 0, 128, 1)">0</span>/<span style="color: rgba(0, 0, 0, 1)">TCP
. T" f5 ~! s0 M3 |: q/ M6 j7 `3 B/ c    State:          Running
9 s9 h  B. F. ~; J* C      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)">
! o0 f( R8 ]5 \    Ready:          True- v! j5 q8 b2 i6 ^1 [! _& u2 ?* X
    Restart Count:  </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">
  Z0 }2 W& J1 I) O9 F: m    Environment:    </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
$ d9 i, a3 Y9 z0 M# Q    Mounts:# n( i- y9 m( w* ?$ e
      </span>/tmp from webapp-<span style="color: rgba(0, 0, 0, 1)">logs (rw)" E8 v1 q+ _; P3 }# N2 m
      </span>/var/run/secrets/kubernetes.io/serviceaccount from default-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h (ro)
8 _" c3 |$ k+ }9 J  busybox:
) G; _7 G# [. B2 r$ ~$ n+ z    Container ID:  docker:</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">6a6a35a628a782fc643af3dd49986bbc77c23de1ae4726bc521c77f61abbbf5d</span>
1 e* T" R  ]# X, q1 L/ h<span style="color: rgba(0, 0, 0, 1)">    Image:         busybox5 d. g& S. R( J# N5 A
    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># {, h! {' r, P. x$ [0 K
    Port:          &lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">. S, p- A. Q0 O9 Y& f: O
    Host Port:     </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">3 C/ i0 B4 D9 h) }$ Z8 X" `
    Command:
: J: l6 R, C$ w  X# }% a7 w& k      </span><span style="color: rgba(0, 0, 255, 1)">sh</span># q# I8 T9 s5 K8 ^- x
      -<span style="color: rgba(0, 0, 0, 1)">c$ ?* u  M* J# \" x0 j+ _, I; m( a" [, B
      </span><span style="color: rgba(0, 0, 255, 1)">tail</span> -f /logs/<span style="color: rgba(0, 0, 0, 1)">log.out. ~8 v0 {+ X7 h/ ?$ m4 J- R9 K
    State:          Running: |* D, W2 G3 r+ O
      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)">8 E  q3 \  P/ x- u: y; F. P+ L
    Ready:          True: l$ s1 b0 t) w1 S
    Restart Count:  </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">' }8 e# ^5 M' @2 ?* [7 m7 o
    Environment:    </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
! W  Z, q/ f$ V" Y    Mounts:- W$ M" y9 J5 i* C9 _
      </span>/logs from webapp-<span style="color: rgba(0, 0, 0, 1)">logs (rw)
: F8 V( D- A; W      </span>/var/run/secrets/kubernetes.io/serviceaccount from default-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h (ro)
# W8 z9 e. ~0 iConditions:: n" R, S' n! J" b5 P# s, u
  Type              Status* k- J3 m- R! A8 U% X
  Initialized       True
9 a1 Z9 t/ S. j  Ready             True
5 H8 Q1 c6 Q+ ?- }, h/ W  ContainersReady   True' j0 d7 ?5 l8 j
  PodScheduled      True
6 a! @, R6 n7 E- BVolumes:
, M0 u% w. |; K2 Z  webapp</span>-<span style="color: rgba(0, 0, 0, 1)">logs:
+ ~- X& q4 Z, k: y9 k    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>" D9 m% ?5 p8 e3 Y$ {! u8 Z
<span style="color: rgba(0, 0, 0, 1)">    Medium:( X0 q5 ~/ ]0 i& b# C- {$ g, o
    SizeLimit:  </span>&lt;unset&gt;<span style="color: rgba(0, 0, 0, 1)">
1 {6 E) X  J: n3 I  default</span>-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h:8 Z) H0 g, o8 }" `- f+ d# X
    Type:        Secret (a volume populated by a Secret)
6 T0 r4 x4 e$ S/ x4 O6 N$ N2 i1 V    SecretName:  default</span>-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h
5 i7 h( j0 _( H/ B4 ]$ _& J    Optional:    </span><span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)">
- p9 ^: w6 o7 X# zQoS Class:       BestEffort
7 l8 G2 L  G0 ?# {Node</span>-Selectors:  &lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
( g) V/ e8 w1 tTolerations:     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
% V' ?* ]+ c: X                 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
% G7 j  K7 _: h) y% K6 h% j1 W# ZEvents:; l9 m; P; Z/ P+ d- Y. `1 [/ }
  Type    Reason     Age    From               Message# W9 v: O, _( ]- Y8 K9 [
  </span>----    ------     ----   ----               -------<span style="color: rgba(0, 0, 0, 1)">0 N+ S- I* y, y9 G1 u8 z
  Normal  Scheduled  2m23s  default</span>-scheduler  Successfully assigned default/<span style="color: rgba(0, 0, 0, 1)">webapp to ayato7 o/ \& N, f% }" [
  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
5 }7 ]3 J6 f: {( {1 \4 c+ C  Normal  Created    2m21s  kubelet            Created container webapp) q0 ~3 F* H* u
  Normal  Started    2m21s  kubelet            Started container webapp
6 N) \% w$ S6 O, d' @  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)">9 H8 Q1 _8 c/ L* j# ~
  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" O% f. \" T! O* b& ]' ^6 ~& H
  Normal  Created    15s    kubelet            Created container busybox
% r( |; ], h  K$ U! I0 P+ C; f2 z  Normal  Started    14s    kubelet            Started container busybox</span></pre>0 `4 K, z8 X8 M7 t+ W
</div>% z4 u+ l6 q: R0 t* W7 M
<p>真的是飞一般的感觉!!!</p>
- A& d. z# G/ E* B' g<p>&nbsp;</p>
9 P* k& O9 e* [# L, J<p>三、Context和Namespace切换</p>, |( d' C, ]# f# T1 j' U/ g% G
<p>我们在公司的容器平台上使用kubectl时,经常需要切换context和namespace,导致命令非常繁琐,那有没有简便的方式呢?—— kubectx</p>
0 j* \+ Z! I+ f5 B: W. ~& r<p>kubectx安装</p>0 L9 z. s) l: m: b! I
<div class="cnblogs_code">/ e5 ^- p: u2 q6 M, ]; \
<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>
$ t3 y* j  r* E/ A, aCloning 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)">...
* u+ f( ^' D: d) {! kremote: 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 F! W) b! T# Aremote: 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)">.
0 C5 W( e& k( aremote: 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)">.: M% Z  A* |: L- d+ z$ _* U
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)">
% U$ P4 E+ X% N+ t! S2 @6 `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)">.7 v  C, X, N8 o! t
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)">.: K! C4 e; I2 y
$ </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
2 x0 C3 `4 o0 ^6 d- l% N7 W* z* t$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span> <span style="color: rgba(0, 0, 255, 1)">ln</span> -s /opt/kubectx/kubectx /usr/local/bin/kubectl-ctx</pre>5 Z& f0 e' U$ E- w/ M  t
</div>: t) M* z: p# a, e5 X! u. J
<p>我们来看一下效果:</p>
, y4 s6 u# j5 q2 p$ [* B1 U1 A<div class="cnblogs_code">' S) E% m  v# X" N$ j* E; F8 v8 r
<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ctx( `0 H- g6 F; t: A
minikube
% W6 l9 R( y' C9 o& j- F$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ctx minikube
# D- V+ H. o- }9 ^# t$ q4 [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)">.. n6 s, Z/ P6 r7 T- u
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ns  [/ J6 A9 T  B% b5 P; r
default
5 d6 e: C  Z. k9 Dkube</span>-node-<span style="color: rgba(0, 0, 0, 1)">lease& {- B+ Z" q9 `' f# k& S
kube</span>-<span style="color: rgba(0, 0, 0, 1)">public
2 N7 h9 f6 r2 u, K: p  [kube</span>-<span style="color: rgba(0, 0, 0, 1)">system
" d7 \! A  a5 e2 i% Z* k) z% [kubernetes</span>-<span style="color: rgba(0, 0, 0, 1)">dashboard
1 B( ?8 X9 p; a) L, Z2 i$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span> k ns kube-<span style="color: rgba(0, 0, 0, 1)">public4 E- L* W; k9 R* j$ U! n
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.3 M9 X6 b. B* a0 I$ t; L- `
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)">.
2 H  k8 r: z- T) I$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ns default2 `2 {$ n+ y! w( D* B; b1 m
Context </span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">minikube</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)"> modified.- F- w. C! E% ~0 ^& C0 d
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>
7 v3 h" Z1 O: p  O$ z& @* F: X</div>, O, a& U$ N$ l: K% q( @2 M
<p>&nbsp;</p>) x0 J: K0 l  W( J5 c5 S3 d2 L- q7 C
<p>四、跟踪查看多个Pod的日志</p>
2 X3 a/ }0 m7 h/ Q, t: A<p>我们一般使用kubectl logs命令查看Pod日志,但是它不能通过-f参数同时跟踪查看多个Pod日志,这就不方便了,毕竟实际生产环境中每个服务都会有多个Pod,这时我们可以使用stern这个工具,它具备如下能力:</p>
  V* {; z& _1 {$ l8 O2 e. T<ul class="list-paddingleft-2">; Y$ M1 M8 {, Y& a3 H
<li>
3 n' C  H+ J" w- g9 @2 j; U<p>允许使用正则表达式来选择需要查看的PodName</p>$ {! `/ |8 E, m
</li>
4 \; o. _9 x& d' {: I+ b<li>
7 h  k. ^" A: _$ X9 u<p>为不同 Pod 的日志展示不同的颜色</p>+ E9 h1 L2 N' R5 ]1 p- Q9 G5 ]7 |. n
</li>
1 j" ?' z0 Q. B/ n7 b! |' @<li>
0 @+ ^' w2 u7 ^/ B& g9 i. f! S<p>跟踪日志过程中假如有符合规则的新 Pod 被创建, 那么会自动添加到输出中</p>
/ r5 j1 M. b& @5 O7 Q</li>7 b- P# W. B. E8 C- R4 Z
</ul>2 B$ E3 H( o3 c) R7 j
<p>首先安装stern(下载stern时可能较慢可以多试几次):</p>
8 e1 \8 B$ ~. b<div class="cnblogs_code">
& h# ?& B0 c7 d% u8 |2 D<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>: Z" ?; Z" {+ n% t8 |; `
<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>
5 B3 a1 @. C! u2 F% V+ a% w8 c# r<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>* x5 ]: k* b7 ]* V- e5 w
</div>
* M: m& M8 y1 a5 b1 E" o; k- D<p>安装完毕后让我一起感受一下stern的魅力吧,我的Pod里面有两个容器:webapp和busybox,如果使用kubectl logs 还得指定具体的容器,而使用stern就没有这样的限制。</p>
+ a4 y+ o4 {6 g) o<div class="cnblogs_code">
# {" _' n3 v" O( d+ a0 Q  b<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)"> .
0 W: z# s* k! g- G2 O: A# V3 |3 a8 w</span>+<span style="color: rgba(0, 0, 0, 1)"> webapp › busybox
0 k% D. G9 x! X0 k5 M, ^3 k</span>+<span style="color: rgba(0, 0, 0, 1)"> webapp › webapp
' |3 G5 `& D& l5 `- ~4 fwebapp 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)">]
8 n1 E& @6 m3 H- 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.200</span><span style="color: rgba(0, 0, 0, 1)"> [INFO ] [main] [org.apache.catalina.core.StandardService] Starting service [Tomcat]
6 @/ B+ W% f9 q% A2 {+ O, K! y4 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.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)">]
# p# J) f4 A) Y+ Y! E$ ?0 j! \# a- v  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.324</span> [INFO ] [main] [org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/<span style="color: rgba(0, 0, 0, 1)">]] Initializing Spring embedded WebApplicationContext
1 |: j( }9 i( u- D; Cwebapp busybox </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.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)"> ms0 K* G5 J1 U9 C$ Y' Z2 l
webapp busybox </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">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)">
# A& U6 S/ X7 X. W, C( @0 \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)# X6 M/ P, s& u( 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)">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)">]6 l% `" b% i- X6 l
webapp busybox </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">54.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)">$ l7 k  h/ p8 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)">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)">)$ r; ]* v9 d1 a
webapp webapp+ ]+ I* G$ U5 [0 T$ C( d1 _4 [
webapp webapp   .   ____          _            __ _ _
4 j2 x) [- \9 g8 @" p+ k/ T6 Q) Nwebapp webapp  </span>/\\ / ___<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">_ __ _ _(_)_ __  __ _ \ \ \ \</span>7 R  N* N9 h% f' h
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>
  s+ }+ c% ]( Q6 t& nwebapp webapp  \\/  ___)| |_)| | | | | || (_| |<span style="color: rgba(0, 0, 0, 1)">  ) ) ) )+ e* E, z7 E2 a. j# i% V
webapp webapp   </span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">  |____| .__|_| |_|_| |_\__, | / / / /</span>
) C1 e, U* S+ H# ~. D/ w" fwebapp webapp  =========|_|==============|___/=/_/_/_/<span style="color: rgba(0, 0, 0, 1)">5 d) J+ H' }# C9 @+ f. i; k: X
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)">)2 o4 F3 B9 K3 B! G2 ~* [
webapp webapp1 g  c7 c; A" b+ M0 n
webapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">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)3 ]( X& c0 d. W' z$ ]( j
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
0 E4 o, v& F5 R' V9 g& z/ 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.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" v' @# u( }7 m
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)">]' ~1 V5 A. C6 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)">53.200</span><span style="color: rgba(0, 0, 0, 1)"> [INFO ] [main] [org.apache.catalina.core.StandardService] Starting service [Tomcat]
" f1 S3 q3 D. ?& Jwebapp 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)">]2 v" s* R; L5 N
webapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.324</span> [INFO ] [main] [org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/<span style="color: rgba(0, 0, 0, 1)">]] Initializing Spring embedded WebApplicationContext
5 A, L1 f0 }9 j7 Rwebapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.325</span> [INFO ] [main] [org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext] Root WebApplicationContext: initialization completed <span style="color: rgba(0, 0, 255, 1)">in</span> <span style="color: rgba(128, 0, 128, 1)">2952</span><span style="color: rgba(0, 0, 0, 1)"> ms
* g5 n* o$ W, H0 a  T/ twebapp 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)">1 j8 y- p- C3 j; w( K( B7 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)">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)
! Q6 t  ]. j# g8 j+ c1 w8 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)">]
( i" C6 e) G! r" c- d/ L( 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)">
! Z" s9 k; }7 ]) {% L7 [webapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">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>  ^. ]# G$ k) P+ E% v' i  [% a# T
</div>7 F3 S0 u9 [7 _: K1 w* }/ z
<p>&nbsp;</p>
$ K* @( V: R) I0 w
回复

使用道具 举报

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

本版积分规则

手机版|飞雪团队

GMT+8, 2026-10-17 14:25 , Processed in 0.069673 second(s), 21 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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