Centos7 单节点上安装kubernetes-dashboard过程
主机ip地址:10.200.3.81
系统版本:
[root@localhost ~]# cat /etc/redhat-release CentOS Linux release 7.4.1708 (Core)
1、配置yum源:
[root@localhost ~]# cat >/etc/yum.repos.d/kubernetes.repo<<-EOF [virt7-docker-common-release] name=virt7-docker-common-release baseurl=http://cbs.centos.org/repos/virt7-docker-common-release/x86_64/os/ gpgcheck=0 EOF
2、查看当前yum里的Kubernetes版本:
[root@localhost ~]# yum info kubernetes Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: mirrors.shu.edu.cn * extras: ftp.tsukuba.wide.ad.jp * updates: mirrors.shu.edu.cn Installed Packages Name : kubernetes Arch : x86_64 Version : 1.5.2Release : 0.7.git269f928.el7 Size : 0.0 Repo : installed From repo : extras Summary : Container cluster management URL : k8s.io/kubernetes License : ASL 2.0Description : Container cluster management
3、安装所需要的包:
[root@localhost ~]# yum -y install --enablerepo=virt7-docker-common-release kubernetes etcd
4、配置文件的修改:
修改配置文件:/etc/kubernetes/apiserver
KUBE_API_ADDRESS="--insecure-bind-address=0.0.0.0" #这里把127.0.0.1改成0.0.0.0 KUBE_ADMISSION_CONTROL="--admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,Security ContextDeny,ResourceQuota" #去掉ServiceAccount即可;
5、查看docker的版本:[上面命令并没有加入docker,但它却自动安装了]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | [root@localhost ~]#docker version Client: Version: 1.13.1 API version: 1.26 Package version: <unknown> Go version: go1.8.3 Git commit: 774336d/1.13.1 Built: Wed Mar 7 17:06:16 2018 OS/Arch: linux/amd64 Server: Version: 1.13.1 API version: 1.26 (minimum version 1.12) Package version: <unknown> Go version: go1.8.3 Git commit: 774336d/1.13.1 Built: Wed Mar 7 17:06:16 2018 OS/Arch: linux/amd64 Experimental: false |
6、 把服务添加到启动项,并启动服务:
for SERVICE in docker etcd kube-apiserver kube-controller-manager kube-scheduler kube-proxy kubelet; do systemctl start $SERVICE systemctl enable $SERVICE done
7、验证安装成果:
#当前主机上没有任何镜像,接下来我们创建一个pod实例;
[root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE
使用kubectl命令创建一个nginx实例:
创建之前先docker pull nginx一个镜像到本地:
命令行创建nginx pods
[root@localhost ~]#kubectl run my-nginx --image=nginx --replicas=1 --port=80
命令行创建service
# kubectl expose deployment my-nginx --port=8888 --target-port=80 --external-ip=10.200.3.81
查看pod实例分配的Ip地址;
[root@localhost ~]# kubectl get pods -o wide NAME READY STATUS RESTARTS AGE IP NODE my-nginx-379829228-mpm5f 1/1 Running 0 51m 172.17.0.2 127.0.0.1
查看Kubetnetes里的service[简写svc],可以看到指定了外网IP地址:10.200.3.81
[root@localhost ~]# kubectl get svc NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes 10.254.0.1 <none> 443/TCP 1h my-nginx 10.254.81.204 10.200.3.81 8888/TCP 41m
查看nginx服务的状态:
[root@localhost ~]# curl -I 10.200.3.81:8888HTTP/1.1 200 OK Server: nginx/1.13.12Date: Thu, 10 May 2018 08:42:28 GMT Content-Type: text/html Content-Length: 612Last-Modified: Mon, 09 Apr 2018 16:01:09 GMT Connection: keep-alive ETag: "5acb8e45-264"Accept-Ranges: bytes
这样单节点的Kubernetes就已经跑起来了,接下来就是安装kubernetes-dashboard ,下载kubernetes-dashboard.yaml文件,修改一下即可;因为我使用的是公网的docker镜像,所以先下载dashborad的镜像到本地仓库.
[root@localhost ~]#docker pull docker.io/siriuszg/kubernetes-dashboard-amd64:v1.5.1
kubernetes-dashboard.yaml文件如下:
[root@localhost ~]# cat kubernetes-dashboard.yaml kind: Deployment apiVersion: extensions/v1beta1 metadata: labels: app: kubernetes-dashboard name: kubernetes-dashboard namespace: kube-system spec: replicas: 1 selector: matchLabels: app: kubernetes-dashboard template: metadata: labels: app: kubernetes-dashboard # Comment the following annotation if Dashboard must not be deployed on master annotations: scheduler.alpha.kubernetes.io/tolerations: | [ { "key": "dedicated", "operator": "Equal", "value": "master", "effect": "NoSchedule" } ] spec: containers: - name: kubernetes-dashboard image: docker.io/siriuszg/kubernetes-dashboard-amd64:v1.5.1 imagePullPolicy: Always ports: - containerPort: 9090 protocol: TCP args: # Uncomment the following line to manually specify Kubernetes API server Host # If not specified, Dashboard will attempt to auto discover the API server and connect # to it. Uncomment only if the default does not work. - --apiserver-host=http://10.200.3.81:8080 livenessProbe: httpGet: path: / port: 9090 initialDelaySeconds: 30 timeoutSeconds: 30 --- kind: Service apiVersion: v1 metadata: labels: app: kubernetes-dashboard name: kubernetes-dashboard namespace: kube-system spec: type: NodePort ports: - port: 80 targetPort: 9090 selector: app: kubernetes-dashboard
创建实例:
# kubectl create -f kubernetes-dashboard.yaml
查看是否成功运行:
[root@localhost ~]# kubectl get pods --all-namespaces NAMESPACE NAME READY STATUS RESTARTS AGEdefault my-nginx-379829228-mpm5f 1/1 Running 0 59m kube-system kubernetes-dashboard-3162153223-2s0qb 1/1 Running 0 40m
启动成功就可以打开网页看到效果啦:(输入http://10.200.3.81:8080/ui 即可跳转到如下地址)
号外:
kubectl get pods 状态一直为ContainerCreating解决:
跟踪状态:
可以使用kubectl describe pods Pod_Name来查看是什么原因
如果报错如下,
需要安装rhsm
#yum install *rhsm* -y
再重启服务即可
参考文档:https://www.58jb.com/html/152.html
https://www.cnblogs.com/stromliu/p/8567741.html
目录 返回
首页