PodPreset

#podpreset属于名称级别的资源,用于给新建的pod设置一些默认值,常见的现象:新建的pod中的容器的时间没有和宿主机同步
#查看已经运行的sysc中的时间差8个小时
[root@master greenwich]# kubectl get pod -n greenwich 
NAME                     READY   STATUS    RESTARTS   AGE
myweb-7f4646c84d-c692d   1/1     Running   0          28m
sync                     1/1     Running   0          15h
[root@master greenwich]# kubectl exec pod/sync -n greenwich -- date
Wed Mar 10 01:45:21 GMT 2021
[root@master greenwich]# date
Wed Mar 10 09:45:36 CST 2021
#配置podpreset
[root@master greenwich]# cat podpreset.yaml 
apiVersion: settings.k8s.io/v1alpha1
kind: PodPreset
metadata:
  name: synctime
  namespace: greenwich
spec:
  env:
    - name: TZ
      value: Asia/Shanghai
  selector:
    matchLabels:
      app: nginx
  volumes:
  - name: host-time
    hostPath: 
      path: /etc/localtime
  volumeMounts:
  - name: host-time
    mountPath: /etc/localtime
[root@master greenwich]# kubectl apply -f podpreset.yaml 
podpreset.settings.k8s.io/synctime configured
[root@master greenwich]# kubectl get  podpreset -n greenwich -o wide
NAME       CREATED AT
synctime   2021-03-09T09:59:55Z
 # 新生成pod的时间
 [root@master greenwich]# kubectl delete pod  sync -n greenwich
pod "sync" deleted
[root@master greenwich]# kubectl get pod -n greenwich
NAME                     READY   STATUS    RESTARTS   AGE
myweb-7f4646c84d-c692d   1/1     Running   0          35m
[root@master greenwich]# kubectl run sync --image=nginx -n greenwich
pod/sync created
[root@master greenwich]# kubectl get pods -n greenwich
NAME                     READY   STATUS    RESTARTS   AGE
myweb-7f4646c84d-c692d   1/1     Running   0          36m
sync                     1/1     Running   0          53s
[root@master greenwich]# kubectl exec pod/sync -n greenwich -- date
Wed Mar 10 09:54:03 CST 2021
[root@master greenwich]# date
Wed Mar 10 09:54:04 CST 2021

总结:
1.podpreset需要设置环境变量 TZ=Asia/Shanghai
2.容器挂载宿主机的/etc/localtime
3.selector.matchLabels下要跟上对应pod中定义的labels(app:nginx),不然新生成的容器的时间不会同步,网上说可以不写app:nginx,但是我新建的容器时间没有同步。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值