Home | 简体中文 | 繁体中文 | 杂文 | Github | 知乎专栏 | Facebook | Linkedin | Youtube | 打赏(Donations) | About
知乎专栏

第 108 章 Kubernetes 集群管理

kubectl - controls the Kubernetes cluster manager.

目录

108.1. 配置
108.1.1. KUBECONFIG
108.1.2. use-context
108.2. 如何从 docker 过渡到 kubectl 命令
108.2.1. 执行 Shell
108.2.2. 查看信息
108.2.3. 查看 pod 日志
108.2.4. 复制文件
108.2.5. edit
108.2.6. 端口转发
108.2.7. 操作系统资源配置
108.2.8. endpoints
108.2.9. explain
108.2.10. describe
108.3. namespace 命名空间
108.3.1. 查看命名空间
108.3.2. 创建命名空间
108.3.3. 使用 yaml 创建命名空间
108.3.4. 删除命名空间
108.4. label 标签
108.5. 服务管理
108.5.1. 列出服务
108.5.2. 创建服务
108.5.3. 查看服务详细信息
108.5.4. 更新服务
108.5.5. 删除服务
108.5.6. clusterip
108.5.7. 设置外部IP
108.5.8. externalname
108.5.9. 负载均衡
108.5.10. nodeport
108.5.11. Example
108.6. serviceaccount
108.7. Pod 管理
108.7.1. 查看 POD 状态
108.7.2. 运行 POD
108.7.3. 删除 pod
108.7.4. 查看 Pod 的事件
108.7.5. Taint(污点)和 Toleration(容忍)
108.7.6. 镜像拉取策略
108.7.7. 指定主机名
108.7.8. 环境变量
108.7.9. 健康状态检查
108.7.10. securityContext
108.7.11. nodeName 选择节点
108.7.12. nodeSelector 选择节点
108.7.13. nodeAffinity 选择节点
108.7.14. Taint(污点)和 Toleration(容忍)
108.7.15. strategy
108.8. 部署管理
108.8.1. expose
108.8.2. 部署容器
108.8.3. 删除 deployment
108.8.4. 扩容管理
108.8.5. rollout
108.8.6. 重启容器
108.8.7. 更新镜像
108.9. secret 密钥管理
108.9.1. 获取 Token
108.9.2. 创建 Secret
108.9.3. Private Registry 用户认证
108.9.4. 配置TLS SSL
108.10. ConfigMap
108.10.1. 创建 Key-Value 配置项
108.10.2. 从文件创建 ConfigMap
108.10.3. 从环境变量文件创建 ConfigMap
108.10.4. 查看 ConfigMap
108.10.5. 删除 ConfigMap
108.10.6. ConfigMap
108.11. Job/CronJob
108.11.1. CronJob
108.11.2. Job
108.12. clusterrolebinding
108.13. Volume
108.13.1. local
108.14. Ingress
108.14.1. 管理 Ingress
108.14.2. 挂载 SSL 证书上
108.14.3. 端口
108.14.4. URI 规则
108.14.5. vhost 虚拟主机
108.14.6. rewrite
108.14.7. annotations 配置
108.14.8. 金丝雀发布(灰度发布)
108.14.9. 解决 504 网关超时

kubectl是Kubernetes的命令行管理工具

	
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 Service
  run            Run a particular image on the cluster
  set            Set specific features on objects

Basic Commands (Intermediate):
  explain        Documentation of resources
  get            Display one or many resources
  edit           Edit a resource on the server
  delete         Delete resources by filenames, stdin, resources and names, or by resources and label selector

Deploy Commands:
  rollout        Manage the rollout of a resource
  scale          Set a new size for a Deployment, ReplicaSet, Replication Controller, or Job
  autoscale      Auto-scale a Deployment, ReplicaSet, or ReplicationController

Cluster Management Commands:
  certificate    Modify certificate resources.
  cluster-info   Display cluster info
  top            Display Resource (CPU/Memory/Storage) usage.
  cordon         Mark node as unschedulable
  uncordon       Mark node as schedulable
  drain          Drain node in preparation for maintenance
  taint          Update the taints on one or more nodes

Troubleshooting and Debugging Commands:
  describe       Show details of a specific resource or group of resources
  logs           Print the logs for a container in a pod
  attach         Attach to a running container
  exec           Execute a command in a container
  port-forward   Forward one or more local ports to a pod
  proxy          Run a proxy to the Kubernetes API server
  cp             Copy files and directories to and from containers.
  auth           Inspect authorization

Advanced Commands:
  diff           Diff live version against would-be applied version
  apply          Apply a configuration to a resource by filename or stdin
  patch          Update field(s) of a resource using strategic merge patch
  replace        Replace a resource by filename or stdin
  wait           Experimental: Wait for a specific condition on one or many resources.
  convert        Convert config files between different API versions

Settings Commands:
  label          Update the labels on a resource
  annotate       Update the annotations on a resource
  completion     Output shell completion code for the specified shell (bash or zsh)

Other Commands:
  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         Modify kubeconfig files
  plugin         Provides utilities for interacting with plugins.
  version        Print the client and server version information

Usage:
  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).	
	
	

108.1. 配置

108.1.1. KUBECONFIG

KUBECONFIG 环境变量

108.1.2. use-context

			
[root@netkiller ~]# kubectl config view
apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: DATA+OMITTED
    server: https://127.0.0.1:6445
  name: k3d-mycluster
contexts:
- context:
    cluster: k3d-mycluster
    user: admin@k3d-mycluster
  name: k3d-mycluster
current-context: k3d-mycluster
kind: Config
preferences: {}
users:
- name: admin@k3d-mycluster
  user:
    client-certificate-data: REDACTED
    client-key-data: REDACTED			
			
			
			
$ kubectl config use-context