Ubuntu 1604部署单机Kubernetes

回到老家后手边没有趁手的电脑,只有一个2003年左右的超低配置松下牌笔记本,安装了Ubuntu1604Server版虚拟环境后,在上面试着搭建Kubernetes的单机展示环境,以下是踩坑过程:

安装docker
root@googlebigtable-virtual-machine:/home/googlebigtable/Downloads# apt-get remove docker docker-engine docker-ce docker.io
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package 'docker-engine' is not installed, so not removed
Package 'docker' is not installed, so not removed
Package 'docker.io' is not installed, so not removed
The following packages will be REMOVED:
docker-ce
0 upgraded, 0 newly installed, 1 to remove and 63 not upgraded.
After this operation, 201 MB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 167732 files and directories currently installed.)
Removing docker-ce (18.06.3~ce~3-0~ubuntu) ...
docker stop/waiting
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...br/>root@googlebigtable-virtual-machine:/home/googlebigtable/Downloads#
root@googlebigtable-virtual-machine:/home/googlebigtable/Downloads# apt-get update
Hit 
http://security.ubuntu.com trusty-security InRelease
..........................................................................................................
Reading package lists... Done
root@googlebigtable-virtual-machine:/home/googlebigtable/Downloads# apt-get install -y apt-transport-https ca-certificates curl software-properties-common
Reading package lists... Done
Building dependency tree
Reading state information... Done
apt-transport-https is already the newest version.
ca-certificates is already the newest version.
curl is already the newest version.
software-properties-common is already the newest version.
software-properties-common set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 63 not upgraded.
root@googlebigtable-virtual-machine:/home/googlebigtable/Downloads# curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
OK
root@googlebigtable-virtual-machine:/home/googlebigtable/Downloads# add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
root@googlebigtable-virtual-machine:/home/googlebigtable/Downloads# apt-get update
Ign http://extras.ubuntu.com trusty InRelease
........................................................................................................................
Reading package lists... Done
root@googlebigtable-virtual-machine:/home/googlebigtable/Downloads# apt-get install -y docker-ce
Reading package lists... Done
Building dependency tree
..............................................................................................................................
Processing triggers for ureadahead (0.100.0-16) ...
root@googlebigtable-virtual-machine:/home/googlebigtable/Downloads# systemctl start docker && systemctl enable docker && systemctl status docker
systemctl: command not foundbr/>root@googlebigtable-virtual-machine:/home/googlebigtable/Downloads#
root@googlebigtable-virtual-machine:/home/googlebigtable/Downloads# apt-get install --reinstall systemd
Reading package lists... Done
Building dependency tree
.................................................................................................................................
Processing triggers for ureadahead (0.100.0-16) ...
root@googlebigtable-virtual-machine:/home/googlebigtable/Downloads# systemctl start docker && systemctl enable docker
root@googlebigtable-virtual-machine:/home/googlebigtable/Downloads# docker --version
Docker version 18.06.3-ce, build d7080c1
root@googlebigtable-virtual-machine:/home/googlebigtable/Downloads# docker info
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 18.06.3-ce
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 468a545b9edcd5932818eb9de8e72413e616e86e
runc version: a592beb5bc4c4092b1b1bac971afed27687340c5
init version: fec3683
Security Options:
apparmor
Kernel Version: 4.4.0-142-generic
Operating System: Ubuntu 14.04.6 LTS
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 3.842GiB
Name: googlebigtable-virtual-machine
ID: VBLT:KFPE:TNQZ:K5CL:GOAN:DVCD:WPY6:6AY6:YX4C:P55M:QMXO:UJBY
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: 
https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false

WARNING: No swap limit support
root@googlebigtable-virtual-machine:/home/googlebigtable/Downloads# docker version
Client:
Version: 18.06.3-ce
API version: 1.38
Go version: go1.10.3
Git commit: d7080c1
Built: Wed Feb 20 02:27:13 2019
OS/Arch: linux/amd64
Experimental: false

+-----------------+br/>root@googlebigtable-virtual-machine:/home/googlebigtable/Downloads#
root@googlebigtable-virtual-machine:/home/googlebigtable/Downloads# wget 
https://github.com/kubernetes/kubernetes/archive/v1.4.12.tar.gz
--2020-05-29 19:59:29-- https://github.com/kubernetes/kubernetes/archive/v1.4.12.tar.gz
Resolving github.com (github.com)... 52.74.223.119
Connecting to github.com (github.com)|52.74.223.119|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://codeload.github.com/kubernetes/kubernetes/tar.gz/v1.4.12 [following]
--2020-05-29 19:59:32-- https://codeload.github.com/kubernetes/kubernetes/tar.gz/v1.4.12
Resolving codeload.github.com (codeload.github.com)... 54.251.140.56
Connecting to codeload.github.com (codeload.github.com)|54.251.140.56|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [application/x-gzip]
Saving to: ‘v1.4.12.tar.gz’
[ <=> ] 7,335,298 13.5KB/s in 6m 42s
2020-05-29 20:06:17 (17.8 KB/s) - ‘v1.4.12.tar.gz’ saved [7335298]
root@googlebigtable-virtual-machine:/home/googlebigtable/Downloads# ls
v1.4.12.tar.gz vmware-tools-distribbr/>root@googlebigtable-virtual-machine:/home/googlebigtable/Downloads#
root@googlebigtable-virtual-machine:/home/googlebigtable/Downloads# tar -xzvf v1.4.12.tar.gz
...................................................................................................
root@googlebigtable-virtual-machine:/home/googlebigtable/Downloads# ls
kubernetes-1.4.12 v1.4.12.tar.gz vmware-tools-distrib
root@googlebigtable-virtual-machine:/home/googlebigtable/Downloads# mv kubernetes-1.4.12 /usr/local/
root@googlebigtable-virtual-machine:/home/googlebigtable/Downloads# cd /usr/local/
root@googlebigtable-virtual-machine:/usr/local# ls
bin etc games include kubernetes-1.4.12 lib man sbin share src
root@googlebigtable-virtual-machine:/usr/local# ifconfig -a
docker0 Link encap:Ethernet HWaddr 02:42:38:b0:3a:81
inet addr:172.17.0.1 Bcast:172.17.255.255 Mask:255.255.0.0
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

eth0 Link encap:Ethernet HWaddr 00:0c:29:87:3e:ff
inet addr:192.168.207.131 Bcast:192.168.207.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe87:3eff/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:61230 errors:0 dropped:0 overruns:0 frame:0
TX packets:26449 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:77624982 (77.6 MB) TX bytes:2305959 (2.3 MB)

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:2142 errors:0 dropped:0 overruns:0 frame:0
TX packets:2142 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:202686 (202.6 KB) TX bytes:202686 (202.6 KB)

root@googlebigtable-virtual-machine:/usr/local# ls
bin etc games include kubernetes-1.4.12 lib man sbin share src
root@googlebigtable-virtual-machine:/usr/local# cd kubernetes-1.4.12/
root@googlebigtable-virtual-machine:/usr/local/kubernetes-1.4.12# ls
api cluster contrib DESIGN.md federation hooks logo OWNERS Vagrantfile
build cmd CONTRIB.md docs Godeps labels.yaml Makefile pkg
CHANGELOG.md code-of-conduct.md CONTRIBUTING.md examples hack LICENSE Makefile.generated_files README.md
root@googlebigtable-virtual-machine:/usr/local/kubernetes-1.4.12# cd cluster/
root@googlebigtable-virtual-machine:/usr/local/kubernetes-1.4.12/cluster# ls
addons common.sh images kube-push.sh local ovirt saltbase ubuntu
aws gce juju kube-up.sh log-dump.sh OWNERS skeleton update-storage-objects.sh
azure get-kube-local.sh kubectl.sh kube-util.sh mesos photon-controller test-e2e.sh vagrant
azure-legacy get-kube.sh kube-down.sh lib openstack-heat rackspace test-network.sh validate-cluster.sh
centos gke kubemark libvirt-coreos options.md README.md test-smoke.sh vsphere
root@googlebigtable-virtual-machine:/usr/local/kubernetes-1.4.12/cluster# cd ubuntu/
root@googlebigtable-virtual-machine:/usr/local/kubernetes-1.4.12/cluster/ubuntu# ls
config-default.sh deployAddons.sh master minion namespace.yaml util.sh
config-test.sh download-release.sh master-flannel minion-flannel reconfDocker.sh
root@googlebigtable-virtual-machine:/usr/local/kubernetes-1.4.12/cluster/ubuntu# cp config-default.sh{,.original}
root@googlebigtable-virtual-machine:/usr/local/kubernetes-1.4.12/cluster/ubuntu# ls
config-default.sh config-test.sh download-release.sh master-flannel minion-flannel reconfDocker.sh
config-default.sh.original deployAddons.sh master minion namespace.yaml util.sh
root@googlebigtable-virtual-machine:/usr/local/kubernetes-1.4.12/cluster/ubuntu# gedit config-default.sh

(gedit:17616): Gtk-WARNING **: Calling Inhibit failed: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name org.gnome.SessionManager was not provided by any .service files

(gedit:17616): Gtk-WARNING **: Calling Inhibit failed: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name org.gnome.SessionManager was not provided by any .service files
root@googlebigtable-virtual-machine:/usr/local/kubernetes-1.4.12/cluster/ubuntu# cat -n config-default.sh
1 #!/bin/bash
2
3 # Copyright 2015 The Kubernetes Authors.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # 
http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 ## Contains configuration values for the Ubuntu cluster
18
19 # Define all your cluster nodes, MASTER node comes first"
20 # And separated with blank space like <user_1@ip_1> <user_2@ip_2> <user_3@ip_3>
21 export nodes=${nodes:-"vcap@10.10.103.250 vcap@10.10.103.162 vcap@10.10.103.223"}
22
23 # Define all your nodes role: a(master) or i(minion) or ai(both master and minion),
24 # Roles must be the same order with the nodes.
25 roles=${roles:-"ai i i"}
26 # If it practically impossible to set an array as an environment variable
27 # from a script, so assume variable is a string then convert it to an array
28 export roles_array=($roles)
29
30 # Define minion numbers
31 export NUM_NODES=${NUM_NODES:-3}
32 # define the IP range used for service cluster IPs.
33 # according to rfc 1918 ref: https://tools.ietf.org/html/rfc1918 choose a private ip range here.
34 export SERVICE_CLUSTER_IP_RANGE=${SERVICE_CLUSTER_IP_RANGE:-192.168.3.0/24} # formerly PORTAL_NET
35 # define the IP range used for flannel overlay network, should not conflict with above SERVICE_CLUSTER_IP_RANGE
36
37 # The Ubuntu scripting supports two ways of networking: Flannel and
38 # CNI. To use CNI: (1) put a CNI configuration file, whose basename
39 # is the configured network type plus ".conf", somewhere on the driver
40 # machine (the one running kube-up.sh) and set CNI_PLUGIN_CONF to a
41 # pathname of that file, (2) put one or more executable binaries on
42 # the driver machine and set CNI_PLUGIN_EXES to a space-separated list
43 # of their pathnames, and (3) set CNI_KUBELET_TRIGGER to identify an
44 # appropriate service on which to trigger the start and stop of the
45 # kubelet on non-master machines. For (1) and (2) the pathnames may
46 # be relative, in which case they are relative to kubernetes/cluster.
47 # If either of CNI_PLUGIN_CONF or CNI_PLUGIN_EXES is undefined or has
48 # a zero length value then Flannel will be used instead of CNI.
49
50 export CNI_PLUGIN_CONF CNI_PLUGIN_EXES CNI_KUBELET_TRIGGER
51 CNI_PLUGIN_CONF=${CNI_PLUGIN_CONF:-""}
52 CNI_PLUGIN_EXES=${CNI_PLUGIN_EXES:-""}
53 CNI_KUBELET_TRIGGER=${CNI_KUBELET_TRIGGER:-networking}
54
55 # Flannel networking is used if CNI networking is not. The following
56 # variable defines the CIDR block from which cluster addresses are
57 # drawn.
58 export FLANNEL_NET=${FLANNEL_NET:-172.16.0.0/16}
59
60 # Optionally add other contents to the Flannel configuration JSON
61 # object normally stored in etcd as /coreos.com/network/config. Use
62 # JSON syntax suitable for insertion into a JSON object constructor
63 # after other field name:value pairs. For example:
64 # FLANNEL_OTHER_NET_CONFIG=', "SubnetMin": "172.16.10.0", "SubnetMax": "172.16.90.0"'
65
66 export FLANNEL_OTHER_NET_CONFIG
67 FLANNEL_OTHER_NET_CONFIG=''
68
69 # Admission Controllers to invoke prior to persisting objects in cluster
70 # If we included ResourceQuota, we should keep it at the end of the list to prevent incremeting quota usage prematurely.
71 export ADMISSION_CONTROL=NamespaceLifecycle,LimitRanger,ServiceAccount,SecurityContextDeny,DefaultStorageClass,ResourceQuota
72
73 # Path to the config file or directory of files of kubelet
74 export KUBELET_CONFIG=${KUBELET_CONFIG:-""}
75
76 # A port range to reserve for services with NodePort visibility
77 SERVICE_NODE_PORT_RANGE=${SERVICE_NODE_PORT_RANGE:-"30000-32767"}
78
79 # Optional: Enable node logging.
80 ENABLE_NODE_LOGGING=false
81 LOGGING_DESTINATION=${LOGGING_DESTINATION:-elasticsearch}
82
83 # Optional: When set to true, Elasticsearch and Kibana will be setup as part of the cluster bring up.
84 ENABLE_CLUSTER_LOGGING=false
85 ELASTICSEARCH_LOGGING_REPLICAS=${ELASTICSEARCH_LOGGING_REPLICAS:-1}
86
87 # Optional: When set to true, heapster, Influxdb and Grafana will be setup as part of the cluster bring up.
88 ENABLE_CLUSTER_MONITORING="${KUBE_ENABLE_CLUSTER_MONITORING:-true}"
89
90 # Extra options to set on the Docker command line. This is useful for setting
91 # --insecure-registry for local registries.
92 DOCKER_OPTS=${DOCKER_OPTS:-""}
93
94 # Extra options to set on the kube-proxy command line. This is useful
95 # for selecting the iptables proxy-mode, for example.
96 KUBE_PROXY_EXTRA_OPTS=${KUBE_PROXY_EXTRA_OPTS:-""}
97
98 # Optional: Install cluster DNS.
99 ENABLE_CLUSTER_DNS="${KUBE_ENABLE_CLUSTER_DNS:-true}"
100 # DNS_SERVER_IP must be a IP in SERVICE_CLUSTER_IP_RANGE
101 DNS_SERVER_IP=${DNS_SERVER_IP:-"192.168.3.10"}
102 DNS_DOMAIN=${DNS_DOMAIN:-"cluster.local"}
103 DNS_REPLICAS=${DNS_REPLICAS:-1}
104
105 # Optional: Install Kubernetes UI
106 ENABLE_CLUSTER_UI="${KUBE_ENABLE_CLUSTER_UI:-true}"
107
108 # Optional: Enable setting flags for kube-apiserver to turn on behavior in active-dev
109 #RUNTIME_CONFIG=""
110
111 # Optional: Add http or https proxy when download easy-rsa.
112 # Add environment variable separated with blank space like "http_proxy=http://10.x.x.x:8080 https_proxy=https://10.x.x.x:8443"
113 PROXY_SETTING=${PROXY_SETTING:-""}
114
115 # Optional: Allows kublet/kube-api to be run in privileged mode
116 ALLOW_PRIVILEGED=${ALLOW_PRIVILEGED:-"false"}
117
118 DEBUG=${DEBUG:-"false"}
119
120 # Add SSH_OPTS: Add this to config ssh port
121 SSH_OPTS="-oPort=22 -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null -oLogLevel=ERROR"
122
123 #node信息,默认配置文件由三个物理node组成,其中第一个node既是master,也是slave,后两个是slave。也可以选择不填写
124 export nodes=${nodes:-"vcap@192.168.207.131 vcap@192.168.207.132 vcap@192.168.207.133"}
125 # a表示Master,s表示slave
126 roles=${roles:-"as s s"}
127
128 # slave node个数
129 export NUM_NODES=${NUM_NODES:-3}
130
131 ##根据实际情况修改,其中export nodes是待安装Kubernetes的机器地址和无密码登录的用户。本次只有一个节点,既是Master 又是 slave:
132
133 # 192.168.207.131为本机ip地址
134 export nodes=${nodes:-"root@192.168.207.131"}
135 roles=${roles:-"as"}
136 export NUM_NODES=${NUM_NODES:-1}
root@googlebigtable-virtual-machine:/usr/local/kubernetes-1.4.12/cluster/ubuntu# cp download-release.sh{,.original}
root@googlebigtable-virtual-machine:/usr/local/kubernetes-1.4.12/cluster/ubuntu# gedit download-release.sh
.............................................................................................................
67 #if [ -z "$KUBE_VERSION" ]; then
68 # KUBE_VERSION=$(get_latest_version_number | sed 's/^v//')
69 #fi
70 KUBE_VERSION=1.4.12
【禁止下载github上最新发布的Kubernetes版本,直接下载v1.4.12版】
root@googlebigtable-virtual-machine:/usr/local/kubernetes-1.4.12/cluster/ubuntu# ls -F
config-default.sh config-test.sh download-release.sh~ master-flannel/ namespace.yaml
config-default.sh~ deployAddons.sh download-release.sh.original minion/ reconfDocker.sh
config-default.sh.original download-release.sh master/ minion-flannel/ util.sh*
root@googlebigtable-virtual-machine:/usr/local/kubernetes-1.4.12/cluster/ubuntu# ./download-release.sh
/usr/local/kubernetes-1.4.12/cluster/ubuntu /usr/local/kubernetes-1.4.12/cluster/ubuntu
Prepare flannel 0.5.5 release ...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 643 100 643 0 0 709 0 --:--:-- --:--:-- --:--:-- 708
..............................................................................................................................................
root@googlebigtable-virtual-machine:/usr/local/kubernetes-1.4.12/cluster# ./kube-up.sh
... Starting cluster using provider: ubuntu
... calling verify-prereqs
Identity added: /root/.ssh/id_rsa (/root/.ssh/id_rsa)
... calling kube-up
/usr/local/kubernetes-1.4.12/cluster/ubuntu /usr/local/kubernetes-1.4.12/cluster
Prepare flannel 0.5.5 release ...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 643 100 643 0 0 692 0 --:--:-- --:--:-- --:--:-- 692
..........................................................................................................................................
Cluster validation successded
Done,listing cluster services:

kubernetes master is running at http://192.168.207.131:8080

To further debug and diagnose cluster problems,use 'kubectl cluster-info dump'.br/>root@googlebigtable-virtual-machine:/usr/local/kubernetes-1.4.12/cluster#
【注意:执行/usr/local/kubernetes-1.4.12/cluster/ubuntu/ download-release.sh成功并下载etcd、flannel、Kubernetes完毕后,将/usr/local/kubernetes-1.4.12/cluster/ubuntu/ download-release.sh清空,因为 /usr/local/kubernetes-1.4.12/cluster/kube-up.sh 会调用/usr/local/kubernetes-1.4.12/cluster/ubuntu/ download-release.sh并执行下载任务】
【在浏览器中输入http://192.168.207.131:8080可发现Kubernetes集群已经启动成功】

孟伯,20200529

交流联系:微信 1807479153 ,QQ 1807479153

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值