1、安装etcd和kubernetes

该步骤会默认安装docker。所以建议在原机器上没有安装Docker,否则可能会有冲突导致安装失败。

yum install -y etcd kubernetes

2、配置

(1)、修改配置文件:/etc/sysconfig/docker(可不必操作,因为后面使用的仓库是daocloude镜像地址:https://dashboard.daocloud.io/packages)
添加下面一行,使用内网仓库:

ADD_REGISTRY='--add-registry reg.docker.lc'

(2)修改配置文件:/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去掉

3、查看docker版本

上面命令并没有加入docker,但它却自动安装了

docker version

在这里插入图片描述

4、启动服务

把服务添加到启动项,并启动服务:

for SERVICE in docker etcd kube-apiserver kube-controller-manager kube-scheduler kube-proxy kubelet; do  
 
    systemctl start $SERVICE 
    systemctl enable $SERVICE 
 	# systemctl stop $SERVICE #关闭服务
done

5、查看相关情况

ps -ef | grep kube

在这里插入图片描述
出现以上结果,则说明安装成功

6、安装kubernetes-dashboard

(1)kubernetes-dashboard.yaml文件配置

源文件地址:https://github.com/kubernetes/dashboard/releases?after=v1.7.0

cat >kubernetes-dashboard.yaml<<-EOF 
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: reg.docker.lc/share/kubernetes-dashboard-amd64:v1.5.1      #默认的镜像是使用google的,这里改成内网 
        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.0.10.10:8080    #注意这里是api的地址 
        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 
 
EOF

(2)安装

kubectl create -f kubernetes-dashboard.yaml

(3)查看

kubectl get pods --all-namespaces

在这里插入图片描述

7、使用

(1)查看网络端口使用情况

netstat -nultup

在这里插入图片描述

(2)浏览器访问

①api访问
http://ip:8080
在这里插入图片描述

②界面访问
http://ip:8080/api/v1/namespaces/kube-system/services/http:kubernetes-dashboard:/proxy/#/workload?namespace=default
在这里插入图片描述

8、问题解决

(1)containerCreating

FailedSynError syncing pod, skipping: failed to "StartContainer" for "POD" with ErrImagePull: "image pull failed for registry.access.redhat.com/rhel7/pod-infrastructure:latest, this may be because there are no credentials on this request.  details: (open /etc/docker/certs.d/registry.access.redhat.com/redhat-ca.crt: no such file or directory)" 13m 11s 56 {kubelet 127.0.0.1} Warning FailedSync Error syncing pod, skipping: failed to "StartContainer" for "POD" with ImagePullBackOff: "Back-off pulling image \"registry.access.redhat.com/rhel7/pod-infrastructure:latest\""

Error syncing pod, skipping: failed to "StartContainer" for "POD" with ErrImagePull: "image pull failed for registry.access.redhat.com/rhel7/pod-infrastructure:latest, this may be because there are no credentials on this request.  details: (open /etc/docker/certs.d/registry.access.redhat.com/redhat-ca.crt: no such file or directory)"

①查看pod

kubectl describe pod kubernetes-dashboard-3603079361-b2x00 --namespace=kube-system

②删除pod

kubectl get pod -n nameSpaceName
kubectl delete pod podName -n nameSpaceName
kubectl get deployment -n nameSpaceName
kubectl delete deployment deploymentName -n nameSpaceName

③添加证书

wget http://mirror.centos.org/centos/7/os/x86_64/Packages/python-rhsm-certificates-1.19.10-1.el7_4.x86_64.rpm
rpm2cpio python-rhsm-certificates-1.19.10-1.el7_4.x86_64.rpm | cpio -iv --to-stdout ./etc/rhsm/ca/redhat-uep.pem | tee /etc/rhsm/ca/redhat-uep.pem

(2)ImagePullBackOff

①问题阐述:
在这里插入图片描述
在这里插入图片描述
②添加可被成功拉取的镜像
daocloude镜像地址:https://dashboard.daocloud.io/packages

# Copyright 2015 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Configuration to deploy release version of the Dashboard UI.
#
# Example usage: kubectl create -f <this_file>

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: daocloud.io/gfkchinanetquest/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://my-address:port
        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

(3)CrashLoopBackOff

服务无法启动,处于不断重启的过程中,但是无法成功开启
在这里插入图片描述

查看日志

kubectl logs kubernetes-dashboard-3933968709-9f7qn -n kube-system

在这里插入图片描述
网络端口使用情况
在这里插入图片描述
原因分析:apiserver的端口使用错误,在配置中若将“# - --apiserver-host”部分注释,则系统默认使用了无证书的6443,导致无法征程链接apiserver服务,因此要将注释去掉,修改成以下内容

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

140.143.159.146为你的云服务器IP地址,8080为含证书的dashboard的http访问端口,6443为https访问端口

附上最终的yaml文件

# Copyright 2015 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Configuration to deploy release version of the Dashboard UI.
#
# Example usage: kubectl create -f <this_file>

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: daocloud.io/gfkchinanetquest/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://140.111.123.252:8080 #将140.111.123.252更改为你的ip地址
        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

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐