首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >Centos7 使用Minikube安装kubernetes

Centos7 使用Minikube安装kubernetes

作者头像
Linux运维技术之路
发布2022-06-07 08:42:16
发布2022-06-07 08:42:16
1.6K0
举报

一、 初始化

代码语言:javascript
复制
systemctl stop firewalld && systemctl disable firewalld
swapoff -a
setenforce 0
cat <<EOF >  /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
setenforce 0

二、下载安装 minikube

  • 1、下载minikube (建议使用阿里云镜像,国外镜像太慢了)
代码语言:javascript
复制
curl -Lo minikube http://kubernetes.oss-cn-hangzhou.aliyuncs.com/minikube/releases/v1.3.1/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/

或者手动获取代码了

代码语言:javascript
复制
git clone https://github.com/AliyunContainerService/minikube
cd minikube
git checkout aliyun-v1.3.1
make
sudo cp out/minikube /usr/local/bin/
  • 2、帮助文档
代码语言:javascript
复制
[root@xuxingyue-test-01 ~]# minikube --help
Minikube is a CLI tool that provisions and manages single-node Kubernetes clusters optimized for development workflows.

Basic Commands:
  start          Starts a local kubernetes cluster
  status         Gets the status of a local kubernetes cluster
  stop           Stops a running local kubernetes cluster
  delete         Deletes a local kubernetes cluster
  dashboard      Access the kubernetes dashboard running within the minikube cluster

Images Commands:
  docker-env     Sets up docker env variables; similar to '$(docker-machine env)'
  cache          Add or delete an image from the local cache.

Configuration and Management Commands:
  addons         Modify minikube's kubernetes addons
  config         Modify minikube config
  profile        Profile gets or sets the current minikube profile
  update-context Verify the IP address of the running cluster in kubeconfig.

Networking and Connectivity Commands:
  service        Gets the kubernetes URL(s) for the specified service in your local cluster
  tunnel         tunnel makes services of type LoadBalancer accessible on localhost

Advanced Commands:
  mount          Mounts the specified directory into minikube
  ssh            Log into or run a command on a machine with SSH; similar to 'docker-machine ssh'
  kubectl        Run kubectl

Troubleshooting Commands:
  ssh-key        Retrieve the ssh identity key path of the specified cluster
  ip             Retrieves the IP address of the running cluster
  logs           Gets the logs of the running instance, used for debugging minikube, not user code.
  update-check   Print current and latest version number
  version        Print the version of minikube

Other Commands:
  completion     Outputs minikube shell completion for the given shell (bash or zsh)

Use "minikube <command> --help" for more information about a given command.
  • 正式安装 安装有2种方式,一、是提前安装VirtualBox,二、添加一个"--vm-driver=none",目前这里安装采用第二种
代码语言:javascript
复制
[root@test-01 ~]# minikube start --vm-driver=none --registry-mirror=https://docker.mirrors.ustc.edu.cn
* minikube v1.3.1 on Centos 7.6.1810
* Using image repository registry.cn-hangzhou.aliyuncs.com/google_containers
* Running on localhost (CPUs=4, Memory=3789MB, Disk=25587MB) ...
* OS release is CentOS Linux 7 (Core)
* Preparing Kubernetes v1.15.2 on Docker 19.03.0 ...
* Downloading kubeadm v1.15.2
* Downloading kubelet v1.15.2
* 拉取镜像 ...
* 正在启动 Kubernetes ...
* Configuring local host environment ...
*
! The 'none' driver provides limited isolation and may reduce system security and reliability.
! For more information, see:
  - https://minikube.sigs.k8s.io/docs/reference/drivers/none/
*
! 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

三、测试容器案例并访问

  • 1、启动一个容器
代码语言:javascript
复制
[root@test-01 ~]# kubectl run kube-nginx --image=nginx:latest --port=80
kubectl run --generator=deployment/apps.v1 is DEPRECATED and will be removed in a future version. Use kubectl run --generator=run-pod/v1 or kubectl create instead.
修改为如下命令
[root@test-01 ~]# kubectl run --generator=run-pod/v1   kube-nginx --image=nginx:latest --port=80
pod/kube-nginx created
  • 2、查看状态
代码语言:javascript
复制
[root@test-01 ~]# kubectl  get pods
NAME                          READY   STATUS    RESTARTS   AGE
kube-nginx-7c765ffd95-rszh4   1/1     Running   0          20m
  • 3、查看集群信息
代码语言:javascript
复制
[root@test-01 ~]#  kubectl cluster-info
Kubernetes master is running at https://10.10.40.5:8443
KubeDNS is running at https://10.10.40.5:8443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
  • 4、查看启动日志
代码语言:javascript
复制
[root@test-01 ~]# minikube logs
* ==> Docker <==
* -- Logs begin at 四 2019-08-29 11:28:07 CST, end at 四 2019-08-29 15:10:53 CST. --
* 8月 29 13:43:19 test-01 dockerd[19819]: time="2019-08-29T13:43:19.670690663+08:00" level=info msg="Attempting next endpoint for pull after error: Get https://k8s.gcr.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)"
* 8月 29 13:43:19 test-01 dockerd[19819]: time="2019-08-29T13:43:19.670742179+08:00" level=error msg="Handler for POST /v1.40/images/create returned error: Get https://k8s.gcr.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)"
  • 5、重新启动服务
代码语言:javascript
复制
[root@test-01 ~]# kubectl run kube-nginx --image=nginx:latest --port=80 --image-pull-policy=IfNotPresent
kubectl run --generator=deployment/apps.v1 is DEPRECATED and will be removed in a future version. Use kubectl run --generator=run-pod/v1 or kubectl create instead.
Error from server (AlreadyExists): deployments.apps "kube-nginx" already exists
  • 6、发布服务
代码语言:javascript
复制
[root@test-01 ~]# kubectl expose deployment kube-nginx --type=NodePort
service/kube-nginx exposed
  • 7、取得deployments列表
代码语言:javascript
复制
[root@test-01 ~]# kubectl get deployment
NAME         READY   UP-TO-DATE   AVAILABLE   AGE
kube-nginx   1/1     1            1           13m
  • 8、查看服务地址
代码语言:javascript
复制
[root@test-01 ~]#  minikube service kube-nginx --url
* http://10.10.40.5:30017
  • 9、访问地址:http://10.10.40.5:30017

四、minikube 安装dashboard

dashboard管理后台是kubernetes提供的容器管理后台,可以用来进行机器负载,集群管理,镜像扩展,配置参数等相关操作

  • 1、直接通过minikube dashboard
代码语言:javascript
复制
[root@xuxingyue-test-01 ~]# minikube dashboard --url
* Verifying dashboard health ...
* Launching proxy ...
* Verifying proxy health ...
http://127.0.0.1:5154/api/v1/namespaces/kube-system/services/http:kubernetes-dashboard:/proxy/
  • 2、命令安装dashboard
代码语言:javascript
复制
[root@test-01 ~]# kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0-beta1/aio/deploy/recommended.yaml
namespace/kubernetes-dashboard created
serviceaccount/kubernetes-dashboard created
service/kubernetes-dashboard created
secret/kubernetes-dashboard-certs created
secret/kubernetes-dashboard-csrf created
secret/kubernetes-dashboard-key-holder created
configmap/kubernetes-dashboard-settings created
role.rbac.authorization.k8s.io/kubernetes-dashboard created
clusterrole.rbac.authorization.k8s.io/kubernetes-dashboard created
rolebinding.rbac.authorization.k8s.io/kubernetes-dashboard created
clusterrolebinding.rbac.authorization.k8s.io/kubernetes-dashboard created
deployment.apps/kubernetes-dashboard created
service/dashboard-metrics-scraper created
deployment.apps/kubernetes-metrics-scraper created
代码语言:javascript
复制
[root@test-01 ~]# kubectl proxy --address='0.0.0.0' --accept-hosts='^*$'
Starting to serve on [::]:8001
  • 3、访问URL :http://10.10.40.5:8001/api/v1/namespaces/kube-system/services/http:kubernetes-dashboard:/proxy/
本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2019-08-31,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 Linux运维技术之路 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 一、 初始化
  • 二、下载安装 minikube
  • 三、测试容器案例并访问
  • 四、minikube 安装dashboard
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档