没有web界面的展示是不完整的,继Centos7.3 Kubernetes集群部署我们安装了K8S,接下来我带着大家一步步去搭建UI界面。
一、搭建私有仓库
我们在搭建过程中会用到一些镜像,为了方便演示,我们自己搭建一个私有仓库。
1、pull私有仓库
docker pull registry
2、运行私有仓库
docker run -d --name siyou --restart always -p 5000:5000 -v /data/docker/registry:/tmp/registry docker.io/registry
注意:报错请参考 http://blog.sina.com.cn/s/blog_8e032fb90102xuon.html
3、访问私有仓库
[root@k8s-master ~]# curl -X GET http://127.0.0.1:5000/v2/_catalog
{"repositories":[]}
4、为基础镜像打标签
[root@k8s-master ~]# docker tag 177391bcf802 192.168.56.130:5000/centos
5、所有节点修改配置文件为私有仓库
vim /etc/sysconfig/docker
OPTIONS='--selinux-enabled --insecure-registry 192.168.56.130:5000'
systemctl restart docker
6、提交镜像到私有仓库中
[root@k8s-master ~]# docker push 192.168.56.130:5000/centos
7、检查是否存在对应镜像
[root@k8s-master ~]# curl -X GET http://192.168.56.130:5000/v2/_catalog
{"repositories":["centos"]}
[root@k8s-master ~]#
[root@k8s-master ~]# curl -X GET http://192.168.56.130:5000/v2/centos/tags/list
{"name":"centos","tags":["latest"]}
8、客户端验证
[root@k8s-node1 ~]# docker pull 192.168.56.130:5000/centos
[root@k8s-node2 ~]# docker pull 192.168.56.130:5000/centos
二、下载k8s dashboard镜像
注意:docker.io不支持下载,这里我们提供:http://download.zhsir.org/docker/images/kubernets-dashboard/
1、上传镜像
[root@k8s-master ~]# mkdir /data/images -p
[root@k8s-master ~]# cd /data/images/
2、导入
[root@k8s-master images]# cat kubernetes-dashboard-amd64.tar.gz |docker import - load/kubernetes-dashboard-amd64
[root@k8s-master images]# cat pause-amd64.tar.gz|docker import - load/pause-amd64 docker
3、根据镜像ID 打tag
[root@k8s-master images]# docker tag 71dfe833ce74 192.168.56.130:5000/kubernetes-dashboard-amd64
[root@k8s-master images]# docker tag 99e59f495ffa 192.168.56.130:5000/pause-amd64
4、上传私有仓库
[root@k8s-master images]# docker push 192.168.56.130:5000/kubernetes-dashboard-amd64
[root@k8s-master images]# docker push 192.168.56.130:5000/pause-amd64
5、客户端下载pause-amd64
docker pull 192.168.56.130:5000/kubernetes-dashboard-amd64
三、K8S ui
1、新建kube-system的namespace
[root@k8s-master ~]# mkdir /data/pods
[root@k8s-master ~]# cd /data/pods/
[root@k8s-master pods]#
[root@k8s-master pods]# vim kube-namespace.yaml
{
"kind": "Namespace",
"apiVersion": "v1",
"metadata": {
"name": "kube-system"
}
}
[root@k8s-master pods]# kubectl create -f kube-namespace.yaml
[root@k8s-master pods]# kubectl get namespace
NAME STATUS AGE
default Active 12m
kube-system Active 12m
二、新建kube-ui.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
# Keep the name in sync with image version and
# gce/coreos/kube-manifests/addons/dashboard counterparts
name: kubernetes-dashboard-latest
namespace: kube-system
spec:
replicas: 1
template:
metadata:
labels:
k8s-app: kubernetes-dashboard
version: latest
kubernetes.io/cluster-service: "true"
spec:
containers:
- name: kubernetes-dashboard
image: 192.168.56.130:5000/kubernetes-dashboard-amd64
resources:
# keep request = limit to keep this container in guaranteed class
limits:
cpu: 100m
memory: 50Mi
requests:
cpu: 100m
memory: 50Mi
ports:
- containerPort: 9090
args:
- --apiserver-host=http://192.168.56.130:8080
livenessProbe:
httpGet:
path: /
port: 9090
initialDelaySeconds: 30
timeoutSeconds: 30
---
kind: Service
metadata:
name: kubernetes-dashboard
namespace: kube-system
labels:
k8s-app: kubernetes-dashboard
kubernetes.io/cluster-service: "true"
spec:
selector:
k8s-app: kubernetes-dashboard
ports:
- port: 80
请将文件中apiserver-host修改为自己的kebu-apiserver
三、创建POD
[root@k8s-master pods]# kubectl create -f kube-ui.yaml
deployment "kubernetes-dashboard-latest" created
service "kubernetes-dashboard" created
[root@k8s-master pods]# kubectl get pods --namespace=kube-system
NAME READY STATUS RESTARTS AGE
kubernetes-dashboard-latest-3472061128-gs22w 1/1 Running 0 6s
四、查看容器详细过程
[root@k8s-master pods]# kubectl describe pods kubernetes-dashboard-latest-3472061128-gs22w --namespace=kube-system
报错:参考http://blog.51cto.com/tsing/1983480
当有多个node,可以用该命令中看到容器被分配到哪个node上,启动后分配的ip地址等信息.
如果在结果中看到"State: Running"时,请移步到node查看容器运行状态,应该也是up的状态.
五、web登录验证
访问http://192.168.56.130:8080/ui会跳转到http://192.168.56.130:8080/api/v1/proxy/namespaces/kube-system/services/kubernetes-dashboard/#!/workload?namespace=default即可访问kube-ui的dashboard 页面,如下图所示: