【精选】Kubernetes in Action 前4章读书笔记

62 阅读2分钟

文章目录

笔记

0 资源类型 Node, Pod, Container, ReplicationController, ReplicaSet, DaemonSet, Job, CronJob
1 构件镜像 docker build -t kubia . 使用当前文件夹中的Dockerfile
2 使用镜像但不创建容器,docker run busybox echo “Hello World”
3 打标签 docker tag [local image] [username/image]
4 登录docker login,输入用户名、密码
5 上传到registry,docker push [带用户名标签的镜像名]
6 解决 minikube start 过程中拉取镜像慢的问题
先执行 minikube delete
再执行 minikube start --image-mirror-country=‘cn’
7 将用户添加到某个组
arvin@ubuntu:~$ sudo groupadd docker #添加docker用户组
groupadd: group ‘docker’ already exists
arvin@ubuntu:~$ sudo gpasswd -a KaTeX parse error: Expected 'EOF', got '#' at position 13: USER docker #̲将登陆用户加入到docker用… newgrp docker #更新用户组
8 安装docker docs.docker.com/engine/inst…
9 自动补全 source <(kubectl completion bash)
10 暴露pod, kubectl expose pod kubia --type=LoadBalancer --name kubia-http
11 描述 kubectl describe po kubia
12 创建资源 by json ymal文件 kubectl create -f
13 查看参数 kubectl explain
14 查看日志 kubectl logs [pod -c contain]
15 如何访问到容器:端口转发。kubectl port-forward kubia-manual 8888:8080
16 netstat -antp可以查看监听的IP:端口
17 docker run --rm 参数–rm表示退出时自动移除容器
18 查看标签 kubectl get po --show-labels
19 添加标签 kubectl label po kubia-manual creation_method=manual
20 修改标签 kubectl label po kubia-manual-v2 env=debug --overwrite
21 过滤标签 kubectl get po -l creation_method=manual
22 添加注解 kubectl annotate pod kubia-manual mycompany.com/someannotation=“foo bar”
23 创建namespace kubectl create namespace custom-namespace
24 创建容器时指明命名空间 kubectl create -f kubia-manual.yaml -n custom-namespace
25 查询时也一样,附带上 -n [namespace]
26 删除资源 kubectl delete po kubia-gpu
27 删除当前命令空间下的所有资源 kubectl delete all --all
28 查看容器的运行日志 kubectl logs mypod --previous
29 探针的类型 http-get, tcp connect, exec
30 修改副本控制器 kubectl edit rc kubia
31 水平缩放副本 kubectl scale rc kubia --replicas=10,该操作的触发修改rc配置文件。或者直接修改rc配置文件中的spec.replicas参数
32 删除副本控制器但保留容器 kubectl delete rc kubia --cascade=orphan
33 ReplicaSet取缔了ReplicaController。
34 给节点打标签 kubectl label node minikube disk=ssd

小节

  • 第1章 介绍Kubernetes,对比Virtual Machine
  • 第2章 了解如何使用Docker构建镜像,安装Kubernetes相关程序
  • 第3章 Pods: 在Kubernetes中运行容器
  • 第4章 讲如手动扩容和调度Pods,提到了ReplicationControllers, ReplicaSets, DaemonSets, BatchJob, CronJob