网站首页 > 技术教程 正文
#kubectl#
使用场景
现在使用Kubernetes的时候,有很多UI工具可以选择,降低我们日常的使用难度,但还是有些场景,必须要使用命令行去查看,今天我们介绍的ingress-nginx插件,就可以在一些必须使用命令行的场景帮助我们提高效率
使用方法
用下面的命令安装后就可以直接使用了
kubectl krew install ingress-nginx
然后这个插件提供了很多的子命令,我们本篇文章挑一些常用来介绍:
mian@mian-PC:~$ kubectl ingress-nginx -h
A kubectl plugin for inspecting your ingress-nginx deployments
Usage:
ingress-nginx [command]
Available Commands:
backends Inspect the dynamic backend information of an ingress-nginx instance
certs Output the certificate data stored in an ingress-nginx pod
conf Inspect the generated nginx.conf
exec Execute a command inside an ingress-nginx pod
general Inspect the other dynamic ingress-nginx information
help Help about any command
info Show information about the ingress-nginx service
ingresses Provide a short summary of all of the ingress definitions
lint Inspect kubernetes resources for possible issues
logs Get the kubernetes logs for an ingress-nginx pod
ssh ssh into a running ingress-nginx pod
Flags:
--as string Username to impersonate for the operation
--as-group stringArray Group to impersonate for the operation, this flag can be repeated to specify multiple groups.
--cache-dir string Default HTTP cache directory (default "/home/mian/.kube/http-cache")
--certificate-authority string Path to a cert file for the certificate authority
--client-certificate string Path to a client certificate file for TLS
--client-key string Path to a client key file for TLS
--cluster string The name of the kubeconfig cluster to use
--context string The name of the kubeconfig context to use
-h, --help help for ingress-nginx
--insecure-skip-tls-verify If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure
--kubeconfig string Path to the kubeconfig file to use for CLI requests.
-n, --namespace string If present, the namespace scope for this CLI request
--request-timeout string The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0")
-s, --server string The address and port of the Kubernetes API server
--tls-server-name string Server name to use for server certificate validation. If it is not provided, the hostname used to contact the server is used
--token string Bearer token for authentication to the API server
--user string The name of the kubeconfig user to use
Use "ingress-nginx [command] --help" for more information about a command.
- ingresses
之前我们看ingress是这样:
$ kubectl get ingresses --all-namespaces
NAMESPACE NAME HOSTS ADDRESS PORTS AGE
default example-ingress1 testaddr.local,testaddr2.local localhost 80 5d
default test-ingress-2 * localhost 80 5d
有了这个插件后,输出会更丰富一些,包含了指向的service和后端副本数
$ kubectl ingress-nginx ingresses --all-namespaces
NAMESPACE INGRESS NAME HOST+PATH ADDRESSES TLS SERVICE SERVICE PORT ENDPOINTS
default example-ingress1 testaddr.local/etameta localhost NO pear-service 5678 5
default example-ingress1 testaddr2.local/otherpath localhost NO apple-service 5678 1
default example-ingress1 testaddr2.local/otherotherpath localhost NO pear-service 5678 5
default test-ingress-2 * localhost NO echo-service 8080 2
- conf
有时候我们下发了配置效果不符合预期,通常会去检查最终生成的nginx配置文件,要进入到ingress controller去查看,有了conf命令就简单多了:
kubectl ingress-nginx conf -n ingress-nginx --host testaddr.local
server {
server_name testaddr.local ;
listen 80;
set $proxy_upstream_name "-";
set $pass_access_scheme $scheme;
set $pass_server_port $server_port;
set $best_http_host $http_host;
set $pass_port $pass_server_port;
location / {
set $namespace "";
set $ingress_name "";
set $service_name "";
set $service_port "0";
set $location_path "/";
...
- lint
这个命令可以帮助我们检查ingress规范的版本不兼容的地方,尤其在升级版本之前检查下,非常有用:非常有用
$ kubectl ingress-nginx lint --all-namespaces --verbose
Checking ingresses...
? anamespace/this-nginx
- Contains the removed session-cookie-hash annotation.
Lint added for version 0.24.0
https://github.com/kubernetes/ingress-nginx/issues/3743
? othernamespace/ingress-definition-blah
- The rewrite-target annotation value does not reference a capture group
Lint added for version 0.22.0
https://github.com/kubernetes/ingress-nginx/issues/3174
Checking deployments...
? namespace2/nginx-ingress-controller
- Uses removed config flag --sort-backends
Lint added for version 0.22.0
https://github.com/kubernetes/ingress-nginx/issues/3655
- Uses removed config flag --enable-dynamic-certificates
Lint added for version 0.24.0
https://github.com/kubernetes/ingress-nginx/issues/3808
还有几点要注意的地方:
- 命名空间的指定一定要放在ingress-nginx插件命令之后,否则kubectl识别会有误
- 如果ingress controller的deployment不是叫“ingress-nginx-controller”,就需要手动指定名称
猜你喜欢
- 2024-10-11 如何使用Nginx对Artifactory进行http应用
- 2024-10-11 IntelliJ IDEA必装插件以及SpringBoot使用小技巧合集
- 2024-10-11 WeCube 2.8.0 发布,一站式IT架构管理和运维工具
- 2024-10-11 Kong系列(三)——Kong插件「IP Restriction」使用
- 2024-10-11 docker开箱即用的java版本nginx-clojure实现负载均衡
- 2024-10-11 RTMP和RTSP的区别(rtp rtmp区别)
- 2024-10-11 「开源资讯」njs 0.4.1 发布,nginx 的 JavaScript 脚本语言
- 2024-10-11 Nginx如何支持OpenTracing - Jaeger
- 2024-09-22 免费又好用的缓存插件,非Speed Optimizer莫属
- 2024-09-22 web中间件nginx性能分析与调优(nginx中间件怎么看版本号?)
你 发表评论:
欢迎- 最近发表
-
- Win10 TH2正式版官方ESD映像转换ISO镜像方法详解
- 使用iso镜像升级到Windows 10的步骤
- macOS Ventura 13.2 (22D49) Boot ISO 原版可引导镜像
- 安利一个用ISO镜像文件制作引导U盘的的小工具RUFUS
- CentOS 7使用ISO镜像配置本地yum源
- 用于x86平台的安卓9.0 ISO镜像发布下载:通吃I/A/N、完全免费
- AlmaLinux 9.6发布:升级工具、初步支持IBM Power虚拟化技术
- Rufus写入工具简洁介绍与教程(写入模式)
- 新硬件也能安装使用了,Edge版Linux Mint 21.3镜像发布
- 开源工程师:Ubuntu应该抛弃32位ISO镜像
- 标签列表
-
- 下划线是什么 (87)
- 精美网站 (58)
- qq登录界面 (90)
- nginx 命令 (82)
- nginx .http (73)
- nginx lua (70)
- nginx 重定向 (68)
- Nginx超时 (65)
- nginx 监控 (57)
- odbc (59)
- rar密码破解工具 (62)
- annotation (71)
- 红黑树 (57)
- 智力题 (62)
- php空间申请 (61)
- 按键精灵 注册码 (69)
- 软件测试报告 (59)
- ntcreatefile (64)
- 闪动文字 (56)
- guid (66)
- abap (63)
- mpeg 2 (65)
- column (63)
- dreamweaver教程 (57)
- excel行列转换 (56)
本文暂时没有评论,来添加一个吧(●'◡'●)