Minikube-Kubernetes本地实验环境

IT
IT
IT
335
文章
1
评论
2020年7月4日19:54:07 评论 4,766 4626字阅读15分25秒

简述

Kubernetes 集群的搭建是有一定难度的,尤其是对于初学者来说,好多概念和原理不懂,即使有现成的教程也会出现很多不可预知的问题,很容易打击学习的积极性,就此弃坑。好在 Kubernetes 社区提供了可以在本地开发和体验的极简集群安装 MiniKube,对于入门学习来说很方便。Minikube-Kubernetes本地实验环境

 

MiniKube 官方安装介绍已经非常详细了,可以参考 installation。但是在国内由于网络访问原因(懂的),即使有梯子也很折腾,所以记录一下阿里修改后的 MiniKube 安装。使用阿里修改后的 MiniKube 就可以从阿里云的镜像地址来获取所需 Docker 镜像和配置,其它的并没有差异,下文着重介绍。

初始化

[root@gitlab ~]# yum install -y git
[root@gitlab ~]# git clone https://github.com/cncentoscn/Centos7
[root@gitlab ~]# cd Centos7/
[root@gitlab Centos7]# ll
总用量 20
-rw-r--r--. 1 root root 4745 7月 6 10:36 basis.sh
-rw-r--r--. 1 root root 2040 7月 6 10:36 detection.sh
-rw-r--r--. 1 root root 2452 7月 6 10:36 docker.sh
-rw-r--r--. 1 root root 10 7月 6 10:36 README.md
[root@gitlab Centos7]# sh basis.sh 
[root@gitlab Centos7]# sh docker.sh 

一、kubectl 安装

MiniKube 的安装需要先安装 kubectl 及相关驱动,这没什么好说的,参考官方介绍

[root@gitlab ~]# curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl
[root@gitlab ~]# chmod +x ./kubectl
[root@gitlab ~]# sudo mv ./kubectl /usr/local/bin/kubectl
[root@gitlab ~]# kubectl version --client
Client Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.5", GitCommit:"e6503f8d8f769ace2f338794c914a96fc335df0f", GitTreeState:"clean", BuildDate:"2020-06-26T03:47:41Z", GoVersion:"go1.13.9", Compiler:"gc", Platform:"linux/amd64"}

MiniKube 安装

  • 要检查Linux是否支持虚拟化,请运行以下命令并验证输出是否为非空
[root@gitlab ~]# grep -E --color 'vmx|svm' /proc/cpuinfo
flags       : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx rdtscp lm constant_tsc arch_perfmon nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq vmx ssse3 fma cx16 pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid mpx rdseed adx smap clflushopt xsaveopt xsavec dtherm arat pln pts
flags       : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx rdtscp lm constant_tsc arch_perfmon nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq vmx ssse3 fma cx16 pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid mpx rdseed adx smap clflushopt xsaveopt xsavec dtherm arat pln pts
  • 直接下载安装Minikube

[root@gitlab ~]# curl -Lo minikube http://kubernetes.oss-cn-hangzhou.aliyuncs.com/minikube/releases/v1.2.0/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/

启动minikube

  • 剩下就是启动了,启动过程中会下载kubeadm、kubelet和启动过程下载的东西
[root@gitlab ~]# minikube start --vm-driver=none --registry-mirror=https://registry.docker-cn.com
😄  minikube v1.2.0 on linux (amd64)
✅  using image repository registry.cn-hangzhou.aliyuncs.com/google_containers
🔥  Creating none VM (CPUs=2, Memory=2048MB, Disk=20000MB) ...
🐳  Configuring environment for Kubernetes v1.15.0 on Docker 19.03.12
💾  Downloading kubeadm v1.15.0
💾  Downloading kubelet v1.15.0
🚜  Pulling images ...
🚀  Launching Kubernetes ... 
🤹  Configuring local host environment ...

⚠️  The 'none' driver provides limited isolation and may reduce system security and reliability.
⚠️  For more information, see:
👉  https://github.com/kubernetes/minikube/blob/master/docs/vmdriver-none.md

⚠️  kubectl and minikube configuration will be stored in /root
⚠️  To use kubectl or minikube commands as your own user, you may
⚠️  need to relocate them. For example, to overwrite your own settings:

    ▪ sudo mv /root/.kube /root/.minikube $HOME
    ▪ sudo chown -R $USER $HOME/.kube $HOME/.minikube

💡  This can also be done automatically by setting the env var CHANGE_MINIKUBE_NONE_USER=true
⌛  Verifying: apiserver proxy etcd
 scheduler controller dns
🏄  Done! kubectl is now configured to use "minikube"
  • 检查服务是否正常
[root@gitlab ~]#  kubectl get cs
NAME                 AGE
scheduler            <unknown>
controller-manager   <unknown>
etcd-0               <unknown>
[root@gitlab ~]# kubectl get node
NAME       STATUS   ROLES    AGE   VERSION
minikube   Ready    <none>   19m   v1.15.0
  • 检查是否能用
[root@gitlab ~]# kubectl create deployment nginx --image=nginx
[root@gitlab ~]#  kubectl expose deployment nginx --port=80 --type=NodePort
[root@gitlab ~]# kubectl get pod,svc
NAME                         READY   STATUS             RESTARTS   AGE
pod/nginx-554b9c67f9-7r54g   1/1     Running            0          102s
NAME                 TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)        AGE
service/kubernetes   ClusterIP   10.96.0.1      <none>        443/TCP        17m
service/nginx        NodePort    10.110.82.66   <none>        80:31754/TCP   94s
  • 测试
[root@gitlab ~]# curl http://192.168.31.36:31754/
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a rel="external nofollow" target="_blank" href="https://www.centoscn.vip/wp-content/themes/begin/go.php?url=aHR0cDovL25naW54Lm9yZy8=">nginx.org</a>.<br/>
Commercial support is available at
<a rel="external nofollow" target="_blank" href="https://www.centoscn.vip/wp-content/themes/begin/go.php?url=aHR0cDovL25naW54LmNvbS8=">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

 

下载信息 二进制文件
网盘密码:登录可见
下载地址
继续阅读
  • 我的QQ
  • QQ扫一扫
  • weinxin
  • 我的头条
  • 头条扫一扫
  • weinxin
IT
  • 本文由 发表于 2020年7月4日19:54:07
  • 除非特殊声明,本站文章均为原创,转载请务必保留本文链接
Pod Kubernetes

Pod

Pod基本概念 Pod存在的意义 Pod实现机制与设计模式 Pod镜像拉取策略
资源编排【YMAL】 Kubernetes

资源编排【YMAL】

YAML 基础 它的基本语法规则如下: 大小写敏感 使用缩进表示层级关系 缩进时不允许使用Tab键,只允许使用空格。 缩进的空格数目不重要,只要相同层级的元素左侧对齐即可 # 表示注释,从这个字符一直...
部署CoreDNS Kubernetes

部署CoreDNS

CoreDNS用于集群内部Service名称解析 下载配置文件 coredns.yaml 创建dns # kubectl apply -f coredns.yaml 查看pod # kubectl g...