kubernetes pod, deployment

本文介绍了Kubernetes中Pod作为最小资源单位的角色,以及它如何通过内部网络实现容器间的通信。展示了Pod的YAML配置文件,包括挂载卷、初始化容器、存活探针等。此外,还详细阐述了如何使用Deployment进行Pod的管理,如设置副本数、更新镜像版本、回滚和扩缩容操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值