当前位置: 首页 > news >正文

Kubernetes学习笔记8

Kubernetes集群客户端工具kubectl

我们已经能够部署Kubernetes了,那么我们如何使用Kubernetes集群运行企业的应用程序呢?那么,我们就需要使用命令行工具kubectl。

kubectl就是控制Kubernetes的驾驶舱,它允许你执行所有可能的Kubernetes操作,从技术角度来看,Kubectl就是Kubernetes API的一个客户端而已。

Kubernetes API 是一个 HTTP REST API 服务,该 API 服务才是 Kubernetes 的真正用到的用户接口,所以 Kubernetes 通过该 API 进行实际的控制。这也就意味着每个 Kubernetes 的操作都会通过 API 端点暴露出去,当然也就可以通过对这些 API 端口进行 HTTP 请求来执行相应的操作。所以,kubectl 最主要的工作就是执行 Kubernetes API 的 HTTP 请求。

 

学习目标:

了解kubectl 命令帮助方法

了解kubectl子命令使用分类

课程内容:

1、kubectl帮助方法:

我们预先是在所有节点上安装了kubectl工具。

# 检查kubectl是否安装:
[root@master1 ~]# rpm -qa |grep kubectl
kubectl-1.21.10-0.x86_64
[root@master1 ~]## 获取kubectl帮助方法:
[root@master1 ~]# kubectl --help
kubectl controls the Kubernetes cluster manager.Find more information at:
https://kubernetes.io/docs/reference/kubectl/overview/Basic Commands (Beginner):create        Create a resource from a file or from stdin.expose        Take a replication controller, service, deployment or pod and
expose it as a new Kubernetes Servicerun           Run a particular image on the clusterset           Set specific features on objectsBasic Commands (Intermediate):explain       Documentation of resourcesget           Display one or many resourcesedit          Edit a resource on the serverdelete        Delete resources by filenames, stdin, resources and names, or by
resources and label selectorDeploy Commands:rollout       Manage the rollout of a resourcescale         Set a new size for a Deployment, ReplicaSet or Replication
Controllerautoscale     Auto-scale a Deployment, ReplicaSet, StatefulSet, or
ReplicationControllerCluster Management Commands:certificate   Modify certificate resources.cluster-info  Display cluster infotop           Display Resource (CPU/Memory) usage.cordon        Mark node as unschedulableuncordon      Mark node as schedulabledrain         Drain node in preparation for maintenancetaint         Update the taints on one or more nodesTroubleshooting and Debugging Commands:describe      Show details of a specific resource or group of resourceslogs          Print the logs for a container in a podattach        Attach to a running containerexec          Execute a command in a containerport-forward  Forward one or more local ports to a podproxy         Run a proxy to the Kubernetes API servercp            Copy files and directories to and from containers.auth          Inspect authorizationdebug         Create debugging sessions for troubleshooting workloads and
nodesAdvanced Commands:diff          Diff live version against would-be applied versionapply         Apply a configuration to a resource by filename or stdinpatch         Update field(s) of a resourcereplace       Replace a resource by filename or stdinwait          Experimental: Wait for a specific condition on one or many
resources.kustomize     Build a kustomization target from a directory or URL.Settings Commands:label         Update the labels on a resourceannotate      Update the annotations on a resourcecompletion    Output shell completion code for the specified shell (bash or
zsh)Other Commands:api-resources Print the supported API resources on the serverapi-versions  Print the supported API versions on the server, in the form of
"group/version"config        Modify kubeconfig filesplugin        Provides utilities for interacting with plugins.version       Print the client and server version informationUsage:kubectl [flags] [options]Use "kubectl <command> --help" for more information about a given command.
Use "kubectl options" for a list of global command-line options (applies to all
commands).

kubectl子命令使用分类:

列出所有pod并显示详细信息

[root@master1 ~]# kubectl get pods -o wide
NAME                     READY   STATUS    RESTARTS   AGE   IP           NODE      NOMINATED NODE   READINESS GATES
nginx-65c4bffcb6-gd9z6   1/1     Running   0          8h    10.244.1.4   worker1   <none>           <none>

查看所有deployment对象。

[root@master1 ~]# kubectl get deployment nginx
NAME    READY   UP-TO-DATE   AVAILABLE   AGE
nginx   1/1     1            1           9h

查看所有service对象:

[root@master1 ~]# kubectl get svc
NAME         TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)        AGE
kubernetes   ClusterIP   10.96.0.1      <none>        443/TCP        10h
nginx        NodePort    10.101.138.1   <none>        80:30831/TCP   9h
[root@master1 ~]#
[root@master1 ~]#
[root@master1 ~]# kubectl get service
NAME         TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)        AGE
kubernetes   ClusterIP   10.96.0.1      <none>        443/TCP        10h
nginx        NodePort    10.101.138.1   <none>        80:30831/TCP   9h

查看不同namespace下的Pod对象:

[root@master1 ~]# kubectl get pods -n default
NAME                     READY   STATUS    RESTARTS   AGE
nginx-65c4bffcb6-gd9z6   1/1     Running   0          9h[root@master1 ~]# kubectl get pods --all-namespaces
NAMESPACE      NAME                                       READY   STATUS    RESTARTS   AGE
default        nginx-65c4bffcb6-gd9z6                     1/1     Running   0          9h
kube-flannel   kube-flannel-ds-dvjnd                      1/1     Running   0          9h
kube-flannel   kube-flannel-ds-gxl4h                      1/1     Running   0          9h
kube-flannel   kube-flannel-ds-jvdzc                      1/1     Running   0          9h
kube-system    calico-kube-controllers-594649bd75-xjbgr   1/1     Running   0          9h
kube-system    calico-node-6lz45                          1/1     Running   0          9h
kube-system    calico-node-fdprn                          1/1     Running   0          9h
kube-system    calico-node-szs6x                          1/1     Running   0          9h
kube-system    coredns-558bd4d5db-fmrpg                   1/1     Running   0          10h
kube-system    coredns-558bd4d5db-fnxdn                   1/1     Running   0          10h
kube-system    etcd-master1                               1/1     Running   1          10h
kube-system    kube-apiserver-master1                     1/1     Running   1          10h
kube-system    kube-controller-manager-master1            1/1     Running   1          10h
kube-system    kube-proxy-rz26h                           1/1     Running   0          9h
kube-system    kube-proxy-spf9t                           1/1     Running   1          9h
kube-system    kube-proxy-x4fq5                           1/1     Running   0          10h
kube-system    kube-scheduler-master1                     1/1     Running   1          10h

查看资源描述:

[root@master1 ~]# kubectl describe pods
Name:         nginx-65c4bffcb6-gd9z6
Namespace:    default
Priority:     0
Node:         worker1/192.168.17.147
Start Time:   Sat, 06 Apr 2024 19:04:43 +0800
Labels:       app=nginxpod-template-hash=65c4bffcb6
Annotations:  <none>
Status:       Running
IP:           10.244.1.4
IPs:IP:           10.244.1.4
Controlled By:  ReplicaSet/nginx-65c4bffcb6
Containers:nginx:Container ID:   docker://b0860e41573587a5c065c9aa18c398475b1b31f9f56d7d3c2e04171f80f1e1c1Image:          nginx:1.14-alpineImage ID:       docker-pullable://nginx@sha256:485b610fefec7ff6c463ced9623314a04ed67e3945b9c08d7e53a47f6d108dc7Port:           <none>Host Port:      <none>State:          RunningStarted:      Sat, 06 Apr 2024 19:05:04 +0800Ready:          TrueRestart Count:  0Environment:    <none>Mounts:/var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-mjhtz (ro)
Conditions:Type              StatusInitialized       TrueReady             TrueContainersReady   TruePodScheduled      True
Volumes:kube-api-access-mjhtz:Type:                    Projected (a volume that contains injected data from multiple sources)TokenExpirationSeconds:  3607ConfigMapName:           kube-root-ca.crtConfigMapOptional:       <nil>DownwardAPI:             true
QoS Class:                   BestEffort
Node-Selectors:              <none>
Tolerations:                 node.kubernetes.io/not-ready:NoExecute op=Exists for 300snode.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:                      <none>

所有的命令都要熟练使用。

使用kubectl命令必要环境:

在worker节点如何使用kubectl命令管理K8s集群?

准备集群管理配置文件:

mkdir .kube
scp master1:/root/.kube/config .kube/

使用命令验证:

[root@worker1 ~]# kubectl get nodes
NAME      STATUS   ROLES                  AGE   VERSION
master1   Ready    control-plane,master   10h   v1.21.10
worker1   Ready    <none>                 10h   v1.21.10
worker2   Ready    <none>                 10h   v1.21.10

其中这个config的配置文件:

这是一个连接Kubernetes API (IP地址+端口),就能管理到集群。

 

相关文章:

Kubernetes学习笔记8

Kubernetes集群客户端工具kubectl 我们已经能够部署Kubernetes了&#xff0c;那么我们如何使用Kubernetes集群运行企业的应用程序呢&#xff1f;那么&#xff0c;我们就需要使用命令行工具kubectl。 kubectl就是控制Kubernetes的驾驶舱&#xff0c;它允许你执行所有可能的Kube…...

[渗透利器]在线渗透测试工具箱?测评

前言 hxd更新完了在线工具箱&#xff0c;受邀写一下使用体验以及测评 使用体验 这个工具箱设计的比较轻便&#xff0c;以往用过的工具箱大多都是以离线打包的方式发布&#xff0c;该工具箱&#xff0c;作者自己掏钱自己买服务器&#xff0c;自己买带宽&#xff0c;先生大义。…...

rocketmq和rabbitmq总是分不清?

1. 官方解答 摘自百度搜索&#xff1a; 2. 通俗易懂的回答...

利用Python ARM网关仓储物流AGV小车控制器

在现代智慧物流体系中&#xff0c;高效的信息管理系统是物流中心实现精准跟踪货物、科学管理库存及优化配送路线的关键环节。通过采用ARM架构的工控机或网关&#xff0c;并结合Python的二次开发能力&#xff0c;可以有效集成并强化物流管理系统的数据处理与通信功能&#xff0c…...

Transformer详解和知识点总结

目录 1. 注意力机制1.1 注意力评分函数1.2 多头注意力&#xff08;Multi-head self-attention&#xff09; 2. Layer norm3. 模型结构4. Attention在Transformer中三种形式的应用 论文&#xff1a;https://arxiv.org/abs/1706.03762 李沐B站视频&#xff1a;https://www.bilibi…...

【Ubuntu】update-alternatives 命令详解

1、查看所有候选项 ​​​​​​​sudo update-alternatives --list java 2、​​​​​​​更换候选项 sudo update-alternatives --config java 3、自动选择优先级最高的作为默认项 sudo update-alternatives --auto java 4、删除候选项 sudo update-alternatives --rem…...

数据结构之堆练习题及PriorityQueue深入讲解!

题外话 上午学了一些JavaEE初阶知识,下午继续复习数据结构内容 正题 本篇内容把堆的练习题做一下 第一题 1.下列关键字序列为堆的是:( A ) A: 100,60,70,50,32,65 B: 60,70,65,50,32,100 C: 65,100,70,32,50,60 D: 70,65,100,32,50,60 E: 32,50,100,70,65,60 …...

MySQL——Linux安装包

一、下载安装包 MySQL下载路径&#xff1a; MySQL :: MySQL Downloads //默认下载的企业版MySQL 下载社区版MySQL MySQL :: MySQL Community Downloads 1、源码下载 2、仓库配置 3、二进制安装包 基于官方仓库安装 清华centos 软件仓库&#xff1a; Index of /cen…...

MySQL学习笔记(数据类型, DDL, DML, DQL, DCL)

Learning note 1、前言2、数据类型2.1、数值类型2.2、字符串类型2.3、日期类型 3、DDL总览数据库/表切换数据库查看表内容创建数据库/表删除数据库/表添加字段删除字段表的重命名修改字段名&#xff08;以及对应的数据类型&#xff09; 4、DML往字段里写入具体内容修改字段内容…...

Asible管理变量与事实——管理变量(1)

Ansible简介 Ansible支持利用变量来储存值&#xff0c;并在Ansible项目的所有文件中重复使用这些值。这可以简化项目的创建和维护&#xff0c;并减少错误的数量。 通过变量&#xff0c;您可以轻松地在Ansible项目中管理给定环境的动态值。例如&#xff0c;变量可能包含下面这些…...

【微服务】------微服务架构技术栈

目前微服务早已火遍大江南北&#xff0c;对于开发来说&#xff0c;我们时刻关注着技术的迭代更新&#xff0c;而项目采用什么技术栈选型落地是开发、产品都需要关注的事情&#xff0c;该篇博客主要分享一些目前普遍公司都在用的技术栈&#xff0c;快来分享一下你当前所在用的技…...

【SCI绘图】【小提琴系列1 python】绘制按分类变量分组的垂直小提琴图

SCI&#xff0c;CCF&#xff0c;EI及核心期刊绘图宝典&#xff0c;爆款持续更新&#xff0c;助力科研&#xff01; 本期分享&#xff1a; 【SCI绘图】【小提琴系列1 python】绘制按分类变量分组的垂直小提琴图&#xff0c;文末附完整代码 小提琴图是一种常用的数据可视化工具…...

docker------docker入门

&#x1f388;个人主页&#xff1a;靓仔很忙i &#x1f4bb;B 站主页&#xff1a;&#x1f449;B站&#x1f448; &#x1f389;欢迎 &#x1f44d;点赞✍评论⭐收藏 &#x1f917;收录专栏&#xff1a;Linux &#x1f91d;希望本文对您有所裨益&#xff0c;如有不足之处&#…...

终极数据传输隐秘通道

SOCKS5代理作为网络请求中介的高级形态&#xff0c;提供了一种方法&#xff0c;通过它&#xff0c;数据包在传达其最终目的地前&#xff0c;首先经过一个第三方服务器。这种代理的先进之处在于其对各种协议的支持&#xff0c;包括HTTP、FTP和SMTP&#xff0c;以及它的认证机制&…...

Qt中的事件与事件处理

Qt框架中的事件处理机制是其GUI编程的核心部分&#xff0c;它确保了用户与应用程序之间的交互能够得到正确的响应。以下是对Qt事件处理机制的详细讲解以及提供一些基本示例。 1. 事件与事件处理简介 事件&#xff1a;在Qt中&#xff0c;所有的事件都是从QEvent基类派生出来的&…...

中间件漏洞攻防学习总结

前言 面试常问的一些中间件&#xff0c;学习总结一下。以下环境分别使用vulhub和vulfocus复现。 Apache apache 文件上传 (CVE-2017-15715) 描述: Apache(音译为阿帕奇)是世界使用排名第一的Web服务器软件。它可以运行在几乎所有广泛使用的计算机平台上&#xff0c;由于其跨…...

HarmonyOS开发实例:【分布式数据管理】

介绍 本示例展示了在eTS中分布式数据管理的使用&#xff0c;包括KVManager对象实例的创建和KVStore数据流转的使用。 通过设备管理接口[ohos.distributedDeviceManager]&#xff0c;实现设备之间的kvStore对象的数据传输交互&#xff0c;该对象拥有以下能力 ; 1、注册和解除注…...

蓝桥杯——运动会

题目 n 个运动员参加一个由 m 项运动组成的运动会&#xff0c;要求每个运动员参加每个项目。每个运动员在每个项目都有一个成绩&#xff0c;成绩越大排名越靠前。每个项目&#xff0c;不同运功员的成绩不会相 同&#xff0c;因此排名不会相同。(但是不同项目可能成绩会相同) 每…...

如何搭建APP分发平台分发平台搭建教程

搭建一个APP分发平台可以帮助开发者更好地分发和管理他们的应用程序。下面是一个简要的教程&#xff0c;介绍如何搭建一个APP分发平台。 1.确定需求和功能&#xff1a;首先&#xff0c;确定你的APP分发平台的需求和功能。考虑以下几个方面&#xff1a; 用户注册和登录&#xff…...

【计算机专业必看】详细说明文件打开模式r,w,a,r+,w+,a+的区别和联系

文章目录 1、联系2、区别r&#xff08;只读&#xff09;w&#xff08;只写&#xff09;a&#xff08;追加&#xff09;r&#xff08;读写&#xff0c;文件必须存在&#xff09;w&#xff08;读写&#xff0c;文件不存在则创建&#xff0c;存在则清空&#xff09;a&#xff08;读…...

利用最小二乘法找圆心和半径

#include <iostream> #include <vector> #include <cmath> #include <Eigen/Dense> // 需安装Eigen库用于矩阵运算 // 定义点结构 struct Point { double x, y; Point(double x_, double y_) : x(x_), y(y_) {} }; // 最小二乘法求圆心和半径 …...

Docker 离线安装指南

参考文章 1、确认操作系统类型及内核版本 Docker依赖于Linux内核的一些特性&#xff0c;不同版本的Docker对内核版本有不同要求。例如&#xff0c;Docker 17.06及之后的版本通常需要Linux内核3.10及以上版本&#xff0c;Docker17.09及更高版本对应Linux内核4.9.x及更高版本。…...

centos 7 部署awstats 网站访问检测

一、基础环境准备&#xff08;两种安装方式都要做&#xff09; bash # 安装必要依赖 yum install -y httpd perl mod_perl perl-Time-HiRes perl-DateTime systemctl enable httpd # 设置 Apache 开机自启 systemctl start httpd # 启动 Apache二、安装 AWStats&#xff0…...

反射获取方法和属性

Java反射获取方法 在Java中&#xff0c;反射&#xff08;Reflection&#xff09;是一种强大的机制&#xff0c;允许程序在运行时访问和操作类的内部属性和方法。通过反射&#xff0c;可以动态地创建对象、调用方法、改变属性值&#xff0c;这在很多Java框架中如Spring和Hiberna…...

零基础设计模式——行为型模式 - 责任链模式

第四部分&#xff1a;行为型模式 - 责任链模式 (Chain of Responsibility Pattern) 欢迎来到行为型模式的学习&#xff01;行为型模式关注对象之间的职责分配、算法封装和对象间的交互。我们将学习的第一个行为型模式是责任链模式。 核心思想&#xff1a;使多个对象都有机会处…...

高防服务器能够抵御哪些网络攻击呢?

高防服务器作为一种有着高度防御能力的服务器&#xff0c;可以帮助网站应对分布式拒绝服务攻击&#xff0c;有效识别和清理一些恶意的网络流量&#xff0c;为用户提供安全且稳定的网络环境&#xff0c;那么&#xff0c;高防服务器一般都可以抵御哪些网络攻击呢&#xff1f;下面…...

使用Spring AI和MCP协议构建图片搜索服务

目录 使用Spring AI和MCP协议构建图片搜索服务 引言 技术栈概览 项目架构设计 架构图 服务端开发 1. 创建Spring Boot项目 2. 实现图片搜索工具 3. 配置传输模式 Stdio模式&#xff08;本地调用&#xff09; SSE模式&#xff08;远程调用&#xff09; 4. 注册工具提…...

Netty从入门到进阶(二)

二、Netty入门 1. 概述 1.1 Netty是什么 Netty is an asynchronous event-driven network application framework for rapid development of maintainable high performance protocol servers & clients. Netty是一个异步的、基于事件驱动的网络应用框架&#xff0c;用于…...

给网站添加live2d看板娘

给网站添加live2d看板娘 参考文献&#xff1a; stevenjoezhang/live2d-widget: 把萌萌哒的看板娘抱回家 (ノ≧∇≦)ノ | Live2D widget for web platformEikanya/Live2d-model: Live2d model collectionzenghongtu/live2d-model-assets 前言 网站环境如下&#xff0c;文章也主…...

stm32wle5 lpuart DMA数据不接收

配置波特率9600时&#xff0c;需要使用外部低速晶振...