(一)K8S 资源管理方式
创始人
2024-05-09 01:43:59
0

什么是资源

在K8s集群中创建的任何东西都可以被视为资源:部署(deployment)、Pod、Service等等

资源的管理方式

1、命令式对象管理

直接使用命令去操作k8s的资源,操作简单,只能操作活动对象,无法审计和跟踪,所以通常用于测试
命令语法:kubectl command [type] [name] [flags]command:指定要对资源执行的操作,run、create、get、deletetype:指定资源的类型,deployment、pod、servicename:指定资源的名称(名称大小写敏感)flags:指定额外的可选参数

command

kubectl --help # 查询所有command
  • 基础命令
    create【创建资源】
    edit【编辑资源】
    set【为对象设置指定特性】
    get【显示资源】
    delete【删除资源】

  • 运行、调试命令
    run【在集群上运行特定镜像】
    expose【暴露资源为Service】
    describe【 显示特定资源或资源组的详细信息】
    explain【显示资源文档】
    logs【打印 Pod 中容器的日志】
    attach【挂接到一个运行中的容器】
    exec【在某个容器中执行一个命令】
    port-forward【将一个或多个本地端口转发到某个 Pod】
    proxy【运行一个指向 Kubernetes API 服务器的代理】
    cp【在Pod内、外复制文件】
    auth【检查授权】
    debug【创建调试会话以排除工作负载和节点故障】
    events【列出事件】

  • 高级命令
    apply【根据文件名或stdin创建资源】
    replace【根据文件名或stdin替换资源】
    patch【更新资源】
    diff【区分实时版本与潜在应用版本】
    wait【Experimental: Wait for a specific condition on one or many resources】
    kustomize【Build a kustomization target from a directory or URL】

  • 设置指令
    label【更新某资源上的标签】
    annotate【更新一个资源的注解】
    completion【输出指定shell(bash、zsh、fish或powershell)的shell完成代码】

  • 部署指令
    rollout【Manage the rollout of a resource】
    scale【Set a new size for a deployment, replica set, or replication controller】
    autoscale【Auto-scale a deployment, replica set, stateful set, or replication controller】

  • 集群管理指令
    cluster-info【展示集群信息】
    top【Display resource (CPU/memory) usage】
    cordon【标记节点为不可调度】
    uncordon【标记节点为可调度】
    drain【 清空节点以准备维护】
    taint【更新一个或者多个节点上的污点】
    certificate【修改证书资源】

  • 其它指令
    alpha【Commands for features in alpha】
    api-resources【Print the supported API resources on the server】
    api-versions【Print the supported API versions on the server, in the form of “group/version”】
    config【修改 kubeconfig 文件】
    plugin【Provides utilities for interacting with plugins】
    version【输出客户端和服务端的版本信息】

type

kubectl api-resources # 查询所有type
  • 集群级别资源
    namespaces【命名空间,隔离Pod】
    nodes【集群组成部分】

  • Pod资源
    pods【装载容器】

  • Pod资源控制器
    deployments【Pod控制器】
    replicationcontrollers
    replicasets
    daemonsets
    statefulsets
    controllerrevisions
    jobs
    cronjobs
    horizontalpodautoscalers

  • 服务发现资源
    services【统一Pod对外接口】
    ingresses【统一Pod对外接口】
    ingressclasses
    networkpolicies

  • 存储资源
    csidrivers
    csinodes
    csistoragecapacities
    storageclasses
    volumeattachments

  • 配置资源
    configmaps
    secrets

  • 其它
    bindings
    componentstatuses
    endpoints
    events
    limitranges
    persistentvolumeclaims
    persistentvolumes
    podtemplates
    resourcequotas
    serviceaccounts

localsubjectaccessreviews
selfsubjectaccessreviews
selfsubjectrulesreviews
subjectaccessreviews

clusterrolebindings
clusterroles
rolebindings
roles

mutatingwebhookconfigurations
validatingwebhookconfigurations

2、命令式对象配置

理解:通过create命令和配置文件去操作kubernetes的资源
cd /home/lixing && kubectl create -f nginx-pod.yaml # 创建Pod
cd /home/lixing && kubectl get -f nginx-pod.yaml # 查询Pod
cd /home/lixing && kubectl delete -f nginx-pod.yaml # 删除Pod
  • nginx-pod.yaml
apiVersion: v1
kind: Pod
metadata: name: nginx-podnamespace: devlabels: env: "dev"version: "1.0"
spec: containers: - image: nginx:1.17.1imagePullPolicy: IfNotPresentname: nginx-containerports:- name: nginx-portcontainerPort: 80protocol: TCP

3、声明式对象配置

通过apply命令和配置文件去操作kubernetes的资源。可以同时操作一个目录下的多个配置文件,出现错误难调试。
apply的资源不存在则创建,存在则更新,相当于create和patch的组合
cd /home/lixing && kubectl apply -f nginx-pod.yaml # 创建Pod

相关内容

热门资讯

保存时出现了1个错误,导致这篇... 当保存文章时出现错误时,可以通过以下步骤解决问题:查看错误信息:查看错误提示信息可以帮助我们了解具体...
汇川伺服电机位置控制模式参数配... 1. 基本控制参数设置 1)设置位置控制模式   2)绝对值位置线性模...
不能访问光猫的的管理页面 光猫是现代家庭宽带网络的重要组成部分,它可以提供高速稳定的网络连接。但是,有时候我们会遇到不能访问光...
表格中数据未显示 当表格中的数据未显示时,可能是由于以下几个原因导致的:HTML代码问题:检查表格的HTML代码是否正...
本地主机上的图像未显示 问题描述:在本地主机上显示图像时,图像未能正常显示。解决方法:以下是一些可能的解决方法,具体取决于问...
不一致的条件格式 要解决不一致的条件格式问题,可以按照以下步骤进行:确定条件格式的规则:首先,需要明确条件格式的规则是...
表格列调整大小出现问题 问题描述:表格列调整大小出现问题,无法正常调整列宽。解决方法:检查表格的布局方式是否正确。确保表格使...
Android|无法访问或保存... 这个问题可能是由于权限设置不正确导致的。您需要在应用程序清单文件中添加以下代码来请求适当的权限:此外...
【NI Multisim 14...   目录 序言 一、工具栏 🍊1.“标准”工具栏 🍊 2.视图工具...
银河麒麟V10SP1高级服务器... 银河麒麟高级服务器操作系统简介: 银河麒麟高级服务器操作系统V10是针对企业级关键业务...