k8s.gcr.io改為registry.k8s.io

新聞:k8s.gcr.io Redirect to registry.k8s.io – What You Need to Know | Kubernetes

簡單的說,k8s.gcr.io 要被關掉了,所以從 k8s.gcr.io 拉取的 image ,未來會有影響,例如砍掉 pod 以後,有可能拉不到 image 了。

所以要找出所有使用 k8s.gcr.io 的 deployment/statefulset/pod … 資源,方法有兩種。

第1種是用 kubectl 來找

kubectl get pods --all-namespaces -o jsonpath="{.items[*].spec.containers[*].image}" |\
tr -s '[[:space:]]' '\n' |\
sort |\
uniq -c

簡單的說,就是列出所有 pod 的 YAML,取出裡面的 image ,整理過以後,列出來。

第二種是用 kubectl krew 安裝 community-images plugin

kubectl krew install community-images
kubectl community-images

使用以上其中一種方法找到以後,該怎麼辦?

接下來就是用 kubectl edit 去修改 image 位址。

若是用 gitops 或 helm 的方法,作法也相似,就是去修改 manifest yaml ,然後重新佈署就可以了。

[RHEL]grub設定密碼

以下指令可以避免讓使用者在開機時,可以調整 kernel 參數。若是在 kernel 參數填入 single 或 rescue ,使用者就有機會可以使用到較高的權限。

先用 grub2-setpassword 設定密碼,設定以後,/boot/grub2 資料夾裡會多出 user.cfg

grub2-setpassword 

再來重新產生 grub.cfg

grub2-mkconfig -o /boot/grub2/grub.cfg

這樣就完成了。

重開機看到開機選單以後,按下 e ,此時會要求輸入密碼,表示設定已經生效。

若要移除,刪除掉 user.cfg 即可。

rm /boot/grub2/user.cfg

若是要一進入開機選單就要輸入帳號跟密碼,那麼可以這樣設定

grub2-editenv - set grub_users="root"

這樣在開機時,就會問帳號跟密碼了。

要移除,可以用

grub2-editenv - set grub_users=

參考資料

[Kubernetes]Pod rebalancing and allocations

文章來源:Pod rebalancing and allocations

簡單整理如下:

  • 應用程式是 deployment,有兩個 pod
  • 本來只有一個 node,兩個 pod 都會佈署在上面,所以如果一個 node 掛了,那麼應用程式就無法回應了。現在增加另外一個 node ,一般會預期 pod 移動一個到新的 node 上,但實際上 Kubernetes 不會做任何動作。

可以怎麼做?

Pod affinity

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
  namespace: ellery-lab
spec:
  # 省略
  template:
    metadata:
      labels:
        app: MyTestApp
    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: disktype
                operator: In
                values:
                - ssd

pod topology spread constraints

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
  namespace: ellery-lab
spec:
  # 省略
  template:
    metadata:
      labels:
        app: MyTestApp
    spec:
      topologySpreadConstraints:
      - maxSkew: 1
        topologyKey: zone
        whenUnsatisfiable: DoNotSchedule
        labelSelector:
          matchLabels:
            foo: bar

descheduler

這個是需要另外安裝的,安裝以後會在 kube-system 裏面找到,是一個 pod 。

The descheduler pod is run as a critical pod in the kube-system namespace to avoid being evicted by itself or by the kubelet

安裝完成以後,還需要設定 policy ,比較麻煩一些,但可以做到動態的處理,功能也比較多。