kubernetes优化之旅

本文详细探讨了kubernetes在处理OOM问题、Pod分配策略、QoS策略、kubelet优化等方面的各种优化方法,包括设置kube-reserved和system-reserved预留资源,使用initContainer初始化服务,以及调整Pod的启动顺序等,旨在提升Kubernetes集群的稳定性和效率。
摘要由CSDN通过智能技术生成

1、kubectl oom问题处理,把oomkill进程的权限交给k8s去killpod

https://blog.csdn.net/liukuan73/article/details/78787911
https://github.com/kubernetes/community/blob/master/contributors/design-proposals/node/kubelet-eviction.md#enforce-node-allocatable

2、pod statfulset 分配到不同机器上,使用亲和性反亲和

https://www.cnblogs.com/breezey/tag/kubernetes/

3、pod添加启动依赖,顺序

      initContainers:
      - name: init
        image: reg.xiaoneng.cn/library/k8s-kubectl:v1.10.4
        command:
        - "/bin/sh"
        - "-c"
        - "until kubectl get pods |grep dolphin-setting|grep \"Running\"|grep \"1/1\"; do echo waiting for dolphin-setting;sleep 2;done && \
           until if [[ `kubectl get pods |grep \"zk-\" |grep \"Running\"|grep \"1/1\"|wc -l` -ge 5 ]];then echo ok;else asd >/dev/null 2&>1 ;fi;do e
cho waiting for zookeeper;sleep 2;done "        env:
        - name: KUBECONFIG
          value: "/etc/kubernetes/admin.conf"
        volumeMounts:
        - name: kubectl-admin
          mountPath: /etc/kubernetes/
      volumes:
      - name: kubectl-admin
        configMap:
          name: kubectl-admin

4、使用pod的名字作为变量

https://kubernetes.io/docs/tasks/inject-data-application/environment-variable-expose-pod-information/
       - name: MY_NODE_NAME
          valueFrom:
            fieldRef:
              fieldPath: spec.nodeName
        - name: MY_POD_NAME
          valueFrom:
            fieldRef:
              fieldPath: metadata.name
        - name: MY_POD_NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        - name: MY_POD_IP
          valueFrom:
            fieldRef:
              fieldPath: status.podIP
        - name: MY_POD_SERVICE_ACCOUNT
          valueFrom:
            fieldRef:
              fieldPath: spec.serviceAccountName

使用limit/request作为变量

     resources:
        requests:
          memory: "32Mi"
          cpu: "125m"
        limits:
          memory: "64Mi"
          cpu: "250m"
      env:
        - name: MY_CPU_REQUEST
          valueFrom:
            resourceFieldRef:
              containerName: test-container
              resource: requests.cpu
        - name: MY_CPU_LIMIT
          valueFrom:
            resourceFieldRef:
              containerName: test-container
              resource: limits.cpu
        - name: MY_MEM_REQUEST
          valueFrom:
            resourceFieldRef:
              containerName: test-container
              resource: requests.memory
        - name: MY_MEM_LIMIT
          valueFrom:
            resourceFieldRef:
              containerName: test-container
              resource: limits.memory

5、ingress各种规则修改

6、kubernetes node失效后的调度过程以及时间调整参数(kube-controller-manager)

#https://blog.csdn.net/levy_cui/article/details/70229818
# https://k8smeetup.github.io/docs/admin/kube-controller-manager/

kubernetes节点失效后pod的调度过程

0、Master每隔一段时间和node联系一次,判定node是否失联,这个时间周期配置项为 node-monitor-period ,默认5s

1、当node失联后一段时间后,kubernetes判定node为notready状态,这段时长的配置项为 node-monitor-grace-period ,默认40s

2、当node失联后一段时间后,kubernetes判定node为unhealthy,这段时长的配置项为 node-start
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值