由于不能将多个进程聚集在一个单独的容器里,pod应运而生
但是一般pod上还是只跑一个应用除非这些应用
需要一起运行,代表一个整体,一起进行扩缩容
pod共享网络和命名空间,文件系统每个容器是隔离的
yaml文件格式
cat secret_pod.yml
apiVersion: v1
kind: Pod
metadata:
name: mypod
spec:
containers:
- name: mypod
image: redis
volumeMounts:
- name: foo
mountPath: "/etc/foo"
readOnly: true
volumes:
- name: foo
secret:
secretName: mysecret
metadata: 包括名称、命名空间、标签和关于该容器的其他信息
spec:包含pod内容的实际说明,例如pod的容器、卷和其他数据
label 可以使用标签调度pod到对应的节点
验证一下一个pod下不能占用同一个端口
apiVersion: v1
kind: Pod
metadata:
name: test-pod
labels:
name: test-pod
spec:
containers:
- name: test-pod1
image: nginx
ports:
- containerPort: 80
- name: test-pod2
image: nginx
ports:
- containerPort: 80
[root@master ~]# kubectl get pod
NAME READY STATUS RESTARTS AGE
busybox1 4/4 Running 0 29d
my-nginx-75897978cd-p6p79 1/1 Running 0 39m
my-nginx-75897978cd-z67ch 1/1 Running 0 39m
mypod 1/1 Running 0 36d
test-pod 1/2 CrashLoopBackOff 2 73s
验证一下pod共享存储
**cat pod-volume-applogs.yaml**
apiVersion: v1
kind: Pod
metadata:
name: volume-pod
spec:
containers:
- name: tomcat
image: tomcat
ports:
- containerPort: 8080
volumeMounts:
- name: app-logs
mountPath: /usr/local/tomcat/logs
- name: logreader
image: busybox
command: ['sh','-c','tail -f /logs/catalina*.log']
volumeMounts:
- name: app-logs
mountPath: /logs
volumes:
- name: app-logs
emptyDir: {}
tomcat把日志写到app-logs里面,busybox读日志
能在busybox里面看到tomcat的启动日志