Kubernetes-pod
目录
说明
Pod: k8s最小管理单元,一个pod中可以运行多个容器container
通过POD yaml和 kubectl run 命令运行POD有没有高可用
- 修改默认的namespace
kubectl config set-context --current --namespace=project1
- 创建一个POD
kubectl run --image=nginx --image-pull-policy=IfNotPresent --port=80 web-nginx
-----------------
#:镜像下载策略:
1. Always
2. IfNotPresent
3. Never
- 查看POD日志
kubectl logs web-nginx -n project1
- 查看POD详细信息
kubectl describe pods web-nginx -n project1
- POD运行3个容器
说明
当pod中有多个主容器时,所有主容器都运行正常,POD才正常
trnuser@k8s:~/pod$ cat 3in1-pod.yaml
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
run: 3in1
name: 3in1
spec:
containers:
- image: nginx
imagePullPolicy: IfNotPresent
name: web-test
ports:
- containerPort: 80
resources: {}
- image: busybox
imagePullPolicy: IfNotPresent
name: busybox-1
command: ["sh","-c","sleep 1000"]
resources: {}
- image: centos
imagePullPolicy: IfNotPresent
name: centos1
resources: {}
dnsPolicy: ClusterFirst
restartPolicy: Never
status: {}
- 初始化容器
说明
在一个pod中可以包含多个初始容器, 主容器必须等所有初始容器正常运行并完成时,才会运行主容器。
trnuser@k8s:~/pod/pod$ cat pod-init.yml
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
run: pod8-init
name: pod8-init
spec:
containers:
- image: nginx
name: pod8
imagePullPolicy: IfNotPresent
resources: {}
env:
- name: MYSQL_PASSWORD
value: 'redhat'
initContainers:
- image: busybox
name: busybox-1
imagePullPolicy: IfNotPresent
command: ["sh", "-c","sleep 20"]
securityContext:
privileged: true
dnsPolicy: ClusterFirst
restartPolicy: Never
status: {}
- POD访问
kubectl exet -it web-3in1 -- /bin/bash #默认进入主容器 POD中第一个容器为主容器
进入POD中不同容器,用-c 指定
kubectl exec -it web-nginx-4 -c c2 -- sh
- 通过yaml文件创建POD
kubectl run --image=nginx --image-pull-policy=IfNotPresent --port=80 --dry-run=client web-nginx-3 -o yaml > pod1.yaml
- yaml文件中指定Node标签
trnuser@k8s:~/pod/pod$ cat pod1.yaml
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
run: pod1
name: pod1
spec:
nodeSelector:
storage: ssd ## 指定标签为ssd的NODE节点
containers:
- image: nginx
name: pod1
resources: {}
dnsPolicy: ClusterFirst
restartPolicy: Always
status: {}
- 静态POD
* etcd
* api-server
* controller-manager
* scheduler
* kube-proxy
说明
本地kubelet管理,kubelet服务会动态加载/etc/kubernetes/manifests/下的POD
trnuser@k8s:~/pod/pod$ sudo ls /etc/kubernetes/manifests/
etcd.yaml kube-apiserver.yaml kube-controller-manager.yaml kube-scheduler.yaml
trnuser@k8s:~/pod/pod$

浙公网安备 33010602011771号