Home | 简体中文 | 繁体中文 | 杂文 | Github | 知乎专栏 | 51CTO学院 | CSDN程序员研修院 | OSChina 博客 | 腾讯云社区 | 阿里云栖社区 | Facebook | Linkedin | Youtube | 打赏(Donations) | About
知乎专栏多维度架构

第 6 章 Kubernetes 集群管理

kubectl - controls the Kubernetes cluster manager.

目录

6.1. 配置
6.1.1. KUBECONFIG
6.1.2. use-context
6.2. 如何从 docker 过渡到 kubectl 命令
6.2.1. 执行 Shell
6.2.2. 查看信息
6.2.3. 查看 pod 日志
6.2.4. 复制文件
6.2.5. edit
6.2.6. 端口转发
6.2.7. 操作系统资源配置
6.2.8. endpoints
6.2.9. explain
6.2.10. describe
6.3. namespace 命名空间
6.3.1. 查看命名空间
6.3.2. 创建命名空间
6.3.3. 使用 yaml 创建命名空间
6.3.4. 删除命名空间
6.4. label 标签
6.5. 服务管理
6.5.1. 列出服务
6.5.2. 创建服务
6.5.3. 查看服务详细信息
6.5.4. 更新服务
6.5.5. 删除服务
6.5.6. clusterip
6.5.7. 设置外部IP
6.5.8. externalname
6.5.9. 负载均衡
6.5.10. nodeport
6.5.11. Example
6.6. serviceaccount
6.7. Pod 管理
6.7.1. 查看 POD 状态
6.7.2. 运行 POD
6.7.3. 删除 pod
6.7.4. 查看 Pod 的事件
6.7.5. Taint(污点)和 Toleration(容忍)
6.7.6. 镜像拉取策略
6.7.7. 指定主机名
6.7.8. 环境变量
6.7.9. 健康状态检查
6.7.10. securityContext
6.7.11. nodeName 选择节点
6.7.12. nodeSelector 选择节点
6.7.13. nodeAffinity 选择节点
6.7.14. Taint(污点)和 Toleration(容忍)
6.7.15. strategy
6.8. 部署管理
6.8.1. expose
6.8.2. 部署容器
6.8.3. 删除 deployment
6.8.4. 扩容管理
6.8.5. rollout
6.8.6. 重启容器
6.8.7. 更新镜像
6.9. secret 密钥管理
6.9.1. 获取 Token
6.9.2. 创建 Secret
6.9.3. Private Registry 用户认证
6.9.4. 配置TLS SSL
6.10. ConfigMap
6.10.1. 创建 Key-Value 配置项
6.10.2. 从文件创建 ConfigMap
6.10.3. 从环境变量文件创建 ConfigMap
6.10.4. 查看 ConfigMap
6.10.5. 删除 ConfigMap
6.10.6. ConfigMap
6.11. Job/CronJob
6.11.1. CronJob
6.11.2. Job
6.12. clusterrolebinding
6.13. Volume
6.13.1. local
6.14. Ingress
6.14.1. 管理 Ingress
6.14.2. 挂载 SSL 证书上
6.14.3. 端口
6.14.4. URI 规则
6.14.5. vhost 虚拟主机
6.14.6. rewrite
6.14.7. annotations 配置
6.14.8. 金丝雀发布(灰度发布)
6.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).	
	
	

6.1. 配置

6.1.1. KUBECONFIG

KUBECONFIG 环境变量

6.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