基础环境:
Virtual box
OS: Ubuntu:16.04
enp0s3:(Hostonly)192.168.56.102(提供pc端访问服务器-hostonly)
enp0s8:(NAT)10.0.3.15(访问外网,因为nat映射端原因,本地pc无法访问)
minikube使用的all-in-one方式,所以就放在了一台vm上,配置最好大一点,不然会卡!
---------------------------------------------------------------------------------
离线安装包和镜像
链接:https://pan.baidu.com/s/10oqK80w5SJD2npOYpLZEkg 密码:u95p
1、安装docker-ce环境(引用官网)
https://docs.docker.com/install/linux/docker-ce/ubuntu/#install-docker-ce-1
sudo apt-get update
Install packages to allow apt to use arepository over HTTPS:
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl\
software-properties-common
Add Docker's official GPG key:
curl -fsSLhttps://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
Verify that you now have the key with thefingerprint 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88, by searching forthe last 8 characters of the fingerprint.
sudo apt-key fingerprint 0EBFCD88
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
Install Docker CE,Update the apt package index.
sudo apt-get update
Install the latest version of Docker CE, or goto the next step to install a specific version:
sudo apt-get install docker-ce
sudo systemctl enable docker
sudo systemctl start docker
2、需要下载minikube、kubectl(参考官网github)
https://github.com/kubernetes/minikube
下载命令:(由于防火墙端缘故,无法下载,在国外服务器拉取下来,本地离线安装)
curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64&& chmod +x minikube
curl -Lo kubectlhttps://storage.googleapis.com/kubernetes-release/release/$(curl -shttps://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl&& chmod +x kubectl
离线安装操作:
cd /root
chmod +x minikube
mv minikube /usr/local/bin/
ln -sf /usr/local/bin/minikube/usr/bin/minikube
cd /root
chmod +x kubectl
mv kubectl /usr/local/bin
ln -sf /usr/local/bin/kubectl /usr/bin/kubectl
3、初始化环境变量:
export MINIKUBE_WANTUPDATENOTIFICATION=false
export MINIKUBE_WANTREPORTERRORPROMPT=false
export MINIKUBE_HOME=$HOME
export CHANGE_MINIKUBE_NONE_USER=true
mkdir -p $HOME/.kube
touch $HOME/.kube/config
export KUBECONFIG=$HOME/.kube/config
4、启动minikube
curl -Lo kubeadm http://storage.googleapis.com/kubernetes-release/release/v1.10.0/bin/linux/amd64/kubeadm
curl -Lo kubelet http://storage.googleapis.com/kubernetes-release/release/v1.10.0/bin/linux/amd64/kubelet
sudo -E ./minikube start --vm-driver=none
--vm-driver=none (本身就是虚拟机,所以不需要将minikube再次安装到虚机里面,虚机中再安装虚机我的机器扛不住)
在这个过程中minikube需要下载kubelet、kubeadm,以及拉取所需要到镜像,由于防火墙到原因,这就卡住了,再也不能进行下去了,所以啊,我挨个再国外服务器上拉取到镜像和程序包。
运行一下上面curl两句下载命令,不然会报错,因为下载kubeadm、kubelet时采用的是https,但是无法连接,使用http下载以后就可以跳过
Starting local Kubernetes v1.10.0 cluster...
Starting VM...
Getting VM IP address...
Moving files into cluster...
Downloading kubeadm v1.10.0
Downloading kubelet v1.10.0
这块了,不然会报一下这个错:
E0702 15:58:46.347477 20746 start.go:252] Error updating cluster: downloading binaries: downloading kubeadm: Error downloading kubeadm v1.10.0: failed to download: failed to download to temp file: download failed: 5 error(s) occurred:
* Temporary download error: Get https://storage.googleapis.com/kubernetes-release/release/v1.10.0/bin/linux/amd64/kubeadm: net/http: TLS handshake timeout
* Temporary download error: Get https://storage.googleapis.com/kubernetes-release/release/v1.10.0/bin/linux/amd64/kubeadm: dial tcp 172.217.160.80:443: i/o timeout
* Temporary download error: Get https://storage.googleapis.com/kubernetes-release/release/v1.10.0/bin/linux/amd64/kubeadm: net/http: TLS handshake timeout
* Temporary download error: Get https://storage.googleapis.com/kubernetes-release/release/v1.10.0/bin/linux/amd64/kubeadm: dial tcp 172.217.160.80:443: i/o timeout
* Temporary download error: Get https://storage.googleapis.com/kubernetes-release/release/v1.10.0/bin/linux/amd64/kubeadm: dial tcp 172.217.160.80:443: i/o timeout
以下是所需要的镜像列表:
k8s.gcr.io/kube-apiserver-amd64:v1.10.0
k8s.gcr.io/kube-scheduler-amd64:v1.10.0
k8s.gcr.io/kube-controller-manager-amd64:v1.10.0
k8s.gcr.io/kube-proxy-amd64:v1.10.0
k8s.gcr.io/etcd-amd64:3.1.12
k8s.gcr.io/k8s-dns-dnsmasq-nanny-amd64:1.14.8
k8s.gcr.io/k8s-dns-sidecar-amd64:1.14.8
k8s.gcr.io/k8s-dns-kube-dns-amd64:1.14.8
k8s.gcr.io/pause-amd64:3.1
quay.io/coreos/flannel:v0.9.1-amd64
k8s.gcr.io/kube-addon-manager:v8.6
k8s.gcr.io/kubernetes-dashboard-amd64:v1.8.1
gcr.io/k8s-minikube/storage-provisioner:v1.8.1
如果不出意外应该就可以安装成功了!
安装完成后
root@ubuntu:~# sudo -E ./minikube start --vm-driver=none
Starting local Kubernetes v1.10.0 cluster...
Starting VM...
Getting VM IP address...
Moving files into cluster...
Downloading kubeadm v1.10.0
Downloading kubelet v1.10.0
Finished Downloading kubelet v1.10.0
Finished Downloading kubeadm v1.10.0
Setting up certs...
Connecting to cluster...
Setting up kubeconfig...
Starting cluster components...
Kubectl is now configured to use the cluster.
===================
WARNING: IT IS RECOMMENDED NOT TO RUN THE NONE DRIVER ON PERSONAL WORKSTATIONS
The 'none' driver will run an insecure kubernetes apiserver as root that may leave the host vulnerable to CSRF attacks
Loading cached images from config file.
5、查看状态
查看node节点状态
root@ubuntu:~/1.10.1# kubectl get nodes
NAME STATUS ROLES AGE VERSION
minikube Ready master 20h v1.10.0
查看pod状态
root@ubuntu:~/1.10.1# kubectl get pods--all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system etcd-minikube 1/1 Running 2 1h
kube-system kube-addon-manager-minikube 1/1 Running 1 20h
kube-system kube-apiserver-minikube 1/1 Running 1 1h
kube-system kube-controller-manager-minikube 1/1 Running 2 1h
kube-system kube-dns-86f4d74b45-pndzp 3/3 Running 16 20h
kube-system kube-proxy-pgjpd 1/1 Running 0 1h
kube-system kube-scheduler-minikube 1/1 Running 5 20h
kube-system kubernetes-dashboard-5498ccf677-scd97 1/1 Running 4 18h
kube-system storage-provisioner 1/1 Running 1 18h
看下READY和STATUS状态,如果正常就一切ok,万事大吉了。
如果有问题,那就看看什么原因,例如查看dashboard,可以根据具体问题作出具体的解决方法(下面描述是没问题)
root@ubuntu:~# kubectl describe--namespace=kube-system pod kubernetes-dashboard-5498ccf677-scd97
Name: kubernetes-dashboard-5498ccf677-scd97
Namespace: kube-system
Node: minikube/10.0.3.15
Start Time: Thu, 21 Jun 2018 17:11:28 +0800
Labels: addonmanager.kubernetes.io/mode=Reconcile
app=kubernetes-dashboard
pod-template-hash=1054779233
version=v1.8.1
Annotations:
Status: Running
IP: 172.17.0.3
Controlled By: ReplicaSet/kubernetes-dashboard-5498ccf677
Containers:
kubernetes-dashboard:
Container ID: docker://e5b6c1ae90d34be67da0c51cf4c0924ff7868a7ec76603f9810318b1ed9335b3
Image: k8s.gcr.io/kubernetes-dashboard-amd64:v1.8.1
Image ID: docker://sha256:e94d2f21bc0c297cb74c1dfdd23e2eace013f532c60726601af67984d97f718a
Port: 9090/TCP
HostPort: 0/TCP
State: Running
Started: Fri, 22 Jun 201814:18:41 +0800
LastState: Terminated
Reason: Error
Exit Code: 1
Started: Fri, 22 Jun 201814:17:45 +0800
Finished: Fri, 22 Jun 201814:18:18 +0800
Ready: True
Restart Count: 6
Liveness: http-gethttp://:9090/ delay=30s timeout=30s period=10s #success=1 #failure=3
Environment:
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-6xhk9(ro)
Conditions:
Type Status
Initialized True
Ready True
PodScheduled True
Volumes:
default-token-6xhk9:
Type: Secret (a volumepopulated by a Secret)
SecretName: default-token-6xhk9
Optional: false
QoS Class: BestEffort
Node-Selectors:
Tolerations: node.kubernetes.io/not-ready:NoExecute for 300s
node.kubernetes.io/unreachable:NoExecute for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal SuccessfulMountVolume 29m kubelet, minikube MountVolume.SetUp succeeded for volume"default-token-6xhk9"
Normal SandboxChanged 29m kubelet, minikube Pod sandbox changed, it will be killed andre-created.
Warning Unhealthy 28m kubelet, minikube Liveness probe failed: Gethttp://172.17.0.3:9090/: dial tcp 172.17.0.3:9090: getsockopt: connectionrefused
Warning BackOff 28m (x2 over 28m) kubelet, minikube Back-off restarting failed container
Normal Pulled 28m (x2 over 29m) kubelet, minikube Container image"k8s.gcr.io/kubernetes-dashboard-amd64:v1.8.1" already present onmachine
Normal Created 28m (x2 over 29m) kubelet, minikube Created container
Normal Started 28m (x2 over 29m) kubelet, minikube Started container
6、启动dashboard
root@ubuntu:~# minikube dashboard
访问dashboard的是查看具体url:
root@ubuntu:~# minikube dashboard --url
http://10.0.3.15:30000
由于virtual是双网卡的问题,所以minikube返回的url是不能访问的,10.0.3.15这个IP是内部IP,pc端是无法访问的,所以需要在iptalbes上做一下路由转发!
临时:
echo "1">/proc/sys/net/ipv4/ip_forward
固定:修改/etc/sysctl.conf,取消这一行的注释:
net.ipv4.ip_forward= 1
root@ubuntu:~#sysctl -p
设置iptables规则:
iptables -t nat -A POSTROUTING -j MASQUERADE
再访问:http://192.168.56.102:30000就可以访问了