您现在的位置是:首页 > 文章详情

【从入门到放弃-Kubernetes】Kubernetes入门

日期:2020-04-14点击:472

前言

云原生势不可挡,了解云原生肯定绕不开Kubernetes,这里不对云原生、Kubernetes概念做过多描述,直接开干,在本地搭建Kubernetes环境并了解基础操作。

参考文档:

操作环境:

  • macOS 10.15.3

约定:

  • 后续文章中统一使用Kubernetes的简称:k8s

kubectl

kubectl是k8s集群的命令行管理工具,可以使用kubectl对k8s集群进行管理、进行容器化应用的安装部署等。

安装

brew install kubectl

mac下直接使用brew进行安装,其它环境或安装方式可见官方安装文档

使用

kubectl -h

使用-h参数列出支持命令,有以下输出说明已安装成功

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 使用 replication controller, service, deployment 或者 pod 并暴露它作为一个 新的 Kubernetes Service run 在集群中运行一个指定的镜像 set 为 objects 设置一个指定的特征 Basic Commands (Intermediate): explain 查看资源的文档 get 显示一个或更多 resources edit 在服务器上编辑一个资源 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 or Replication Controller autoscale 自动调整一个 Deployment, ReplicaSet, 或者 ReplicationController 的副本数量 Cluster Management Commands: certificate 修改 certificate 资源. cluster-info 显示集群信息 top Display Resource (CPU/Memory/Storage) usage. cordon 标记 node 为 unschedulable uncordon 标记 node 为 schedulable drain Drain node in preparation for maintenance taint 更新一个或者多个 node 上的 taints Troubleshooting and Debugging Commands: describe 显示一个指定 resource 或者 group 的 resources 详情 logs 输出容器在 pod 中的日志 attach Attach 到一个运行中的 container exec 在一个 container 中执行一个命令 port-forward Forward one or more local ports to a pod proxy 运行一个 proxy 到 Kubernetes API server cp 复制 files 和 directories 到 containers 和从容器中复制 files 和 directories. auth Inspect authorization Advanced Commands: diff Diff live version against would-be applied version apply 通过文件名或标准输入流(stdin)对资源进行配置 patch 使用 strategic merge patch 更新一个资源的 field(s) replace 通过 filename 或者 stdin替换一个资源 wait Experimental: Wait for a specific condition on one or many resources. convert 在不同的 API versions 转换配置文件 kustomize Build a kustomization target from a directory or a remote url. Settings Commands: label 更新在这个资源上的 labels annotate 更新一个资源的注解 completion Output shell completion code for the specified shell (bash or zsh) Other Commands: 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 输出 client 和 server 的版本信息 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).

命令的使用方式,在后续使用时会具体介绍。

Minikube

准备

先执行以下命令检查你的系统是否支持虚拟化。

sysctl -a | grep -E --color 'machdep.cpu.features|VMX'

如果看到输出中有 VMX 则说明支持。

安装

brew install minikube

直接使用brew安装,其它环境或安装方式可见官方安装文档

使用

启动

minikube start --driver=docker

--driver 参数可以指定minikube的启动方式,有:virtualbox、hyperkit、docker、vmware等。
参考文档

这里我们选择docker的方式

然后就是漫长的等待。。。

启动完成

查看状态

使用status检查集群状态

minikube status

出现下列输出,说明集群启动正常

m01 host: Running kubelet: Running apiserver: Running kubeconfig: Configured

关闭

minikube stop

关闭后再运行

minikube status

输出

m01 host: Stopped kubelet: Stopped apiserver: Stopped kubeconfig: Stopped

dashboard

dashboard是k8s提供的一个web操作控制台,可以查看集群运行情况并进行管理。

minikube dashboard

执行后,会自动在默认浏览器中打开 http://127.0.0.1:50281/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/#/overview?namespace=default

总结

至此,一个使用Minikube搭建的k8s集群就已经ready了。下文中,我们将继续学习如何在集群中部署一个简单的应用。

其实可以看到,最基础的入门操作是比较简单的,官方文档也十分详细,只要跟着操作一遍,基本就能了解。

之前尝试过几次k8s的入门学习,都止步于基础概念,看了忘、忘了看,却没有真正的操作一遍。从实践入手,是亘古不变的学习法门,一定不能手懒。

更多文章

见我的博客:https://nc2era.com

written by AloofJr,转载请注明出处

原文链接:https://yq.aliyun.com/articles/755407
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章