飞雪团队

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

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

[复制链接]

4137

主题

4225

帖子

1万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
14711
发表于 2022-2-12 14:35:42 | 显示全部楼层 |阅读模式
4 L/ U4 X7 m$ T  [( b' ]
<p>kubectl作为我们主要的操作K8S的工具,其具备非常丰富的功能,但是如果不经过打磨,使用起来还是存在诸多不便,今天我们来看看如何将我们的kubectl打磨的更加易用。</p>: ^& E6 K( ~$ B2 o0 J
<p>&nbsp;</p>
. Z, x! K0 B* P5 z5 m3 e3 z<p>一、命令自动补全</p>
8 }) Z' Z+ t2 q2 t<p>kubectl中提供非常多的命令,如果每一次都要手动一个字符一个字符的敲未免太累了,那么如何配置自动补全呢?这里以ubuntu系统为例:</p>2 R$ x& I$ T+ [. c4 |+ E
<p>1、安装auto-completion工具</p>. ?4 h$ l# V/ I9 S& t* S7 ~: _
<div class="cnblogs_code">
' g% s6 m, v6 ~<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> apt update- W4 ]# W7 D% @3 _6 o
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>
' f7 Q# o, _2 Q7 _% J$ B$ PHit:<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>
4 d+ U3 s9 R' }6 A$ S% o& n: k, vHit:<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>
2 A; C. r' i, }, U9 m2 WHit:<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>
% G5 C) ]5 e$ N' bHit:<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>4 }+ v, j, `/ R( Y. ?3 p
<span style="color: rgba(0, 0, 0, 1)">Reading package lists... Done
# Z# f& ?5 V+ w. s5 hBuilding dependency tree$ N1 S( q5 C: q& g" {" W6 w2 N0 }
Reading state information... Done4 ~5 {! N6 E6 X9 A$ ]. [# y0 ^
</span><span style="color: rgba(128, 0, 128, 1)">144</span> packages can be upgraded. Run <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">apt list --upgradable</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)"> to see them.9 ?: E/ r- h  G/ [  _
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span> apt <span style="color: rgba(0, 0, 255, 1)">install</span> bash-<span style="color: rgba(0, 0, 0, 1)">completion( ^3 [1 I: i5 g5 C6 `
Reading package lists... Done7 e2 o0 D8 B* u- z" o. C
Building dependency tree4 r. S% D. @( G( O4 i  W
Reading state information... Done7 Z5 A5 d/ {' C
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).! h( b* b& D& T0 x
</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>
. w& r: O- o( \2 I2 N' r</div>% k1 p0 z( v$ P5 ]9 O3 w; E
<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>$ U$ W0 X: |# U( |5 ~2 j1 F, e
<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>
5 h9 s3 i7 l: i, `; ]- O6 q- 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>1 j/ V( ?; ]3 j1 H1 F! X1 Q9 S
<div class="cnblogs_code">  o. F& \2 ?1 k4 d/ \- |2 w
<pre>source &lt;<span style="color: rgba(0, 0, 0, 1)">(kubectl completion bash)
6 N8 G- U/ q" e" L</span><span style="color: rgba(0, 0, 255, 1)">echo</span> <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">source &lt;(kubectl completion bash)</span><span style="color: rgba(128, 0, 0, 1)">"</span> &gt;&gt; ~/.bashrc</pre>( U( B; ?: m+ S
</div>
7 m9 I/ e: I/ Y3 w$ `<p><strong>Zsh</strong>:</p>0 z) o; H9 ^  d8 d3 H5 k( T
<div class="cnblogs_code">( m+ g/ Y& d2 U3 @2 b: `! S
<pre>source &lt;<span style="color: rgba(0, 0, 0, 1)">(kubectl completion zsh)
' I3 f1 \; x2 f2 |: {0 i0 L</span><span style="color: rgba(0, 0, 255, 1)">echo</span> <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">[[ $commands[kubectl] ]] &amp;&amp; source &lt;(kubectl completion zsh)</span><span style="color: rgba(128, 0, 0, 1)">"</span> &gt;&gt; ~/.zshrc</pre>1 p& _" t7 o5 o8 R9 j
</div>
9 f. E) y( \. Y$ h1 [<p>配置后就可以通过Tab键自动补全命令啦!</p>
/ n: T2 [$ _$ T, a% B  x<p>&nbsp;</p>7 ?3 }# R( ?! ^0 Y! ]0 z
<p>二、配置kubectl别名</p>+ s* Y, ?, U8 C* P9 E* B
<p>我们可以通过设置别名简化kubectl命令,编辑.bashrc文件,添加如下内容:</p>5 {- p% a7 i! A* x
<div class="cnblogs_code">
( p: z& i' W1 G- b) {) v<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)">; h) k8 E$ n( ?1 J5 R- T1 U8 M
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)">
  X9 g  {% E+ A) J7 Y+ d+ ?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)">
! |) X& N1 Y) g$ v3 \, Palias 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)">
# q4 h6 e, w, d# K6 W5 ~& `, O$ Talias 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)">$ |/ [/ c3 w- F4 \0 u
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 x" C  \% x. ]1 a1 d, r
alias kd</span>=<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">kubectl describe</span><span style="color: rgba(128, 0, 0, 1)">'</span></pre>5 T0 M  X% u, o' E1 L8 T7 d" [
</div>
( g; ]. K. u% @9 k<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>
% [' H* Z' q, m2 s# X- X/ 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>
2 {( G( w& z+ Z- w& W7 t. H$ M<div class="cnblogs_code">
" r" U, t6 F3 a, _4 B<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> ka webapp_pod.yaml$ X. d7 n( z% P% ]
pod</span>/<span style="color: rgba(0, 0, 0, 1)">webapp created
( L" }$ M% B0 S9 Y6 ]$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> kg pods& e9 c& `6 w* e1 T: Q9 i& U
NAME     READY   STATUS              RESTARTS   AGE# b8 ]  F' |; ~2 f
webapp   </span><span style="color: rgba(128, 0, 128, 1)">0</span>/<span style="color: rgba(128, 0, 128, 1)">2</span>     ContainerCreating   <span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">          7s
  i, \* p, O( Q$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> kd pod webapp4 r( e! k5 W9 z5 J9 ~: I* _
Name:         webapp
7 j4 A6 w: ], i5 g9 w) p7 hNamespace:    default- J% W3 h$ d& W2 w' Z* q' r* C5 G
Priority:     </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">, y6 h+ Q7 H* n
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)">
$ t* @$ R2 M' u7 t2 tStart 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)">! s$ I$ \: g7 I1 k2 U. A4 ^
Labels:       app</span>=<span style="color: rgba(0, 0, 0, 1)">webapp
" _8 j3 w- m$ l5 G& Y  ~" LAnnotations:  </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">6 {# b: H( X3 w# e' M) @5 M
Status:       Running. e4 G, N5 i' d9 a( Y
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)">
6 _+ W5 z- ^" g% A8 dIPs:
9 r5 c/ y4 l9 b& b) b) \6 X, B  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)">0 R9 |- u5 \3 ?" N6 N$ a7 T0 y
Containers:# C, G! y" A% m* B% `4 P
  webapp:) j( Q  w& {3 F+ q0 i" K% A' @# W3 S; |
    Container ID:   docker:</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">d9ddf9dd47de12b53f2119bf75df6706bee2e7711509638ad52adc9addeda704</span>
  X9 v* D5 |$ T5 y: |2 m    Image:          <span style="color: rgba(128, 0, 128, 1)">172.16</span>.<span style="color: rgba(128, 0, 128, 1)">194.135</span>:<span style="color: rgba(128, 0, 128, 1)">5000</span>/webapp:<span style="color: rgba(128, 0, 128, 1)">1.0</span><span style="color: rgba(0, 0, 0, 1)">
' j! `% F4 T1 B2 x    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>0 _8 ?9 U4 W$ Q1 E: a
    Port:           <span style="color: rgba(128, 0, 128, 1)">5000</span>/<span style="color: rgba(0, 0, 0, 1)">TCP& `- l6 o. u1 A
    Host Port:      </span><span style="color: rgba(128, 0, 128, 1)">0</span>/<span style="color: rgba(0, 0, 0, 1)">TCP
* ~, H0 y2 q- `9 L. e% E    State:          Running
' }! D( \  q) O/ x1 G4 k6 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)">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)">, A+ V  O4 |- m2 A4 S/ M
    Ready:          True4 E3 i0 G6 y$ t. B4 X( J4 e
    Restart Count:  </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">
; j/ J# y2 b7 ^! w% v    Environment:    </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
  ~! d5 X5 r% b6 `  ]) ]7 y    Mounts:2 K+ n9 T- X$ ]3 B
      </span>/tmp from webapp-<span style="color: rgba(0, 0, 0, 1)">logs (rw)' J4 ^. I6 `2 E9 l; c; j, g! a
      </span>/var/run/secrets/kubernetes.io/serviceaccount from default-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h (ro)' G( V) C; J( K$ E/ f" d: y
  busybox:
8 B1 h% d' l, Z% l$ U6 a    Container ID:  docker:</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">6a6a35a628a782fc643af3dd49986bbc77c23de1ae4726bc521c77f61abbbf5d</span>( [5 B1 Z( c8 x# Q
<span style="color: rgba(0, 0, 0, 1)">    Image:         busybox
1 v' M5 _: v0 F( C1 o# h. ~    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>
: K$ D  [4 X8 [$ l, l& ?3 a+ M2 g    Port:          &lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">" w% D- G& D- h( _
    Host Port:     </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
' P7 Y$ R+ \. J    Command:
6 Q% D: C8 t' u( a$ ^& v% g- E" ^      </span><span style="color: rgba(0, 0, 255, 1)">sh</span>7 g/ Y5 W2 M. }: O3 T
      -<span style="color: rgba(0, 0, 0, 1)">c
& d7 d: j9 C0 \$ D      </span><span style="color: rgba(0, 0, 255, 1)">tail</span> -f /logs/<span style="color: rgba(0, 0, 0, 1)">log.out! ]; ~% p: |: c) o
    State:          Running& l+ p9 j" M6 a$ M/ S
      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 l& p% w8 G+ b# p: f$ g" ]: x    Ready:          True
7 Y' }1 o0 J& U" d' P2 E- ~    Restart Count:  </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">! X9 B# f% V( N1 ?; e/ x% d
    Environment:    </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
5 @! G9 S% M* l    Mounts:
! W. m% ]4 y' h) p* ?4 i1 t      </span>/logs from webapp-<span style="color: rgba(0, 0, 0, 1)">logs (rw)
" v% D5 H% d, q$ Z9 }      </span>/var/run/secrets/kubernetes.io/serviceaccount from default-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h (ro)
! K; D$ q( n( JConditions:
+ E  U4 s( ~6 w! A  Type              Status/ W/ T: L& f3 i) s$ b, p
  Initialized       True
  h: G' E7 A( C2 e; c  Ready             True
/ R9 n, G% F1 Q  ~  ContainersReady   True
& M( [+ a4 N; C  PodScheduled      True4 d+ c6 \0 Z  C7 o
Volumes:0 Q. p6 \4 e6 ~5 x# X
  webapp</span>-<span style="color: rgba(0, 0, 0, 1)">logs:
+ P$ B5 ~# Y; {    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>
8 D8 c- V. K- [! I) d3 I+ r2 P<span style="color: rgba(0, 0, 0, 1)">    Medium:. ]/ e! b* P" W- w* K- V
    SizeLimit:  </span>&lt;unset&gt;<span style="color: rgba(0, 0, 0, 1)">
$ ~' d  @  e# h5 O* v  default</span>-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h:
5 A+ e: X8 z5 o# r    Type:        Secret (a volume populated by a Secret); S6 n1 E# F4 K. R
    SecretName:  default</span>-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h( d) ^0 c5 v1 `) V4 f  x; h
    Optional:    </span><span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)">4 n: ?6 w. W1 K7 P: m
QoS Class:       BestEffort
, V/ a7 X4 s  z/ d7 m9 d/ KNode</span>-Selectors:  &lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
  w, L) Z3 `, g4 _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
  G$ }' d- V, \1 p' s, x# O; Z                 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
6 X% n- G8 l5 z' ~+ jEvents:
4 R+ D1 B5 k4 G- e' @  Type    Reason     Age    From               Message
' c* q* m* R, U3 r  </span>----    ------     ----   ----               -------<span style="color: rgba(0, 0, 0, 1)">
, l, {5 a* z' e; A  Normal  Scheduled  2m23s  default</span>-scheduler  Successfully assigned default/<span style="color: rgba(0, 0, 0, 1)">webapp to ayato
  z' t, P' c+ }6 t$ ]: T  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; i, _+ N9 I' R0 g, j$ W
  Normal  Created    2m21s  kubelet            Created container webapp8 U& O, X; B5 @7 i
  Normal  Started    2m21s  kubelet            Started container webapp  H, n- a7 s# i9 s$ O- N0 P( C8 j
  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 A" q! I: e, i% u7 b
  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)">.633078305s8 h% M. O! t' N" l% e
  Normal  Created    15s    kubelet            Created container busybox) f- N; u+ g# E& e- v/ E
  Normal  Started    14s    kubelet            Started container busybox</span></pre>
' y+ Y- c; k1 Q</div>7 \+ S5 x. ~# e9 k; |- L$ x/ H0 a
<p>真的是飞一般的感觉!!!</p>
' {0 }& O$ a5 U! z/ {<p>&nbsp;</p>( P7 T- s3 ^4 E' Z
<p>三、Context和Namespace切换</p>+ V5 E1 k/ ?% o* m9 S
<p>我们在公司的容器平台上使用kubectl时,经常需要切换context和namespace,导致命令非常繁琐,那有没有简便的方式呢?—— kubectx</p>/ M, G1 S# }- V2 c+ R, N, B& [3 q
<p>kubectx安装</p>% s1 m/ k% _( C& a$ F; S, ~
<div class="cnblogs_code">! c; }- B& x" k6 y' s* v
<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span> git clone https:<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">github.com/ahmetb/kubectx /opt/kubectx</span>
8 v7 D$ A+ z) b) E9 z1 Q' L4 r7 RCloning 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)">...
9 D) l0 i8 l$ g  H( B0 }* e5 Rremote: 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)">.
( j6 m9 M  W$ p, K' e* j" yremote: 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)">.# Y' @& E$ }* t7 w; a% j& N9 p( I5 S
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)">./ `4 [' a, |: s
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)">& m5 Y+ a& Y( ]
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)">./ N: T$ a% u% Y0 t0 r( B
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)">.* `& r/ i; a* Y) T6 p
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span> <span style="color: rgba(0, 0, 255, 1)">ln</span> -s /opt/kubectx/kubens /usr/local/bin/kubectl-<span style="color: rgba(0, 0, 0, 1)">ns
9 J2 s- h4 L/ u$ </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>
2 t+ Q5 [; J' h- |9 f: t+ N; D! q</div>
0 h+ w6 N, X) d4 d- Z1 C( Q7 f<p>我们来看一下效果:</p>& o6 o( G  M4 Z7 L/ A
<div class="cnblogs_code">
% h; e0 B! N! O9 E<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ctx
1 F  U! S% V  I. v# Zminikube8 J' ?4 O) s4 K( {0 U
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ctx minikube
- c) u" I5 `3 U* n" F' bSwitched 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)">.
; R* Y6 ?6 a: [# r- D& f1 x$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ns6 R! z. i8 P9 k7 v( \1 M
default
- s5 W- P2 k# b% n' [3 L4 [& n5 \kube</span>-node-<span style="color: rgba(0, 0, 0, 1)">lease
& E6 @" u+ w/ J4 I, Xkube</span>-<span style="color: rgba(0, 0, 0, 1)">public
6 o/ }' Y) v8 L/ O& s$ pkube</span>-<span style="color: rgba(0, 0, 0, 1)">system
+ J4 p+ ~" m: l6 z7 z  }5 mkubernetes</span>-<span style="color: rgba(0, 0, 0, 1)">dashboard
0 T* I" Y+ v- J- r, q& w7 |$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span> k ns kube-<span style="color: rgba(0, 0, 0, 1)">public
- L- i) N4 Y$ D) W: Y7 MContext </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.
7 }6 o% u0 i! _- j. s. |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)">.
/ ?* W+ d' E( {' O8 l; E5 l$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ns default
, p$ Z: A) 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.
2 S" W6 o9 K0 _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 ?' b1 w& k/ O0 B5 O
</div>* n7 i+ e2 ?% \' y9 A
<p>&nbsp;</p>& S% X' s) Q% F8 n" s- l: e
<p>四、跟踪查看多个Pod的日志</p>1 E) v% X- p9 s  e  c' I* M
<p>我们一般使用kubectl logs命令查看Pod日志,但是它不能通过-f参数同时跟踪查看多个Pod日志,这就不方便了,毕竟实际生产环境中每个服务都会有多个Pod,这时我们可以使用stern这个工具,它具备如下能力:</p>2 Z- r  M, k+ E; l
<ul class="list-paddingleft-2">& d6 j7 s' l& @
<li>7 ~& x) g# n0 _& l. M) l
<p>允许使用正则表达式来选择需要查看的PodName</p>
; ?, m6 s  |7 u( T: F</li>
, r, W% ~% }+ t( R" ~: G7 [0 r8 g<li>
! ]6 [% {5 D+ S* A6 h8 ^<p>为不同 Pod 的日志展示不同的颜色</p>
  ]( u0 u7 k) }# X</li>
$ z- |3 G9 U' I2 I# U<li>
% O& M% L$ Q- R  W- l<p>跟踪日志过程中假如有符合规则的新 Pod 被创建, 那么会自动添加到输出中</p>% B! F1 H- n! k% I4 E6 w& ^
</li>
! |  [/ c' q- `( }2 Z</ul>1 R  K. E6 B- ]- M
<p>首先安装stern(下载stern时可能较慢可以多试几次):</p>
! w/ N* _6 T; \7 }/ O* A<div class="cnblogs_code">
8 C" l8 P! {- l2 _1 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>
' f1 d1 N( A0 v; e* S<span style="color: rgba(0, 0, 255, 1)">sudo</span> <span style="color: rgba(0, 0, 255, 1)">mv</span> stern_linux_amd64 /usr/local/bin/kubectl-<span style="color: rgba(0, 0, 255, 1)">tail</span>4 f3 j# X% Y4 D! 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>2 g- `2 {: V4 j! U! r. g" v" v
</div>* R/ U' Y8 Y7 T' m* ~* a$ E* y
<p>安装完毕后让我一起感受一下stern的魅力吧,我的Pod里面有两个容器:webapp和busybox,如果使用kubectl logs 还得指定具体的容器,而使用stern就没有这样的限制。</p>
. C5 C$ f6 f- Z$ q# h<div class="cnblogs_code">
; p, K$ I- J% U: L<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)"> .* y  C! U6 `' K- [. |3 ]. P" a
</span>+<span style="color: rgba(0, 0, 0, 1)"> webapp › busybox; T$ t! z3 T4 C0 i
</span>+<span style="color: rgba(0, 0, 0, 1)"> webapp › webapp4 t# ^: A, O! G# f6 Y+ @) c
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 k" C  b: b0 ?& C0 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.200</span><span style="color: rgba(0, 0, 0, 1)"> [INFO ] [main] [org.apache.catalina.core.StandardService] Starting service [Tomcat]5 F+ E2 G9 f: {. l7 W- a* 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.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)">]# w1 z! R, V; t6 N
webapp busybox </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.324</span> [INFO ] [main] [org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/<span style="color: rgba(0, 0, 0, 1)">]] Initializing Spring embedded WebApplicationContext1 Y# v8 H4 [6 K5 Q9 U, W' c
webapp busybox </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.325</span> [INFO ] [main] [org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext] Root WebApplicationContext: initialization completed <span style="color: rgba(0, 0, 255, 1)">in</span> <span style="color: rgba(128, 0, 128, 1)">2952</span><span style="color: rgba(0, 0, 0, 1)"> ms0 T# f$ k" [( `. W% N
webapp busybox </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">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 |9 o: }1 o5 y
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)
( o# q3 I6 d8 l) K5 F( ^8 ~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)">]; ~$ T. M; K# U) O& 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)">
0 P1 _( g7 B0 ^% t5 Uwebapp 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)">)
5 I3 ]. i, ?  T( Pwebapp webapp
& r! o4 ^: J% ^+ N4 k1 Cwebapp webapp   .   ____          _            __ _ _' u: C# {0 w. l: S
webapp webapp  </span>/\\ / ___<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">_ __ _ _(_)_ __  __ _ \ \ \ \</span>
' M/ y' r- v5 l: Swebapp 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>! H1 G2 u' U8 l1 X3 p6 p
webapp webapp  \\/  ___)| |_)| | | | | || (_| |<span style="color: rgba(0, 0, 0, 1)">  ) ) ) )" o) O  f2 k/ F# U  s5 C
webapp webapp   </span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">  |____| .__|_| |_|_| |_\__, | / / / /</span>4 i9 o0 h0 n& Q* R: {0 ?
webapp webapp  =========|_|==============|___/=/_/_/_/<span style="color: rgba(0, 0, 0, 1)">
- A  e4 T. a- |+ C$ C. m9 P# Awebapp webapp  :: Spring Boot ::                (v2.</span><span style="color: rgba(128, 0, 128, 1)">4.2</span><span style="color: rgba(0, 0, 0, 1)">)4 G$ [( C0 v7 W3 x8 O/ B
webapp webapp+ v( G: N8 d9 l( f) s) x  k1 ~7 U
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)' m; |' v# h$ j) A0 S6 x' 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.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
% J9 m  U- [8 F$ ^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)
* `. n( Y1 n7 P5 |' N8 r" 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.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)">]9 C1 Y! F$ c5 s$ e# m$ s5 L- 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]6 |: W  g+ \& V+ e6 U3 X* 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)">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)">]
- Z6 X4 d: o  U! Ewebapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.324</span> [INFO ] [main] [org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/<span style="color: rgba(0, 0, 0, 1)">]] Initializing Spring embedded WebApplicationContext# u, S* O9 v* _9 q' \0 j/ 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.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)"> ms1 t0 j3 P' f% q# ~2 @1 ^) R
webapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.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)">
7 ?6 a; H1 w% lwebapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">54.264</span> [WARN ] [main] [org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration$DefaultTemplateResolverConfiguration] Cannot <span style="color: rgba(0, 0, 255, 1)">find</span> template location: classpath:/templates/<span style="color: rgba(0, 0, 0, 1)"> (please add some templates or check your Thymeleaf configuration)* U+ {  C+ t% h. ]* 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.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)">]# N3 v/ n- |* V; I, z% {# f
webapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">54.481</span> [INFO ] [main] [org.springframework.boot.web.embedded.tomcat.TomcatWebServer] Tomcat started on port(s): <span style="color: rgba(128, 0, 128, 1)">4567</span> (http) with context path <span style="color: rgba(128, 0, 0, 1)">''</span><span style="color: rgba(0, 0, 0, 1)">: a' i$ Y- J& u  |  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)">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># o: U% V7 x5 H( I; j" [! f
</div>
2 T2 j6 {, n4 T4 a8 V  O5 B  ]9 s<p>&nbsp;</p>: C( f: w( a+ R' ]; n  H
回复

使用道具 举报

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

本版积分规则

手机版|飞雪团队

GMT+8, 2024-4-20 07:30 , Processed in 0.069983 second(s), 21 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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