美文网首页Docker&Kubernetes
简单Kubernetes的Minikube安装

简单Kubernetes的Minikube安装

作者: 己乙孔 | 来源:发表于2018-07-22 17:15 被阅读470次

基础环境

  • 操作系统版本:CentOS Linux release 7.3.1611
  • Minikube版本:v0.28.1
  • kubectl版本:v1.11.1

安装kubectl

官方镜像

  • 拉取官方的都需要科学上网
$ cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOF
$ yum install -y kubectl

阿里云镜像

$ cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
$ yum install -y kubectl

安装Minikube

Minikube可以方便的在本地运行Kubernetes集群,方便日常开发,需要安装虚拟机。

安装virtualbox虚拟机

# 安装编译工具
$ yum install -y gcc kernel-devel

# 使用yum安装virtualbox
$ cat <<EOF > /etc/yum.repos.d/virtualbox.repo
[virtualbox]
name=Oracle Linux / RHEL / CentOS-\$releasever / \$basearch - VirtualBox
baseurl=http://download.virtualbox.org/virtualbox/rpm/el/\$releasever/\$basearch
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://www.virtualbox.org/download/oracle_vbox.asc
EOF
$ yum install -y VirtualBox-5.2

# 设置virtualbox
$ sudo /sbin/vboxconfig

获取Minikube

有两种方式,都是官方源。

直接获取安装

  • 该方法需要科学上网
$ curl -Lo minikube https://storage.googleapis.com/minikube/releases/v0.28.1/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/

从GitHub下载

$ mv minikube-linux-amd64 minikube && chmod +x minikube && mv minikube /usr/local/bin/

测试Minikube是否可用

# 使用代理访问gcr.io,proxy填写代理地址
$ minikube start --bootstrapper localkube --docker-env="http_proxy=http://192.168.186.200:8118" --docker-env="https_proxy=http://192.168.186.200:8118"
Starting local Kubernetes v1.10.0 cluster...
Starting VM...
Downloading Minikube ISO
 160.27 MB / 160.27 MB [============================================] 100.00% 0s
Getting VM IP address...
WARNING: The localkube bootstrapper is now deprecated and support for it
will be removed in a future release. Please consider switching to the kubeadm bootstrapper, which
is intended to replace the localkube bootstrapper. To disable this message, run
[minikube config set ShowBootstrapperDeprecationNotification false]
Moving files into cluster...
Downloading localkube binary
 173.54 MB / 173.54 MB [============================================] 100.00% 0s
 0 B / 65 B [----------------------------------------------------------] 0.00%
 65 B / 65 B [======================================================] 100.00% 0sSetting up certs...
Connecting to cluster...
Setting up kubeconfig...
Starting cluster components...
Kubectl is now configured to use the cluster.
Loading cached images from config file.

$ kubectl run hello-minikube --image=k8s.gcr.io/echoserver:1.4 --port=8080
deployment.apps/hello-minikube created

$ kubectl expose deployment hello-minikube --type=NodePort
service/hello-minikube exposed

$ kubectl get pod
NAME                           READY    STATUS             RESTARTS  AGE
hello-minikube-6c47c66d8-rxtfz 0/1      ContainerCreating  0         1m

$ kubectl get pod
NAME                           READY    STATUS             RESTARTS  AGE
hello-minikube-6c47c66d8-rxtfz 1/1      Running            0         5m

$ curl $(minikube service hello-minikube --url)

$ kubectl delete service hello-minikube
service "hello-minikube" deleted

$ kubectl delete deployment hello-minikube
deployment.extensions "hello-minikube" deleted

$ minikube stop
Stopping local Kubernetes cluster...
Machine stopped.

相关文章

网友评论

    本文标题:简单Kubernetes的Minikube安装

    本文链接:https://www.haomeiwen.com/subject/ajxrmftx.html