Pod
pod 可以有多个 副本,比如 slave 实际上是 pod 的副本,单一的 pod 存在唯一的 node 上。
- IP 分配的单位, pod 容器共享
- pod 容器共享 volume, pod所有容器可以共享多个 docker 容器的 fs 下的 volume
- 同一个pod 容器可以共享 IPC UTS namespace
- pod 拥有属性 labels,key 独一无二,1当成是 map
pod 信息有:
- Shared storage, as Volumes
- Networking, as a unique cluster IP address
- Information about how to run each container, such as the container image version or specific ports to use
我们之前说过, pod 类似逻辑主机, 在逻辑主机中运行的进程共享诸如 CPU 、 RAM、 网络接口等资源。 入们会期望进程也能共享磁盘, 但事实并非如此。 需要谨 记 一 点, pod 中的每个容器都有自己独立的文件系统, 因为文件系统来自容器镜像。
pods
apiVersion: v1
kind: Pod # P 要大写
metadata:
name: mwish-bot
spec:
containers:
- image: redis
name: mredis
ports:
- containerPort: 6379
protocol: TCP
然后在这里可以:
kubectl create -f p.yaml
第一次 check 的时候:
➜ k8s kubectl get pods
NAME READY STATUS RESTARTS AGE
mwish-bot 0/1 ContainerCreating 0 55s
等镜像被拉下来就是 running 了。
➜ k8s kubectl get pods
NAME READY STATUS RESTARTS AGE
mwish-bot 1/1 Running 0 6m2s
(这个时候 docker ps 竟然没有,不科学?)
然后可以看 log:
mwish-bot 1/1 Running 0 6m2s
➜ k8s kubectl logs mwish-bot
1:C 08 Feb 2020 19:17:28.146 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1:C 08 Feb 2020 19:17:28.146 # Redis version=5.0.7, bits=64, commit=00000000, modified=0, pid=1, just started
1:C 08 Feb 2020 19:17:28.146 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
1:M 08 Feb 2020 19:17:28.153 * Running mode=standalone, port=6379.
1:M 08 Feb 2020 19:17:28.153 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
1:M 08 Feb 2020 19:17:28.154 # Serv