Minikube 初体验
in Tutorial with 0 comment
Minikube 初体验
in Tutorial with 0 comment

安装

先安装 virtualbox

参考 https://tecadmin.net/install-oracle-virtualbox-on-centos-redhat-and-fedora/

安装kubectl

proxychains4 curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/v1.9.0/bin/linux/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/

安装minikube

proxychains4 curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/

使用docker代理

这个是国内环境必备的修改,否则没法正常使用,这里适应阿里云代理

这是本文的精华

vim ~/.minikube/machines/minikube/config.json

找到 RegistryMirror 字段,修改为

"RegistryMirror": [
                "https://ny0lp769.mirror.aliyuncs.com"
            ]

开始使用

启动

@gz-open-c27 ➜ k8s  minikube start
Starting local Kubernetes v1.9.0 cluster...
Starting VM...
Getting VM IP address...
Moving files into cluster...
Setting 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.

跑一个 Nginx 任务

不要使用gcr.io的镜像,会被墙

@gz-open-c27 ➜ k8s  kubectl run hello-world --image=nginx:stable --port=80
Error from server (AlreadyExists): deployments.extensions "hello-world" already exists
@gz-open-c27 ➜ k8s  kubectl get pods
NAME                          READY     STATUS    RESTARTS   AGE
hello-world-9d5f9b677-79brg   1/1       Running   2          12m
@gz-open-c27 ➜ k8s  kubectl get services
NAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
kubernetes   ClusterIP   10.96.0.1    <none>        443/TCP   1h
@gz-open-c27 ➜ k8s  kubectl expose deployment hello-world --type=NodePort
service "hello-world" exposed
@gz-open-c27 ➜ k8s  kubectl get services
NAME          TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)        AGE
hello-world   NodePort    10.109.96.10   <none>        80:31465/TCP   0s
kubernetes    ClusterIP   10.96.0.1      <none>        443/TCP        1h
@gz-open-c27 ➜ k8s  curl $(minikube service hello-world --url)
<!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 href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

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

使用dashboard

@gz-open-c27 ➜ k8s  minikube dashboard --url
http://192.168.99.100:30000

远程打开

ssh -N -f -L 30000:192.168.99.100:30000 172.25.52.27

这样就能在自己的电脑打开 http://localhost:30000/

1521607738018-wx20180321-124841-resized.png

Responses