安裝kubectl 這個是kubernetes的客戶端 可以使用類似docker run容器語法管理操作
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
安裝minikube
curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 && chmod +x minikube && sudo cp minikube /usr/local/bin/ && rm minikube
啟動minikube
minikube start
如果報錯 如以下訊息
因為minikube預設需要虛擬機來初始化kubernetes環境,但Linux例外 可以使用--vm-driver=none 參數來使用自已的環境
# linux 下獨有,不依賴虛扯機啟動 sudo minikube start --vm-driver=none # 如果是Mac or Windows,安裝VirtualBox後再重新start即可 sudo minikube start
啟動成功訊息如下
啟動一個容器
[root@grafana ~]# sudo kubectl run kube-nginx --image=nginx:latest --port=80 deployment.apps/kube-nginx created
查看狀態
[root@grafana ~]# kubectl get pods NAME READY STATUS RESTARTS AGE kube-nginx-6d8f6d45-bjktp 0/1 ContainerCreating 0 12s
查看叢集詳細資訊
[root@grafana ~]# kubectl cluster-info Kubernetes master is running at https://192.168.1.38:8443 KubeDNS is running at https://192.168.1.38:8443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
查看啟動log
[root@grafana ~]# minikube logs -- Logs begin at Tue 2018-09-04 00:01:09 CST, end at Mon 2018-09-10 16:09:19 CST. -- Sep 10 16:05:41 grafana systemd[1]: Started kubelet: The Kubernetes Node Agent. Sep 10 16:05:41 grafana systemd[1]: Starting kubelet: The Kubernetes Node Agent... Sep 10 16:05:43 grafana kubelet[24522]: Flag --cluster-dns has been deprecated, This parameter should be set via the config file specified by the Kubelet's --config flag. See https://kubernetes.io/docs/tasks/administer-cluster/kubelet-config-file/ for more information. Sep 10 16:05:43 grafana kubelet[24522]: Flag --cluster-domain has been deprecated, This parameter should be set via the config file specified by the Kubelet's --config flag. See https://kubernetes.io/docs/tasks/administer-cluster/kubelet-config-file/ for more information.
重新啟動服務
sudo kubectl run kube-nginx --image=nginx:latest --port=80 --image-pull-policy=IfNotPresent
發布服務
[root@grafana ~]# kubectl expose deployment kube-nginx --type=NodePort service/kube-nginx exposed
取得depolyments列表
[root@grafana ~]# kubectl get deployment NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE kube-nginx 1 1 1 1 4h
查看服務地址
[root@grafana ~]# minikube service kube-nginx --url http://192.168.1.38:30713
dashboard管理後台是kubernetes提供的容器管理後台,可以用來進行機器負載、集管管理、鏡像擴展、配置參數等相關操作
啟動dashboard
[root@grafana ~]# minikube dashboard --url http://192.168.1.38:30000
開啟http://192.168.1.38:30000 即可看到操作後台
官方手動安裝方式
https://kubernetes.io/docs/tasks/access-application-cluster/web-ui-dashboard/
安裝
kubectl create -f https://raw.githubusercontent.com/kubernetes/dashboard/master/aio/deploy/recommended/kubernetes-dashboard.yaml
執行
kubectl proxy --address='0.0.0.0' --accept-hosts='^*$'
http://192.168.1.35:8001/api/v1/namespaces/kube-system/services/http:kubernetes-dashboard:/proxy/#!/overview?namespace=default
GCP上面對應的服務是Kubernetes
Hits: 280