惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
小众软件
小众软件
MongoDB | Blog
MongoDB | Blog
Hugging Face - Blog
Hugging Face - Blog
Jina AI
Jina AI
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Stack Overflow Blog
Stack Overflow Blog
L
LangChain Blog
大猫的无限游戏
大猫的无限游戏
量子位
A
About on SuperTechFans
G
Google Developers Blog
雷峰网
雷峰网
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
IT之家
IT之家
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园_首页
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Vercel News
Vercel News
V
Visual Studio Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 聂微东
U
Unit 42
Apple Machine Learning Research
Apple Machine Learning Research

Hi,I`m lan

MCP协议新进展: 使用 Streamable HTTP 替换当前的 HTTP+SSE 实现。-liangyuanpeng 的博客 我的 AI 员工们开发的微信小程序上线了!-liangyuanpeng 的博客 | liangyuanpeng's Blog liangyuanpeng 的博客 | liangyuanpeng's Blog vercel 记录-liangyuanpeng 的博客 | liangyuanpeng's Blog liangyuanpeng 的博客 | liangyuanpeng's Blog [长期更新]cocos creator问题列表-liangyuanpeng 的博客 | liangyuanpeng's Blog go问题列表记录-liangyuanpeng 的博客 | liangyuanpeng's Blog liangyuanpeng 的博客 | liangyuanpeng's Blog node镜像的更多选择-liangyuanpeng 的博客 | liangyuanpeng's Blog liangyuanpeng 的博客 | liangyuanpeng's Blog liangyuanpeng 的博客 | liangyuanpeng's Blog containerd 中的弃用警告 - 为 2.0 做好准备!-liangyuanpeng 的博客 liangyuanpeng 的博客 | liangyuanpeng's Blog kep-1880-多服务CIDR-liangyuanpeng 的博客 | liangyuanpeng's Blog [长期更新]argoworkflow 的一些实践和思考-liangyuanpeng 的博客 | liangyuanpeng's Blog liangyuanpeng 的博客 | liangyuanpeng's Blog liangyuanpeng 的博客 | liangyuanpeng's Blog 将Etcd作为一个kubernetes sig来运作-liangyuanpeng 的博客 | liangyuanpeng's Blog liangyuanpeng 的博客 | liangyuanpeng's Blog argoworkflow 云原生工作流引擎-liangyuanpeng 的博客 | liangyuanpeng's Blog liangyuanpeng 的博客 | liangyuanpeng's Blog liangyuanpeng 的博客 | liangyuanpeng's Blog kubecon china 2023将在上海举办-liangyuanpeng 的博客 | liangyuanpeng's Blog liangyuanpeng 的博客 | liangyuanpeng's Blog liangyuanpeng 的博客 | liangyuanpeng's Blog liangyuanpeng 的博客 | liangyuanpeng's Blog liangyuanpeng 的博客 | liangyuanpeng's Blog liangyuanpeng 的博客 | liangyuanpeng's Blog liangyuanpeng 的博客 | liangyuanpeng's Blog liangyuanpeng 的博客 | liangyuanpeng's Blog
部署metrics-server,把kubectl top用起来-liangyuanpeng 的博...
2021-11-15 · via Hi,I`m lan

TOC

部署metrics-server

yaml部署

yaml文件如下:

apiVersion: v1
kind: ServiceAccount
metadata:
  labels:
    k8s-app: metrics-server
  name: metrics-server
  namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  labels:
    k8s-app: metrics-server
    rbac.authorization.k8s.io/aggregate-to-admin: "true"
    rbac.authorization.k8s.io/aggregate-to-edit: "true"
    rbac.authorization.k8s.io/aggregate-to-view: "true"
  name: system:aggregated-metrics-reader
rules:
- apiGroups:
  - metrics.k8s.io
  resources:
  - pods
  - nodes
  verbs:
  - get
  - list
  - watch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  labels:
    k8s-app: metrics-server
  name: system:metrics-server
rules:
- apiGroups:
  - ""
  resources:
  - pods
  - nodes
  - nodes/stats
  - namespaces
  - configmaps
  verbs:
  - get
  - list
  - watch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  labels:
    k8s-app: metrics-server
  name: metrics-server-auth-reader
  namespace: kube-system
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: extension-apiserver-authentication-reader
subjects:
- kind: ServiceAccount
  name: metrics-server
  namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  labels:
    k8s-app: metrics-server
  name: metrics-server:system:auth-delegator
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: system:auth-delegator
subjects:
- kind: ServiceAccount
  name: metrics-server
  namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  labels:
    k8s-app: metrics-server
  name: system:metrics-server
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: system:metrics-server
subjects:
- kind: ServiceAccount
  name: metrics-server
  namespace: kube-system
---
apiVersion: v1
kind: Service
metadata:
  labels:
    k8s-app: metrics-server
  name: metrics-server
  namespace: kube-system
spec:
  ports:
  - name: https
    port: 443
    protocol: TCP
    targetPort: https
  selector:
    k8s-app: metrics-server
---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    k8s-app: metrics-server
  name: metrics-server
  namespace: kube-system
spec:
  selector:
    matchLabels:
      k8s-app: metrics-server
  strategy:
    rollingUpdate:
      maxUnavailable: 0
  template:
    metadata:
      labels:
        k8s-app: metrics-server
    spec:
      containers:
      - args:
        - --cert-dir=/tmp
        - --secure-port=443
        - --kubelet-preferred-address-types=InternalIP,ExternalIP,Hostname
        - --kubelet-use-node-status-port
        - --metric-resolution=15s
        image: k8s.gcr.io/metrics-server/metrics-server:v0.5.1
        imagePullPolicy: IfNotPresent
        livenessProbe:
          failureThreshold: 3
          httpGet:
            path: /livez
            port: https
            scheme: HTTPS
          periodSeconds: 10
        name: metrics-server
        ports:
        - containerPort: 443
          name: https
          protocol: TCP
        readinessProbe:
          failureThreshold: 3
          httpGet:
            path: /readyz
            port: https
            scheme: HTTPS
          initialDelaySeconds: 20
          periodSeconds: 10
        resources:
          requests:
            cpu: 100m
            memory: 200Mi
        securityContext:
          readOnlyRootFilesystem: true
          runAsNonRoot: true
          runAsUser: 1000
        volumeMounts:
        - mountPath: /tmp
          name: tmp-dir
      nodeSelector:
        kubernetes.io/os: linux
      priorityClassName: system-cluster-critical
      serviceAccountName: metrics-server
      volumes:
      - emptyDir: {}
        name: tmp-dir
---
apiVersion: apiregistration.k8s.io/v1
kind: APIService
metadata:
  labels:
    k8s-app: metrics-server
  name: v1beta1.metrics.k8s.io
spec:
  group: metrics.k8s.io
  groupPriorityMinimum: 100
  insecureSkipTLSVerify: true
  service:
    name: metrics-server
    namespace: kube-system
  version: v1beta1
  versionPriority: 100

直接用这个yaml部署的话是国内会部署失败的,因为镜像使用了k8s.gcr.io,而国内访问不了.

这时候只需要把k8s.gcr.io修改为lank8s.cn,再次部署这个yaml就可以了!

如果部署k8s.gcr.io的镜像容器多了,每次都去修改的话就会很繁琐,这时候可以部署一个webhook来自动化这个过程(将k8s.gcr.io修改为lank8s.cn).现在lank8s.cn提供了一个在线的webhook在开发测试环境使用,马上会手把手教你部署一个webhook在本地集群.

你可以这样体验一下在线的webhook:

apiVersion: admissionregistration.k8s.io/v1beta1
kind: MutatingWebhookConfiguration
metadata:
  name: lanwebhook
webhooks:
  - name: lanwebhook.lank8s.cn
    clientConfig:
      url: "https://lank8s.cn/mutate"
    rules:
      - operations: [ "CREATE" ]
        apiGroups: ["apps", ""]
        apiVersions: ["v1"]
        resources: ["deployments","daemonsets","statefulsets"]

使用上面内容创建一个webhook-conf.yaml,然后create/apply.

kubectl apply -f webhook-conf.yaml

完美拉取k8s.gcr.io镜像!

Helm 部署

helm repo add metrics-server https://kubernetes-sigs.github.io/metrics-server/
helm upgrade --install metrics-server metrics-server/metrics-server -n kube-system --set image.repository=lank8s.cn/metrics-server/metrics-server

kubectl top原理

测试PR

什么是lank8s.cn

lank8s.cn是我个人在长久维护的一个免费k8s.gcr.io镜像代理服务,也就是说k8s.gcr.io有什么镜像就可以通过lank8s.cn拉取什么镜像.

另一个gcr.io仓库也有对应的gcr.lank8s.cn,不一样的是gcr.lank8s.cn是以收费方式推出的服务,这是希望分担一下我在lank8s.cn上服务器,域名等费用的经济压力.

但是gcr.lank8s.cn也有部分免费镜像提供支持,例如/google_samples的镜像,/kubebuilder的镜像,/istio-release的镜像.

详细内容请查看:https://github.com/lank8s

微信公众号

扫描下面的二维码关注我们的微信公众号,第一时间查看最新内容。同时也可以关注我的Github,看看我都在了解什么技术,在页面底部可以找到我的Github。

wechat-qrcode

温馨提示

本文还在持续创作中,如果你对本文主题感兴趣可以加我微信好友进行催更,博客下方可以找到我的微信联系方式 :)