離線安裝minikube—1.10.1
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
sudo -E ./minikube start --vm-driver=none
--vm-driver=none (本身就是虛擬機,所以不需要將minikube再次安裝到虛機裏面,虛機中再安裝虛機我的機器扛不住)
在這個過程中minikube需要下載kubelet、kubeadm,以及拉取所需要到鏡像,由於防火墻到原因,這就卡住了,再也不能進行下去了,所以啊,我挨個再國外服務器上拉取到鏡像和程序包。
以下是所需要的鏡像列表:
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
如果不出意外應該就可以安裝成功了!
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就可以訪問了
離線安裝minikube—1.10.1