频道栏目
首页 > 资讯 > Linux > 正文

CentOS7下搭建Kubernetes-dashboard管理服务教程

18-05-14        来源:[db:作者]  
收藏   我要投稿

一、先决条件

1、首先你必有现成的Kubernetes集群

2、建议采用etcd集群

二、部署Kubernetes-dashboard

[所有机器:Master、Node1、Node2]

1、安装flannel(flannel为管理Containers网络)

[root@k8s-master ~]# yum -y install epel-release flannel

2、配置flanel

[Master]

[root@k8s-master ~]# vim /etc/sysconfig/flanneld

# Flanneld configuration options

# etcd url location. Point this to the server where etcd runs

FLANNEL_ETCD_ENDPOINTS="http://k8s-master:2379"

# etcd config key. This is the configuration key that flannel queries

# For address range assignment

FLANNEL_ETCD_PREFIX="/atomic.io/network"

# Any additional options that you want to pass

#FLANNEL_OPTIONS=""

[Node]

[root@k8s-node1 ~]# vim /etc/sysconfig/flanneld

# Flanneld configuration options

# etcd url location. Point this to the server where etcd runs

FLANNEL_ETCD_ENDPOINTS="http://k8s-master:2379"

# etcd config key. This is the configuration key that flannel queries

# For address range assignment

FLANNEL_ETCD_PREFIX="/atomic.io/network"

# Any additional options that you want to pass

#FLANNEL_OPTIONS=""

3、添加Etcd网络配置

[Master]

[root@k8s-master ~]# mkdir -p /atomic.io/network/

[root@k8s-master ~]# chmod -R 777 /atomic.io

[root@k8s-master ~]# etcdctl mk /atomic.io/network/config ‘{"Network":"10.254.0.0/16"}‘

****** 注:此IP为/etc/kubernetes/apiserver中{KUBE_SERVICE_ADDRESSES="--service-cluster-ip-range=10.254.0.0/16" }填写的地址

4、启动flannel服务

[所有机器]

[root@k8s-master ~]# systemctl start flanneld.service

[root@k8s-master ~]# systemctl enable flanneld.service

5、修改Kubernetes所有Node节点kubelet设置中添加dns信息,否则会报错

[Node1/Node2]

[root@k8s-node1 ~]# vim /etc/kubernetes/kubelet

###

# kubernetes kubelet (minion) config

# The address for the info server to serve on (set to 0.0.0.0 or "" for all interfaces)

KUBELET_ADDRESS="--address=0.0.0.0"

# The port for the info server to serve on

KUBELET_PORT="--port=10250"

# You may leave this blank to use the actual hostname

KUBELET_HOSTNAME="--hostname-override=k8s-node1"

# location of the api-server

KUBELET_API_SERVER="--api-servers=http://k8s-master:8080"

# pod infrastructure container

KUBELET_POD_INFRA_CONTAINER="--pod-infra-container-image=registry.access.redhat.com/rhel7/pod-infrastructure:latest"

# Add your own!

#KUBELET_ARGS=""

KUBELET_ARGS="--cluster-dns=223.5.5.5 --cluster-domain=k8s-master"

6、重启Node上的服务

[Master]

for SERVICES in flanneld etcd kube-apiserver kube-controller-manager kube-scheduler; do systemctl restart $SERVICES; systemctl enable $SERVICES; systemctl status $SERVICES ; done

[Node]

for SERVICES in flanneld kube-proxy kubelet docker; do systemctl restart $SERVICES; systemctl enable $SERVICES; systemctl status $SERVICES ; done

7、安装dashboard

[Node1/Node2]

a、导入images

***由于墙的原因,需要先导入images,如果你可以翻墙,忽略此步骤

下载地址:

b、导入:

[root@k8s-node1 ~]# docker load < kubernetes-dashboard.tar.gz

c、查看

[root@k8s-node1 ~]# docker images

REPOSITORY TAG IMAGE ID CREATED SIZE

gcr.io/google_containers/kubernetes-dashboard-amd64 v1.6.2 bd4d50b8499e 8 days ago 139 MB

8、创建dashboard容器

[Master]

a、下载kubernetes-dashboar.yaml文件

[root@k8s-master ~]# git clone https://github.com/jdedu/kubernetes.git

b、修改其中标红项

[root@k8s-master ~]# vim kubernetes/kubernetes-dashboard.yaml

kind: Deployment

apiVersion: extensions/v1beta1

metadata:

labels:

app: kubernetes-dashboard

version: v1.1.1

name: kubernetes-dashboard

namespace: kube-system

spec:

replicas: 1

selector:

matchLabels:

app: kubernetes-dashboard

template:

metadata:

labels:

app: kubernetes-dashboard

spec:

containers:

- name: kubernetes-dashboard

image: gcr.io/google_containers/kubernetes-dashboard-amd64:v1.6.2

imagePullPolicy: Always

ports:

- containerPort: 9090

protocol: TCP

args:

- --apiserver-host=http://192.168.80.130: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

9、创建dashboard容器

[Master]

[root@k8s-master ~]# kubectl create -f kubernetes-dashboard.yaml

deployment "kubernetes-dashboard" created

service "kubernetes-dashboard" created

10、查看状态

a、查看pods

[root@k8s-master ~]# kubectl get pods --namespace=kube-system

NAME READY STATUS RESTARTS AGE

kubernetes-dashboard-1607234690-3bnk2 0/1 ContainerCreating 0 34s

b、查看构建详细信息

[root@k8s-master ~]# kubectl describe pods kubernetes-dashboard-1607234690-3bnk2 --namespace=kube-system

Name: kubernetes-dashboard-1607234690-3bnk2

Namespace: kube-system

Node: k8s-node2/192.168.80.132

Start Time: Thu, 03 Aug 2017 17:15:50 +0800

Labels: app=kubernetes-dashboard

pod-template-hash=1607234690

Status: Pending

IP:

Controllers: ReplicaSet/kubernetes-dashboard-1607234690

Containers:

kubernetes-dashboard:

Container ID:

Image: gcr.io/google_containers/kubernetes-dashboard-amd64:v1.6.2

Image ID:

Port: 9090/TCP

Args:

--apiserver-host=http://192.168.80.130:8080

State: Waiting

Reason: ContainerCreating

Ready: False

Restart Count: 0

Liveness: http-get http://:9090/ delay=30s timeout=30s period=10s #success=1 #failure=3

Volume Mounts:

Environment Variables:

Conditions:

Type Status

Initialized True

Ready False

PodScheduled True

No volumes.

QoS Class: BestEffort

Tolerations:

Events:

FirstSeen LastSeen Count From SubObjectPath Type Reason Message

--------- -------- ----- ---- ------------- -------- ------ -------

2m 2m 1 {default-scheduler } Normal Scheduled Successfully assigned kubernetes-dashboard-1607234690-3bnk2 to k8s-node2

三、测试

a、在测试机上添加host信息

192.168.80.130 k8s-master

b、使用浏览器输入:http://k8s-master:8080/ui

四、错误

[错误1]

[root@k8s-master ~]# kubectl describe pods kubernetes-dashboard-1607234690-3bnk2 --namespace=kube-system

1s 1s 1 {kubelet k8s-node2} Warning FailedSync Error syncing pod, skipping: failed to "StartContainer" for "kubernetes-dashboard" with CrashLoopBackOff: "Back-off 10s restarting failed container=kubernetes-dashboard pod=kubernetes-dashboard-980055440-l9zl5_kube-system(870d02e1-7810-11e7-9517-000c296a54e8)"

再次使用kubectl logs查看具体错误信息

[root@k8s-master ~]# kubectl logs kubernetes-dashboard-1607234690-l6gfk --namespace=kube-system

No request provided. Skipping authorization header

Error while initializing connection to Kubernetes apiserver. This most likely means that the cluster is misconfigured (e.g., it has invalid apiserver certificates or service accounts configuration) or the --apiserver-host param points to a server that does not exist. Reason: Get http://k8s-master:8080/version: dial tcp: lookup k8s-master on 223.5.5.5:53: no such host

Refer to the troubleshooting guide for more information: https://github.com/kubernetes/dashboard/blob/master/docs/user-guide/troubleshooting.md

[解决方案]

[root@k8s-master ~]# vim kubenetes-dashboard.yaml

- --apiserver改成ip,不要使用域名

此过程中可能会遇到很多问题,如果需要帮助,请发邮件至:DBA_Master@163.com

本文出自 “Elephant” 博客,请务必保留此出处http://zlyang.blog.51cto.com/1196234/1953399

CentOS7搭建Kubernetes-dashboard管理服务

标签:kubernetesetcdk8sdockerflanalopenvswitch

相关TAG标签
上一篇:nginx缓存静态资源服务器压力响应速度
下一篇:单例模式:Hibernate中封装Session
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站