飞雪团队

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

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

[复制链接]

9321

主题

9409

帖子

3万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
30293
发表于 2022-2-12 14:35:42 | 显示全部楼层 |阅读模式

8 r1 i" Y5 Z0 T4 A+ m<p>kubectl作为我们主要的操作K8S的工具,其具备非常丰富的功能,但是如果不经过打磨,使用起来还是存在诸多不便,今天我们来看看如何将我们的kubectl打磨的更加易用。</p>9 s" |% N1 _* {1 L! X6 i
<p>&nbsp;</p>( X6 l/ L  u: i& q4 j. J; @& l
<p>一、命令自动补全</p>
6 N1 n% K+ n! {4 q& ?<p>kubectl中提供非常多的命令,如果每一次都要手动一个字符一个字符的敲未免太累了,那么如何配置自动补全呢?这里以ubuntu系统为例:</p>
& Z5 ~* r+ D$ g<p>1、安装auto-completion工具</p>; @1 M- B. j- w% J. ]" \3 K
<div class="cnblogs_code">' f" W5 B+ C/ r$ n! z6 V
<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> apt update
1 u4 M4 e$ C9 u8 E% HHit:</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>
2 W% v, s2 B! L$ yHit:<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>+ U; @- p4 A# V# n3 b" p! R
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>9 n+ k, x5 b2 q% @
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>* g: i- K) j/ Y3 P
Hit:<span style="color: rgba(128, 0, 128, 1)">5</span> http:<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">archive.ubuntu.com/ubuntu bionic-backports InRelease</span>
$ @5 K5 c/ c* r3 ?<span style="color: rgba(0, 0, 0, 1)">Reading package lists... Done
! h; e; R1 T2 V8 K3 }& zBuilding dependency tree
2 j7 a- V& ?) d5 J  M/ QReading state information... Done: Y. q+ U0 }  ?% b9 [
</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.
7 Q6 H  p8 z9 l% x0 L9 B1 K$ </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# _' p) Y" @; a+ T* f; Z9 ?1 ^# y
Reading package lists... Done: _  `8 t! L( Z' b. C$ O5 |9 D9 g
Building dependency tree8 q) |9 G" R- g  L
Reading state information... Done
& i3 U$ o/ o( [' N  ~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).8 |$ v5 l# l4 W, t
</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>
) c9 i0 g0 _; y7 H( Z# V</div>( q) r4 P, c3 r4 T& f7 x: {% _
<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># ?, z4 a! k  O' E5 I$ R7 K
<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>
! O0 L6 P6 o3 O2 ]0 p( o<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>
  e# x: a- x# r' }$ h2 o* a<div class="cnblogs_code">, p" s! G! \) o9 M
<pre>source &lt;<span style="color: rgba(0, 0, 0, 1)">(kubectl completion bash)# y( V! s) c0 t/ W
</span><span style="color: rgba(0, 0, 255, 1)">echo</span> <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">source &lt;(kubectl completion bash)</span><span style="color: rgba(128, 0, 0, 1)">"</span> &gt;&gt; ~/.bashrc</pre>" |7 h; Y: K6 H% O% w
</div>+ ~% w) p9 @5 ~% d% X
<p><strong>Zsh</strong>:</p>, w+ `; V4 K, {
<div class="cnblogs_code">
2 S- l4 b  }: i' o. J4 C' `<pre>source &lt;<span style="color: rgba(0, 0, 0, 1)">(kubectl completion zsh)
- T" ^  c6 ?  z! \" P7 f& g</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>
' W2 ~( w* s, t3 i7 Q3 [) x</div>; p6 Y/ M! t7 r) M
<p>配置后就可以通过Tab键自动补全命令啦!</p>
  a) z$ p6 n9 p/ M& h<p>&nbsp;</p>; U4 r' E: O0 V+ w
<p>二、配置kubectl别名</p>
7 K0 T3 F: n; b) c* P' s, Z) @5 o  W# K<p>我们可以通过设置别名简化kubectl命令,编辑.bashrc文件,添加如下内容:</p>- Y2 ?! Z1 u+ B* p; |, T) Y
<div class="cnblogs_code">6 }! d2 G6 V! r  _1 D$ u
<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)">4 e# H% b* W& o5 P. f* v
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)">: z5 U, q+ g" h/ _: o
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)">9 l+ H$ C: J. W
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)">" A/ o  d3 n4 C
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)">) u2 ^0 _/ B( s. p
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)">* L2 D' X/ g3 j, H3 m( \4 n
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 ?+ B$ h  M( A- l' Q5 P% \/ i</div>
; y' B. z9 p4 I" H3 }<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>/ I) S7 ]- I4 p
<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>
# w3 F. w4 `* P3 x  y9 V<div class="cnblogs_code">
1 o4 m- A* R& ?2 y, z1 L0 n8 E; `<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> ka webapp_pod.yaml8 ^* b& g2 G5 Y0 p' Q  p& k8 c
pod</span>/<span style="color: rgba(0, 0, 0, 1)">webapp created; A  d! D  p2 _, E9 Z
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> kg pods
: n' k; `+ x" }) w8 c) T7 E4 `NAME     READY   STATUS              RESTARTS   AGE
8 t4 `5 j+ t( J) \' b; v( d% \1 ?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
# j9 n8 ~) ?0 v$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> kd pod webapp
' e4 ?& h! d8 K5 A+ B- RName:         webapp
! |. C9 P# e" K/ d% t9 Q7 MNamespace:    default
$ Y9 [1 S+ T5 L" n+ L3 FPriority:     </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">
3 z0 E) e! B' l4 w5 ^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)">4 H' M% Q% |5 t$ N
Start Time:   Wed, </span><span style="color: rgba(128, 0, 128, 1)">09</span> Feb <span style="color: rgba(128, 0, 128, 1)">2022</span> <span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">44</span> +<span style="color: rgba(128, 0, 128, 1)">0000</span><span style="color: rgba(0, 0, 0, 1)">
5 ]- `0 T( {- B" O+ u! j% TLabels:       app</span>=<span style="color: rgba(0, 0, 0, 1)">webapp- _; T& M+ P& R
Annotations:  </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
" D" c$ [% [% G" i" L+ KStatus:       Running
6 {% l. K- O% u4 _, `: nIP:           </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 g2 m' p4 S9 wIPs:
1 a  F  j' G! N# X7 ?  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)">! a8 _/ S1 z$ [/ J  P7 f/ @
Containers:
- M' j! u1 ^7 {1 ^( ^  webapp:' u" D) B- T! l2 N
    Container ID:   docker:</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">d9ddf9dd47de12b53f2119bf75df6706bee2e7711509638ad52adc9addeda704</span>
1 G, K9 z$ L  E5 v( V    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)">
7 ~( e! @% |% T# g7 O* }! Z    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>
. F7 l+ }% u# D    Port:           <span style="color: rgba(128, 0, 128, 1)">5000</span>/<span style="color: rgba(0, 0, 0, 1)">TCP
( z4 m3 S( D1 [; O6 I    Host Port:      </span><span style="color: rgba(128, 0, 128, 1)">0</span>/<span style="color: rgba(0, 0, 0, 1)">TCP
8 I; G! K: M5 }/ d! l: U    State:          Running5 ^9 L9 e- m3 H# X% V2 h
      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)">
$ V' r7 g9 x9 I7 A* i( Z' Z' {    Ready:          True
/ }9 b1 N6 [5 `8 k( ^' Z+ I2 ?    Restart Count:  </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">3 y+ m9 K5 D+ t. X9 g3 B$ v
    Environment:    </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">" n9 t0 ~% f! U8 E4 b+ {- V
    Mounts:
" n2 v4 G! c$ q# T2 K1 G4 `      </span>/tmp from webapp-<span style="color: rgba(0, 0, 0, 1)">logs (rw). W( U: s/ x! K; l
      </span>/var/run/secrets/kubernetes.io/serviceaccount from default-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h (ro)3 v6 r/ ^9 T2 D+ ]. n
  busybox:! U! a6 r6 |# n' X7 H
    Container ID:  docker:</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">6a6a35a628a782fc643af3dd49986bbc77c23de1ae4726bc521c77f61abbbf5d</span>  G  }1 K5 c$ J
<span style="color: rgba(0, 0, 0, 1)">    Image:         busybox/ Q" {0 j3 f; ~, }5 e6 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>, @$ O, f* a; Z; w' @
    Port:          &lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">. k, a* F: x1 Y) ^
    Host Port:     </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">$ e, O$ N! i; O- u. d
    Command:! c, G4 P: c2 |5 a
      </span><span style="color: rgba(0, 0, 255, 1)">sh</span>
1 w; e+ l  Y, ^0 x      -<span style="color: rgba(0, 0, 0, 1)">c7 y0 r3 h! }" q2 ^) O% {
      </span><span style="color: rgba(0, 0, 255, 1)">tail</span> -f /logs/<span style="color: rgba(0, 0, 0, 1)">log.out% K# u8 ]+ h( M& a/ ^& R
    State:          Running7 [4 X* b+ Z7 c- Q( U
      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)">
+ b4 r% q2 O; R- j    Ready:          True
+ H& c8 R8 p( f6 W    Restart Count:  </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">
+ b! D0 i  Y0 T$ b+ D+ I/ A) g    Environment:    </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">. q2 o7 m# |: o+ Q# s: g3 G" K" y
    Mounts:
3 R: l+ i/ i; t5 u8 u! W      </span>/logs from webapp-<span style="color: rgba(0, 0, 0, 1)">logs (rw)
( Z/ o! |8 X2 R0 j0 o4 q  \# ~      </span>/var/run/secrets/kubernetes.io/serviceaccount from default-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h (ro)4 a- Z8 B$ A" ?/ I' P
Conditions:
' C* s5 n4 ~' f: n* u  Type              Status
6 P" V: ~  Q* A4 u' z( d  Initialized       True
8 G, |/ A% B6 l5 p0 s/ w  Ready             True
) s% a5 w1 l$ w3 I8 O  ContainersReady   True5 d& l# [7 a  R4 f+ R) Q4 N- _, g
  PodScheduled      True
: O4 a( s  Q( }+ L1 t; X, lVolumes:+ N) u8 Y! ^' t
  webapp</span>-<span style="color: rgba(0, 0, 0, 1)">logs:5 N1 {; `# [9 l7 S1 B
    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>) x7 T3 e% e4 b: W5 Q' M( d: k
<span style="color: rgba(0, 0, 0, 1)">    Medium:9 `" {1 k! r, R
    SizeLimit:  </span>&lt;unset&gt;<span style="color: rgba(0, 0, 0, 1)">) V) [5 s! T! d- }2 Y( w% D/ y
  default</span>-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h:
! U7 j/ M5 D2 t    Type:        Secret (a volume populated by a Secret)
1 Q, d* ^& m5 N% ~    SecretName:  default</span>-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h2 s7 A5 q: q! p. I' w0 Q
    Optional:    </span><span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)">4 g+ ~$ V( o  c/ J- m* q
QoS Class:       BestEffort% D4 q! g7 A& B1 w2 Z6 V
Node</span>-Selectors:  &lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">% V' F& l- ~- j0 t
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; ~. ^5 E+ a: \
                 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( D! y& c) ]7 d3 `0 d% J
Events:: o: s; K/ P2 o
  Type    Reason     Age    From               Message: Q5 n4 @6 t" H; }1 m
  </span>----    ------     ----   ----               -------<span style="color: rgba(0, 0, 0, 1)">
3 k8 Q+ u( P$ u9 m/ B' m7 \+ Q  Normal  Scheduled  2m23s  default</span>-scheduler  Successfully assigned default/<span style="color: rgba(0, 0, 0, 1)">webapp to ayato
( C+ O4 N/ a& u/ B  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 machine7 L, u* r' Y+ e: c! n5 ]0 I
  Normal  Created    2m21s  kubelet            Created container webapp; y, `* Q" j7 e9 T
  Normal  Started    2m21s  kubelet            Started container webapp& \1 `5 L6 S; _6 W7 e
  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)">2 M3 n& V$ O) `: F/ T- J; |8 t7 i9 d
  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% n4 M* f6 l' m( L( o  Normal  Created    15s    kubelet            Created container busybox( J( N' z5 S1 r" v4 W( J
  Normal  Started    14s    kubelet            Started container busybox</span></pre>: C7 g% u: D) j3 m9 O' Y
</div>
. h- ~' c4 e& |, N1 b<p>真的是飞一般的感觉!!!</p>
' y4 L" @! M* m( w: p# ]<p>&nbsp;</p>
' N% Q( j2 N& ]6 X8 O<p>三、Context和Namespace切换</p>7 c4 E! ]: @, M. j3 J8 q
<p>我们在公司的容器平台上使用kubectl时,经常需要切换context和namespace,导致命令非常繁琐,那有没有简便的方式呢?—— kubectx</p>- M; H, f+ B7 r  f/ B) z4 h" Z
<p>kubectx安装</p>
! |  H; U2 l: B. F* T: P<div class="cnblogs_code">1 B9 e  q4 g* L* {! ~  M9 n
<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>
+ ^  {5 Q$ @3 {- E5 ]$ ^7 i/ H" 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)">...: W% Q$ |7 x% W: C
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)">.0 U4 |8 i7 u. f' x: @- r7 _
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)">.
  C0 j% K: `/ y- y; nremote: 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)">.* @: x, C. l5 l; q8 ]
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)">
3 a& l+ l6 @* y) b( h; lReceiving 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)">.
( e1 ~3 W. U6 @# {+ ?6 c, H# 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)">.
: t! y  h4 J7 v, Q! 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
) R$ K3 |7 G3 _, t  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>+ |, h7 c- _# b+ i8 b  |5 M
</div># h4 U, G- @7 i. L* o2 F1 N
<p>我们来看一下效果:</p>+ ~: V+ j4 ]/ P- [  F! \9 y; o& D! Q
<div class="cnblogs_code">" Q, {7 ]& G3 V
<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ctx
! x! {, c* f9 {6 sminikube
# R1 M, O) \; h2 I, T4 O! l$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ctx minikube
; `; `, e; i# \0 w4 xSwitched 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$ w0 h! S( g$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ns' X/ ]! L3 [8 [: n) q
default
: v* T4 [) X3 R- B; pkube</span>-node-<span style="color: rgba(0, 0, 0, 1)">lease7 Q7 y- w1 d2 h7 V. @9 W
kube</span>-<span style="color: rgba(0, 0, 0, 1)">public! @( I4 I( v2 t4 q( B
kube</span>-<span style="color: rgba(0, 0, 0, 1)">system( a/ Z0 X" k( x2 y8 G# \% x: w- h
kubernetes</span>-<span style="color: rgba(0, 0, 0, 1)">dashboard) \# a3 s0 c1 _; z
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span> k ns kube-<span style="color: rgba(0, 0, 0, 1)">public/ p# w5 B4 T: |
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 s4 B( s& _0 M, A5 d0 yActive 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)">.4 Q! q, q9 W6 D
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ns default
, d% K: q! t5 U# W; Q# RContext </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.
5 Q) Z  v& c0 l& n% Y6 O  dActive 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>
! f$ v! J5 v5 s. A0 w! m</div>
! c* B) u7 ^' A3 y- z1 P<p>&nbsp;</p>
, l2 k7 t: f/ W  ]/ l<p>四、跟踪查看多个Pod的日志</p>* C+ c: z  s$ O" R% W  G2 t
<p>我们一般使用kubectl logs命令查看Pod日志,但是它不能通过-f参数同时跟踪查看多个Pod日志,这就不方便了,毕竟实际生产环境中每个服务都会有多个Pod,这时我们可以使用stern这个工具,它具备如下能力:</p>) O- V/ I/ |$ v" K/ C& h- e
<ul class="list-paddingleft-2">
% }/ ?& g1 q- |3 S0 n7 ]<li>9 ]! T% c5 q: Q: x3 \
<p>允许使用正则表达式来选择需要查看的PodName</p>: e. t; v4 U4 Y  N5 }  n
</li>$ Z- Q3 P% x! S; r- d! p  a
<li>
3 z+ R& U7 L& U<p>为不同 Pod 的日志展示不同的颜色</p>$ l1 q- u7 X' L* f  g
</li>4 g4 F5 ?  s4 @* h9 @
<li>
/ i/ \8 T$ l; e! i<p>跟踪日志过程中假如有符合规则的新 Pod 被创建, 那么会自动添加到输出中</p>1 u+ _/ N1 G4 ?
</li>
1 F3 ?5 u# t4 [4 R. j' l9 G</ul>+ D; k6 P5 K9 F, E' \) A$ K; [
<p>首先安装stern(下载stern时可能较慢可以多试几次):</p>
! v/ x8 s& q8 M/ ~8 O<div class="cnblogs_code">
. w+ K) T; @- x7 b9 o3 U<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>1 I# M5 [$ a7 E; T* e+ @
<span style="color: rgba(0, 0, 255, 1)">sudo</span> <span style="color: rgba(0, 0, 255, 1)">mv</span> stern_linux_amd64 /usr/local/bin/kubectl-<span style="color: rgba(0, 0, 255, 1)">tail</span>
- Q0 L. r% H$ t5 Y, k. l6 q<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>$ ]0 q" h, ~0 F
</div># b8 s/ Q, K) Q# a
<p>安装完毕后让我一起感受一下stern的魅力吧,我的Pod里面有两个容器:webapp和busybox,如果使用kubectl logs 还得指定具体的容器,而使用stern就没有这样的限制。</p>
6 ~) p1 k0 o. h9 k+ f<div class="cnblogs_code">
, Z; ?7 O3 L6 B( G# D<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)"> .. v4 w0 o9 x: E- j& u) p" @) W% |
</span>+<span style="color: rgba(0, 0, 0, 1)"> webapp › busybox- v0 u* I6 y0 t, r/ U: i1 v
</span>+<span style="color: rgba(0, 0, 0, 1)"> webapp › webapp
% K* M, P+ Y8 X" v) \, swebapp 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)">]$ E/ _: k. h8 P; B1 ?
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]4 Q0 B7 x) C5 _) o* l2 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)">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)">]
6 u8 V. z  ?$ J6 w* ewebapp 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
6 E5 \; D# V, u1 _  r8 C4 |" _$ }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)"> ms$ g. |) p5 I# ?
webapp busybox </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.801</span> [INFO ] [main] [org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor] Initializing ExecutorService <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">applicationTaskExecutor</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">+ c/ L7 }1 B) P, G. f( 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.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)/ s: x8 y* n' }
webapp busybox </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">54.377</span> [INFO ] [main] [org.apache.coyote.http11.Http11NioProtocol] Starting ProtocolHandler [<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">http-nio-4567</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">]
3 A2 M' Z1 ]8 ]) K( t+ [$ `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)">
4 ?: B2 G  m  G% r; 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)">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 N/ K( @$ Z, `9 h6 V- X. Z8 Swebapp webapp2 B' n/ g4 b; P" D" b  z4 ]% Q5 a
webapp webapp   .   ____          _            __ _ _& D# K- t" g' s' O& b% g5 ]
webapp webapp  </span>/\\ / ___<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">_ __ _ _(_)_ __  __ _ \ \ \ \</span>. Y! a3 Y2 o9 B6 |  E
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>1 Q1 P" ]1 ]( }) x6 y4 b/ M3 Z% n
webapp webapp  \\/  ___)| |_)| | | | | || (_| |<span style="color: rgba(0, 0, 0, 1)">  ) ) ) )
0 @! w- F) h/ m2 ~webapp webapp   </span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">  |____| .__|_| |_|_| |_\__, | / / / /</span>
, q+ P! h* K) O; {- n* G* Vwebapp webapp  =========|_|==============|___/=/_/_/_/<span style="color: rgba(0, 0, 0, 1)">
* t6 ~" P/ p$ W- J  l6 R# O" Mwebapp webapp  :: Spring Boot ::                (v2.</span><span style="color: rgba(128, 0, 128, 1)">4.2</span><span style="color: rgba(0, 0, 0, 1)">)1 z' G, V! U7 I. N4 t. u
webapp webapp
* t! \9 ^: i! Mwebapp 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)
& F+ _1 Y$ P4 j  p6 Xwebapp 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
- {9 u2 i, ~* g6 r; z+ l# M" k3 N3 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)
4 |$ g1 s3 H1 u# ^9 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.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)">]( i( i, ~! J+ V8 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.200</span><span style="color: rgba(0, 0, 0, 1)"> [INFO ] [main] [org.apache.catalina.core.StandardService] Starting service [Tomcat]% V$ ]& i( J. E4 s$ u( 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.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  i) d7 d  y6 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.324</span> [INFO ] [main] [org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/<span style="color: rgba(0, 0, 0, 1)">]] Initializing Spring embedded WebApplicationContext- z) y& O( G+ c. N3 C
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)"> ms
! m" A9 d1 v" o  @9 K8 G/ F6 @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)">3 a$ m* @. d/ N0 G: b
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)1 v1 T; P/ p2 t" 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)">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# p7 N# awebapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">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)">2 d0 [' l+ p3 C* S
webapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">54.509</span> [INFO ] [main] [org.demo.webapp.todolist.TodoListApplication] Started TodoListApplication <span style="color: rgba(0, 0, 255, 1)">in</span> <span style="color: rgba(128, 0, 128, 1)">6.235</span> seconds (JVM running <span style="color: rgba(0, 0, 255, 1)">for</span> <span style="color: rgba(128, 0, 128, 1)">8.074</span>)</pre>
* H: S3 Y) M% |& n</div>! X1 p- \6 _+ C+ L* A: f
<p>&nbsp;</p>
! Z5 ^1 u) d  c4 v- v- [5 c
回复

使用道具 举报

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

本版积分规则

手机版|飞雪团队

GMT+8, 2026-11-4 15:51 , Processed in 0.067430 second(s), 21 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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