暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

Centos7 使用Minikube安装kubernetes

Linux运维技术之路 2019-08-31
615




一、 初始化

systemctl stop firewalld && systemctl disable firewalld
swapoff -a
setenforce 0
cat <<EOF > etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
setenforce 0

复制

二、下载安装 minikube

  • 1、下载minikube (建议使用阿里云镜像,国外镜像太慢了)

curl -Lo minikube http://kubernetes.oss-cn-hangzhou.aliyuncs.com/minikube/releases/v1.3.1/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube usr/local/bin/

复制

或者手动获取代码了

git clone https://github.com/AliyunContainerService/minikube
cd minikube
git checkout aliyun-v1.3.1
make
sudo cp out/minikube usr/local/bin/

复制
  • 2、帮助文档

[root@xuxingyue-test-01 ~]# minikube --help
Minikube is a CLI tool that provisions and manages single-node Kubernetes clusters optimized for development workflows.

Basic Commands:
start Starts a local kubernetes cluster
status Gets the status of a local kubernetes cluster
stop Stops a running local kubernetes cluster
delete Deletes a local kubernetes cluster
dashboard Access the kubernetes dashboard running within the minikube cluster

Images Commands:
docker-env Sets up docker env variables; similar to '$(docker-machine env)'
cache Add or delete an image from the local cache.

Configuration and Management Commands:
addons Modify minikube's kubernetes addons
config Modify minikube config
profile Profile gets or sets the current minikube profile
update-context Verify the IP address of the running cluster in kubeconfig.

Networking and Connectivity Commands:
service Gets the kubernetes URL(s) for the specified service in your local cluster
tunnel tunnel makes services of type LoadBalancer accessible on localhost

Advanced Commands:
mount Mounts the specified directory into minikube
ssh Log into or run a command on a machine with SSH; similar to '
docker-machine ssh'
kubectl Run kubectl

Troubleshooting Commands:
ssh-key Retrieve the ssh identity key path of the specified cluster
ip Retrieves the IP address of the running cluster
logs Gets the logs of the running instance, used for debugging minikube, not user code.
update-check Print current and latest version number
version Print the version of minikube

Other Commands:
completion Outputs minikube shell completion for the given shell (bash or zsh)

Use "minikube <command> --help" for more information about a given command.

复制
  • 正式安装 安装有2种方式,一、是提前安装VirtualBox,二、添加一个"--vm-driver=none",目前这里安装采用第二种

[root@test-01 ~]# minikube start --vm-driver=none --registry-mirror=https://docker.mirrors.ustc.edu.cn
* minikube v1.3.1 on Centos 7.6.1810
* Using image repository registry.cn-hangzhou.aliyuncs.com/google_containers
* Running on localhost (CPUs=4, Memory=3789MB, Disk=25587MB) ...
* OS release is CentOS Linux 7 (Core)
* Preparing Kubernetes v1.15.2 on Docker 19.03.0 ...
* Downloading kubeadm v1.15.2
* Downloading kubelet v1.15.2
* 拉取镜像 ...
* 正在启动 Kubernetes ...
* Configuring local host environment ...
*
! The 'none' driver provides limited isolation and may reduce system security and reliability.
! For more information, see:
- https://minikube.sigs.k8s.io/docs/reference/drivers/none/
*
! kubectl and minikube configuration will be stored in root
! To use kubectl or minikube commands as your own user, you may
! need to relocate them. For example, to overwrite your own settings:
*
- sudo mv /root/.kube /root/.minikube $HOME
- sudo chown -R $USER $HOME/.kube $HOME/.minikube
*
* This can also be done automatically by setting the env var CHANGE_MINIKUBE_NONE_USER=true

复制

三、测试容器案例并访问

  • 1、启动一个容器

[root@test-01 ~]# kubectl run kube-nginx --image=nginx:latest --port=80
kubectl run --generator=deployment/apps.v1 is DEPRECATED and will be removed in a future version. Use kubectl run --generator=run-pod/v1 or kubectl create instead.
修改为如下命令
[root@test-01 ~]# kubectl run --generator=run-pod/v1 kube-nginx --image=nginx:latest --port=80
pod/kube-nginx created

复制
  • 2、查看状态

[root@test-01 ~]# kubectl  get pods
NAME READY STATUS RESTARTS AGE
kube-nginx-7c765ffd95-rszh4 1/1 Running 0 20m

复制
  • 3、查看集群信息

[root@test-01 ~]#  kubectl cluster-info
Kubernetes master is running at https://10.10.40.5:8443
KubeDNS is running at https://10.10.40.5:8443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.

复制
  • 4、查看启动日志

[root@test-01 ~]# minikube logs
* ==> Docker <==
* -- Logs begin at 四 2019-08-29 11:28:07 CST, end at 四 2019-08-29 15:10:53 CST. --
* 8月 29 13:43:19 test-01 dockerd[19819]: time="2019-08-29T13:43:19.670690663+08:00" level=info msg="Attempting next endpoint for pull after error: Get https://k8s.gcr.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)"
* 8月 29 13:43:19 test-01 dockerd[19819]: time="2019-08-29T13:43:19.670742179+08:00" level=error msg="Handler for POST v1.40/images/create returned error: Get https://k8s.gcr.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)"

复制
  • 5、重新启动服务

[root@test-01 ~]# kubectl run kube-nginx --image=nginx:latest --port=80 --image-pull-policy=IfNotPresent
kubectl run --generator=deployment/apps.v1 is DEPRECATED and will be removed in a future version. Use kubectl run --generator=run-pod/v1 or kubectl create instead.
Error from server (AlreadyExists): deployments.apps "kube-nginx" already exists

复制
  • 6、发布服务

[root@test-01 ~]# kubectl expose deployment kube-nginx --type=NodePort
service/kube-nginx exposed

复制
  • 7、取得deployments列表

[root@test-01 ~]# kubectl get deployment
NAME READY UP-TO-DATE AVAILABLE AGE
kube-nginx 1/1 1 1 13m

复制
  • 8、查看服务地址

[root@test-01 ~]#  minikube service kube-nginx --url
* http://10.10.40.5:30017

复制
  • 9、访问地址:http://10.10.40.5:30017

四、minikube 安装dashboard

dashboard管理后台是kubernetes提供的容器管理后台,可以用来进行机器负载,集群管理,镜像扩展,配置参数等相关操作

  • 1、直接通过minikube dashboard

[root@xuxingyue-test-01 ~]# minikube dashboard --url
* Verifying dashboard health ...
* Launching proxy ...
* Verifying proxy health ...
http://127.0.0.1:5154/api/v1/namespaces/kube-system/services/http:kubernetes-dashboard:/proxy/

复制
  • 2、命令安装dashboard

[root@test-01 ~]# kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0-beta1/aio/deploy/recommended.yaml
namespace/kubernetes-dashboard created
serviceaccount/kubernetes-dashboard created
service/kubernetes-dashboard created
secret/kubernetes-dashboard-certs created
secret/kubernetes-dashboard-csrf created
secret/kubernetes-dashboard-key-holder created
configmap/kubernetes-dashboard-settings created
role.rbac.authorization.k8s.io/kubernetes-dashboard created
clusterrole.rbac.authorization.k8s.io/kubernetes-dashboard created
rolebinding.rbac.authorization.k8s.io/kubernetes-dashboard created
clusterrolebinding.rbac.authorization.k8s.io/kubernetes-dashboard created
deployment.apps/kubernetes-dashboard created
service/dashboard-metrics-scraper created
deployment.apps/kubernetes-metrics-scraper created

复制
[root@test-01 ~]# kubectl proxy --address='0.0.0.0' --accept-hosts='^*$'
Starting to serve on [::]:8001

复制
  • 3、访问URL :http://10.10.40.5:8001/api/v1/namespaces/kube-system/services/http:kubernetes-dashboard:/proxy/



爱运维^_^爱分享


文章转载自Linux运维技术之路,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论