ubuntu16.04 安装 kubernetes 1.7.2

安装步骤

  • 安装docker 1.12
  • pull k8s(1.7.2)需要用到的 image
  • 安装k8s
  • 安装flannel
  • 安装dashboard(head)

安装docker

# 执行
./install.sh docker

pull k8s 镜像

# 执行, 直接从线上下载
./install.sh pull

或者直接把我已经打好包的镜像 load 到本地
下载地址: 百度网盘 密码: uxe8

# 执行导入镜像
docker load < kube-proxy-amd64_v1.7.2.tar
docker load < kube-scheduler-amd64_v1.7.2.tar
docker load < kube-controller-manager-amd64_v1.7.2.tar
docker load < kube-apiserver-amd64_v1.7.2.tar
docker load < pause-amd64_3.0.tar
docker load < etcd-amd64_3.0.17.tar
docker load < k8s-dns-sidecar-amd64_1.14.4.tar
docker load < k8s-dns-kube-dns-amd64_1.14.4.tar
docker load < k8s-dns-dnsmasq-nanny-amd64_1.14.4.tar
docker load < flannel-v0.8.0-amd64.tar
docker load < kubernetes-dashboard-amd64-head.tar

安装k8s

下载我们已经编译好的deb包(k8s_bin.zip),并且解压
下载地址: 百度网盘 密码: xprx

# 执行安装
./install install

启动kube

./install start

安装flannel, 把文件保存到当前目录

新建文件: kube-flannel.yaml

---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: flannel
  namespace: kube-system
---
kind: ConfigMap
apiVersion: v1
metadata:
  name: kube-flannel-cfg
  namespace: kube-system
  labels:
    tier: node
    app: flannel
data:
  cni-conf.json: |
    {
      "name": "cbr0",
      "type": "flannel",
      "delegate": {
        "isDefaultGateway": true
      }
    }
  net-conf.json: |
    {
      "Network": "10.244.0.0/16",
      "Backend": {
        "Type": "vxlan"
      }
    }
---
apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
  name: kube-flannel-ds
  namespace: kube-system
  labels:
    tier: node
    app: flannel
spec:
  template:
    metadata:
      labels:
        tier: node
        app: flannel
    spec:
      hostNetwork: true
      nodeSelector:
        beta.kubernetes.io/arch: amd64
      tolerations:
      - key: node-role.kubernetes.io/master
        operator: Exists
        effect: NoSchedule
      serviceAccountName: flannel
      containers:
      - name: kube-flannel
        image: registry.cn-hangzhou.aliyuncs.com/szss_k8s/flannel:v0.8.0-amd64
        command: [ "/opt/bin/flanneld", "--ip-masq", "--kube-subnet-mgr" ]
        securityContext:
          privileged: true
        env:
        - name: POD_NAME
          valueFrom:
            fieldRef:
              fieldPath: metadata.name
        - name: POD_NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        volumeMounts:
        - name: run
          mountPath: /run
        - name: flannel-cfg
          mountPath: /etc/kube-flannel/
      - name: install-cni
        image: registry.cn-hangzhou.aliyuncs.com/szss_k8s/flannel:v0.8.0-amd64
        command: [ "/bin/sh", "-c", "set -e -x; cp -f /etc/kube-flannel/cni-conf.json /etc/cni/net.d/10-flannel.conf; while true; do sleep 3600; done" ]
        volumeMounts:
        - name: cni
          mountPath: /etc/cni/net.d
        - name: flannel-cfg
          mountPath: /etc/kube-flannel/
      volumes:
        - name: run
          hostPath:
            path: /run
        - name: cni
          hostPath:
            path: /etc/cni/net.d
        - name: flannel-cfg
          configMap:
            name: kube-flannel-cfg

新建文件: kube-flannel-rbac.yaml, 把文件保存到当前目录

# Create the clusterrole and clusterrolebinding:
# $ kubectl create -f kube-flannel-rbac.yml
# Create the pod using the same namespace used by the flannel serviceaccount:
# $ kubectl create --namespace kube-system -f kube-flannel.yml
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
  name: flannel
rules:
  - apiGroups:
      - ""
    resources:
      - pods
    verbs:
      - get
  - apiGroups:
      - ""
    resources:
      - nodes
    verbs:
      - list
      - watch
  - apiGroups:
      - ""
    resources:
      - nodes/status
    verbs:
      - patch
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
  name: flannel
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: flannel
subjects:
- kind: ServiceAccount
  name: flannel
  namespace: kube-system

安装flannel服务

#
./install flannel

启动代理

kubectl proxy --port=8080 --address='0.0.0.0'  --accept-hosts='^*$' &

安装dashboard

保存文件 kubernetes-dashboard-head.yaml 到当前目录

注意: 修改 - --apiserver-host=http://masterIP:8080 masterIP为主服务器ip

# 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 head version of the Dashboard UI compatible with
# Kubernetes 1.6 (RBAC enabled).
#
# Example usage: kubectl create -f 

apiVersion: v1
kind: ServiceAccount
metadata:
  labels:
    k8s-app: kubernetes-dashboard-head
  name: kubernetes-dashboard-head
  namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
  name: kubernetes-dashboard-head
  labels:
    k8s-app: kubernetes-dashboard-head
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
- kind: ServiceAccount
  name: kubernetes-dashboard-head
  namespace: kube-system
---
kind: Deployment
apiVersion: extensions/v1beta1
metadata:
  labels:
    k8s-app: kubernetes-dashboard-head
  name: kubernetes-dashboard-head
  namespace: kube-system
spec:
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      k8s-app: kubernetes-dashboard-head
  template:
    metadata:
      labels:
        k8s-app: kubernetes-dashboard-head
    spec:
      containers:
      - name: kubernetes-dashboard-head
        image: kubernetesdashboarddev/kubernetes-dashboard-amd64:head
        # Image is tagged and updated with :head, so always pull it.
        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://:8080
        livenessProbe:
          httpGet:
            path: /
            port: 9090
          initialDelaySeconds: 30
          timeoutSeconds: 30
      serviceAccountName: kubernetes-dashboard-head
      # Comment the following tolerations if Dashboard must not be deployed on master
      tolerations:
      - key: node-role.kubernetes.io/master
        effect: NoSchedule
---
kind: Service
apiVersion: v1
metadata:
  labels:
    k8s-app: kubernetes-dashboard-head
  name: kubernetes-dashboard-head
  namespace: kube-system
spec:
  type: NodePort
  ports:
  - port: 80
    targetPort: 9090
    nodePort: 30000
  selector:
    k8s-app: kubernetes-dashboard-head

启动dashboard 服务

kubectl create -f ./kubernetes-dashboard-head.yaml

访问dashboard: http://192.168.7.65:30000/

脚本install.sh

以下脚本被部署过程用到的脚本, 把以下脚本保存为 install.sh (修改为可执行文件)

#!/bin/bash
#
# 参考: http://blog.csdn.net/zhuchuangang/article/details/76572157
#set -x
#set -e
#
root=$(id -u)
if [ "$root" -ne 0 ] ;then
    echo must run as root
    exit 1
fi


HOST_NAME="k8s-node"
# 服务器 ip
HOST_IP_ADDR='192.168.1.xxx'   # 修改成服务器IP
# 
POD_NETWORK_CIDR='10.244.0.0/16'

###################################安装docker#########################
kube::install_docker(){
    echo '执行安装docker...'
   
    which docker > /dev/null 2>&1
    i=$?
    if [ $i -ne 0 ]; then
        apt-get update
        apt install -y apt-transport-https ca-certificates
        apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
     
        cat > /etc/apt/sources.list.d/Docker.list < /etc/systemd/system/kubelet.service.d/20-pod-infra-image.conf < step 1: $0 docker -> 安装docker 版本 1.12.6-0~ubuntu-wily "
        echo "-> step 2: $0 pull -> 下载镜像"
        echo "-> step 3: $0 install -> 安装k8s"
        echo "-> step 4: $0 start -> 启动k8s "
        echo "-> step 5: $0 flannel -> 启动flannel "
        echo "-> step 6: $0 dashboard -> 启动dashboard "
        echo "       unkown command $0 $@"
        ;;
    esac
}

main $@

你可能感兴趣的:(ubuntu16.04 安装 kubernetes 1.7.2)