first: pod is the smallest unit of the k8s(pod是k8s最小资源单位)
pod can include servral containers the init container which provide the netwoprk environment for the other pod,it means the containers in the pod the network is interlinked(pod 内部有一个基础容器,提供类似docker bridge的功能实现pod内container之间的相互通信)
pod yaml file is as below:
apiVersion: v1
kind: Pod
metadata:
name: nginx
namespace: lf
label: myblog
sepc:
volumes:
- name: myblog-data
hostpath:
path: /opt/myblog-data
NodeSelector:
component: myblog
containers:
- name: myblog
image: 10.0.0.21:5000/myblog #image pull ip and port image nam
imagePullPolicy: IfNotPresent
volumeMounts:
- mountPath: /test-ebs #mount the dir to the defined hostpath
name: myblog-data #the defined volume
args: ["sleep 1000"]
env: #the environment of the pod
CACHE_SIZE: 500Mi
livenessProbe:
httpGet:
path: /index.html
port: 8002
scheme: HTTP
health check
livenessProbe:
httpGet:
path: /index.html
port: 8002
scheme: HTTP
command :
kubectl apply deployment.yaml
#get the deployment 获取deployment资源
kubectl get deployments -n namespacename
kubectl rollout status deployment/nginx-deployment
kubectl get pods --show-labels
#update teh image version
kubectl --record deployments.app/nginx-deployment set image deployments.app/nginx-deployment nginx=nginx:1.16.1
kubectl rollout history deployment.v1.apps/nginx-deployment
#rollback to revision 2 回退到版本2
kubectl rollout history deployment.v1.apps/nginx-deployment --revision=2
kubectl scale deployment.v1.apps/nginx-deployment --replicas=10
question1: how to manage these the pod?(如何管理pod )
we have the deployment resource controller which can manage the pod by the label.(deployment 一般是管理控制无状态的如app 等)
the deployment yaml file is as below:
deployment is executed on the replicaset so we can set the replicas(deployment 运行在replicaset之上,可以设置副本数,匹配通过matchLabels label)
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80