Kubernetes安裝記

首先安裝3臺虛擬機

  • 使用virtualbox
  • 使用centos minimal安裝iso
  • 每臺虛擬機能夠連接google
  • 每臺虛擬機兩個網(wǎng)卡

設置http和https的代理:

export http_proxy=http://192.168.99.1:1087;export https_proxy=http://192.168.99.1:1087;
export no_proxy="127.0.0.1,192.168.99.0/24,localhost,10.96.0.0/12,10.244.0.0/16"

取消的話使用:

unset http_proxy;
unset https_proxy;

在virtualbox里面航邢,選擇創(chuàng)建虛擬機叼丑,linux->redhat 64
內(nèi)存設置為4096
硬盤位動態(tài)分配,20G

創(chuàng)建完成之后,進入該虛擬機的設置是掰,選擇network,打開第二張網(wǎng)卡辙浑,設置為hostonly adapter
選擇display升略,將Graphics Controller設置為VBoxVGA。不然進入安裝系統(tǒng)界面的時候看不到鼠標蔼夜。

啟動虛擬機兼耀,安裝centos系統(tǒng):

  • 時區(qū)設置,中國上海
  • 分區(qū)設置
  • 網(wǎng)絡設置求冷,設置節(jié)點名翠订,打開兩個網(wǎng)卡

安裝完成之后,設置靜態(tài)ip:

BOOTPROTO="static"         # 使用靜態(tài)IP地址遵倦,默認為dhcp
IPADDR="192.168.241.100"   # 設置的靜態(tài)IP地址
NETMASK="255.255.255.0"    # 子網(wǎng)掩碼
GATEWAY="192.168.241.2"    # 網(wǎng)關地址

設置時區(qū):

timedatectl set-timezone Asia/Shanghai

安裝kubernetes:

  • 禁用機器的swap:
sudo swapoff -a 
sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab

yum update 進行更新

關閉selinux

* vi /etc/selinux/config
* SELINUX=disabled
* reboot
* 使用/usr/sbin/sestatus -v查看selinux狀態(tài)

關閉firewalld

systemctl stop firewalld.service
systemctl disable firewalld.service
firewall-cmd --state

安裝docker和containerd

根據(jù)官方文檔安裝docker daemon

sudo systemctl start docker
sudo systemctl enable docker

為docker增加http proxy:

sudo mkdir -p /etc/systemd/system/docker.service.d
vi /etc/systemd/system/docker.service.d/http-proxy.conf

[Service]    
Environment="HTTP_PROXY=http://192.168.99.1:1087/" "HTTPS_PROXY=http://192.168.99.1:1087/"  "NO_PROXY=localhost,127.0.0.1,192.168.99.0/24,.corp,10.96.0.0/12,10.244.0.0/16"

sudo systemctl daemon-reload
sudo systemctl restart docker

在所有機器上安裝:

  • kubeadm
  • kubelet
  • kubectl

首先增加kubernetes的yum repo:

cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
exclude=kube*
EOF

使用yum安裝:

yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes
systemctl enable --now kubelet

iptable設置:

cat <<EOF >  /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system

使用kubeadm init進行安裝:

kubeadm init --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=192.168.99.110

kubeadm輸出:


[init] Using Kubernetes version: v1.13.3
[preflight] Running pre-flight checks
    [WARNING Firewalld]: firewalld is active, please ensure ports [6443 10250] are open or your cluster may not function correctly
    [WARNING HTTPProxy]: Connection to "https://192.168.99.110" uses proxy "http://192.168.99.1:1087". If that is not intended, adjust your proxy settings
    [WARNING HTTPProxyCIDR]: connection to "10.96.0.0/12" uses proxy "http://192.168.99.1:1087". This may lead to malfunctional cluster setup. Make sure that Pod and Services IP ranges specified correctly as exceptions in proxy configuration
    [WARNING HTTPProxyCIDR]: connection to "10.244.0.0/16" uses proxy "http://192.168.99.1:1087". This may lead to malfunctional cluster setup. Make sure that Pod and Services IP ranges specified correctly as exceptions in proxy configuration
    [WARNING SystemVerification]: this Docker version is not on the list of validated versions: 18.09.2. Latest validated version: 18.06
    [WARNING Hostname]: hostname "master" could not be reached
    [WARNING Hostname]: hostname "master": lookup master on 192.168.0.1:53: no such host
[preflight] Pulling images required for setting up a Kubernetes cluster
[preflight] This might take a minute or two, depending on the speed of your internet connection
[preflight] You can also perform this action in beforehand using 'kubeadm config images pull'
[kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
[kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
[kubelet-start] Activating the kubelet service
[certs] Using certificateDir folder "/etc/kubernetes/pki"
[certs] Generating "etcd/ca" certificate and key
[certs] Generating "apiserver-etcd-client" certificate and key
[certs] Generating "etcd/server" certificate and key
[certs] etcd/server serving cert is signed for DNS names [master localhost] and IPs [192.168.99.110 127.0.0.1 ::1]
[certs] Generating "etcd/peer" certificate and key
[certs] etcd/peer serving cert is signed for DNS names [master localhost] and IPs [192.168.99.110 127.0.0.1 ::1]
[certs] Generating "etcd/healthcheck-client" certificate and key
[certs] Generating "ca" certificate and key
[certs] Generating "apiserver" certificate and key
[certs] apiserver serving cert is signed for DNS names [master kubernetes kubernetes.default kubernetes.default.svc kubernetes.default.svc.cluster.local] and IPs [10.96.0.1 192.168.99.110]
[certs] Generating "apiserver-kubelet-client" certificate and key
[certs] Generating "front-proxy-ca" certificate and key
[certs] Generating "front-proxy-client" certificate and key
[certs] Generating "sa" key and public key
[kubeconfig] Using kubeconfig folder "/etc/kubernetes"
[kubeconfig] Writing "admin.conf" kubeconfig file
[kubeconfig] Writing "kubelet.conf" kubeconfig file
[kubeconfig] Writing "controller-manager.conf" kubeconfig file
[kubeconfig] Writing "scheduler.conf" kubeconfig file
[control-plane] Using manifest folder "/etc/kubernetes/manifests"
[control-plane] Creating static Pod manifest for "kube-apiserver"
[control-plane] Creating static Pod manifest for "kube-controller-manager"
[control-plane] Creating static Pod manifest for "kube-scheduler"
[etcd] Creating static Pod manifest for local etcd in "/etc/kubernetes/manifests"
[wait-control-plane] Waiting for the kubelet to boot up the control plane as static Pods from directory "/etc/kubernetes/manifests". This can take up to 4m0s
[kubelet-check] Initial timeout of 40s passed.

卡在這個地方尽超,估計是鏡像拉不下來,單獨拉鏡像梧躺。

kubeadm config images pull的輸出:

[root@master ~]# kubeadm config images pull
[config/images] Pulled k8s.gcr.io/kube-apiserver:v1.13.3
[config/images] Pulled k8s.gcr.io/kube-controller-manager:v1.13.3
[config/images] Pulled k8s.gcr.io/kube-scheduler:v1.13.3
[config/images] Pulled k8s.gcr.io/kube-proxy:v1.13.3
[config/images] Pulled k8s.gcr.io/pause:3.1
[config/images] Pulled k8s.gcr.io/etcd:3.2.24
[config/images] Pulled k8s.gcr.io/coredns:1.2.6

成功時候的輸出:

[root@master ~]# kubeadm init --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=192.168.99.110
[init] Using Kubernetes version: v1.13.3
[preflight] Running pre-flight checks
    [WARNING SystemVerification]: this Docker version is not on the list of validated versions: 18.09.2. Latest validated version: 18.06
[preflight] Pulling images required for setting up a Kubernetes cluster
[preflight] This might take a minute or two, depending on the speed of your internet connection
[preflight] You can also perform this action in beforehand using 'kubeadm config images pull'
[kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
[kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
[kubelet-start] Activating the kubelet service
[certs] Using certificateDir folder "/etc/kubernetes/pki"
[certs] Generating "etcd/ca" certificate and key
[certs] Generating "etcd/healthcheck-client" certificate and key
[certs] Generating "apiserver-etcd-client" certificate and key
[certs] Generating "etcd/server" certificate and key
[certs] etcd/server serving cert is signed for DNS names [master localhost] and IPs [192.168.99.110 127.0.0.1 ::1]
[certs] Generating "etcd/peer" certificate and key
[certs] etcd/peer serving cert is signed for DNS names [master localhost] and IPs [192.168.99.110 127.0.0.1 ::1]
[certs] Generating "ca" certificate and key
[certs] Generating "apiserver" certificate and key
[certs] apiserver serving cert is signed for DNS names [master kubernetes kubernetes.default kubernetes.default.svc kubernetes.default.svc.cluster.local] and IPs [10.96.0.1 192.168.99.110]
[certs] Generating "apiserver-kubelet-client" certificate and key
[certs] Generating "front-proxy-ca" certificate and key
[certs] Generating "front-proxy-client" certificate and key
[certs] Generating "sa" key and public key
[kubeconfig] Using kubeconfig folder "/etc/kubernetes"
[kubeconfig] Writing "admin.conf" kubeconfig file
[kubeconfig] Writing "kubelet.conf" kubeconfig file
[kubeconfig] Writing "controller-manager.conf" kubeconfig file
[kubeconfig] Writing "scheduler.conf" kubeconfig file
[control-plane] Using manifest folder "/etc/kubernetes/manifests"
[control-plane] Creating static Pod manifest for "kube-apiserver"
[control-plane] Creating static Pod manifest for "kube-controller-manager"
[control-plane] Creating static Pod manifest for "kube-scheduler"
[etcd] Creating static Pod manifest for local etcd in "/etc/kubernetes/manifests"
[wait-control-plane] Waiting for the kubelet to boot up the control plane as static Pods from directory "/etc/kubernetes/manifests". This can take up to 4m0s
[apiclient] All control plane components are healthy after 18.502503 seconds
[uploadconfig] storing the configuration used in ConfigMap "kubeadm-config" in the "kube-system" Namespace
[kubelet] Creating a ConfigMap "kubelet-config-1.13" in namespace kube-system with the configuration for the kubelets in the cluster
[patchnode] Uploading the CRI Socket information "/var/run/dockershim.sock" to the Node API object "master" as an annotation
[mark-control-plane] Marking the node master as control-plane by adding the label "node-role.kubernetes.io/master=''"
[mark-control-plane] Marking the node master as control-plane by adding the taints [node-role.kubernetes.io/master:NoSchedule]
[bootstrap-token] Using token: 77dklp.ma1npwcluyzzk6xv
[bootstrap-token] Configuring bootstrap tokens, cluster-info ConfigMap, RBAC Roles
[bootstraptoken] configured RBAC rules to allow Node Bootstrap tokens to post CSRs in order for nodes to get long term certificate credentials
[bootstraptoken] configured RBAC rules to allow the csrapprover controller automatically approve CSRs from a Node Bootstrap Token
[bootstraptoken] configured RBAC rules to allow certificate rotation for all node client certificates in the cluster
[bootstraptoken] creating the "cluster-info" ConfigMap in the "kube-public" namespace
[addons] Applied essential addon: CoreDNS
[addons] Applied essential addon: kube-proxy

Your Kubernetes master has initialized successfully!

To start using your cluster, you need to run the following as a regular user:

  mkdir -p $HOME/.kube
  sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  sudo chown $(id -u):$(id -g) $HOME/.kube/config

You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
  https://kubernetes.io/docs/concepts/cluster-administration/addons/

You can now join any number of machines by running the following on each node
as root:

  kubeadm join 192.168.99.110:6443 --token 77dklp.ma1npwcluyzzk6xv --discovery-token-ca-cert-hash sha256:d5f6bb873da3295f409ddee1289559d6205b807af98fae22e8f390f1fa213bce

作為root運行kubectl:

export KUBECONFIG=/etc/kubernetes/admin.conf

安裝flannel:

sysctl net.bridge.bridge-nf-call-iptables=1
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/a70459be0084506e4ec919aa1c114638878db11b/Documentation/kube-flannel.yml

添加node:

kubeadm join 192.168.99.110:6443 --token 77dklp.ma1npwcluyzzk6xv --discovery-token-ca-cert-hash sha256:d5f6bb873da3295f409ddee1289559d6205b807af98fae22e8f390f1fa213bce
[preflight] Running pre-flight checks
    [WARNING SystemVerification]: this Docker version is not on the list of validated versions: 18.09.2. Latest validated version: 18.06
    [WARNING HTTPProxy]: Connection to "https://192.168.99.110" uses proxy "http://192.168.99.1:1087". If that is not intended, adjust your proxy settings
[discovery] Trying to connect to API Server "192.168.99.110:6443"
[discovery] Created cluster-info discovery client, requesting info from "https://192.168.99.110:6443"
[discovery] Requesting info from "https://192.168.99.110:6443" again to validate TLS against the pinned public key
[discovery] Cluster info signature and contents are valid and TLS certificate validates against pinned roots, will use API Server "192.168.99.110:6443"
[discovery] Successfully established connection with API Server "192.168.99.110:6443"
[join] Reading configuration from the cluster...
[join] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -oyaml'
[kubelet] Downloading configuration for the kubelet from the "kubelet-config-1.13" ConfigMap in the kube-system namespace
[kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
[kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
[kubelet-start] Activating the kubelet service
[tlsbootstrap] Waiting for the kubelet to perform the TLS Bootstrap...
[patchnode] Uploading the CRI Socket information "/var/run/dockershim.sock" to the Node API object "node1" as an annotation

This node has joined the cluster:
* Certificate signing request was sent to apiserver and a response was received.
* The Kubelet was informed of the new secure connection details.

Run 'kubectl get nodes' on the master to see this node join the cluster.

安裝helm

  • 根據(jù)官網(wǎng)的知道教程似谁,其實就是下了一個tar包,解壓就可以看到helm的二進制文件了
  • 安裝tiller掠哥,直接helm init

之后出現(xiàn):

[root@master ~]# helm install --name my-release stable/tomcat
Error: release my-release failed: namespaces "default" is forbidden: User "system:serviceaccount:kube-system:default" cannot get resource "namespaces" in API group "" in the namespace "default"

是RBAC的權限問題巩踏。解決:
創(chuàng)建rbac-config.yaml:

apiVersion: v1
kind: ServiceAccount
metadata:
  name: tiller
  namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: tiller
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
  - kind: ServiceAccount
    name: tiller
    namespace: kube-system

然后

$ kubectl create -f rbac-config.yaml
serviceaccount "tiller" created
clusterrolebinding "tiller" created
$ helm init --service-account tiller

發(fā)現(xiàn)helm install還是不行,于是:

helm init --service-account tiller --upgrade

執(zhí)行完之后tiller pod重啟续搀,然后再helm install就ok了的

至此kubernetes和helm就安裝好了塞琼。

安裝完成之后

查看kube-system命名空間中的pod:

[root@master ~]# kubectl get pods -n kube-system -o wide
NAME                             READY   STATUS    RESTARTS   AGE   IP               NODE     NOMINATED NODE   READINESS GATES
coredns-86c58d9df4-jpbvn         1/1     Running   12         59d   10.244.0.26      master   <none>           <none>
coredns-86c58d9df4-jvtdb         1/1     Running   13         59d   10.244.0.27      master   <none>           <none>
etcd-master                      1/1     Running   14         59d   192.168.99.110   master   <none>           <none>
kube-apiserver-master            1/1     Running   14         59d   192.168.99.110   master   <none>           <none>
kube-controller-manager-master   1/1     Running   12         59d   192.168.99.110   master   <none>           <none>
kube-flannel-ds-amd64-6jxs4      1/1     Running   1          24h   192.168.99.111   node1    <none>           <none>
kube-flannel-ds-amd64-l7nx9      1/1     Running   1          24h   192.168.99.110   master   <none>           <none>
kube-flannel-ds-amd64-mk2s6      1/1     Running   1          24h   192.168.99.112   node2    <none>           <none>
kube-proxy-hhn9w                 1/1     Running   12         59d   192.168.99.110   master   <none>           <none>
kube-proxy-hj2mv                 1/1     Running   10         59d   192.168.99.112   node2    <none>           <none>
kube-proxy-qqrzn                 1/1     Running   10         59d   192.168.99.111   node1    <none>           <none>
kube-scheduler-master            1/1     Running   13         59d   192.168.99.110   master   <none>           <none>
tiller-deploy-dbb85cb99-fr5th    1/1     Running   6          46d   10.244.1.35      node1    <none>           <none>

根據(jù)kubernetes的文檔,master節(jié)點上有:

  • kube-apiserver禁舷,
  • etcd
  • kube-scheduler
  • kube-controller-manager
  • coredns

node節(jié)點上有:

  • kubelet
  • kube-proxy
  • container runtime

可以看到除了kubelet是以進程的形式運行在節(jié)點上彪杉,其余的組件都是以pod的形式運行的毅往。

安裝kubernetes dashboard

使用命令:

kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/master/aio/deploy/recommended/kubernetes-dashboard.yaml

secret/kubernetes-dashboard-certs created
secret/kubernetes-dashboard-csrf created
serviceaccount/kubernetes-dashboard created
role.rbac.authorization.k8s.io/kubernetes-dashboard-minimal created
rolebinding.rbac.authorization.k8s.io/kubernetes-dashboard-minimal created
deployment.apps/kubernetes-dashboard created
service/kubernetes-dashboard created
最后編輯于
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市派近,隨后出現(xiàn)的幾起案子攀唯,更是在濱河造成了極大的恐慌,老刑警劉巖渴丸,帶你破解...
    沈念sama閱讀 217,406評論 6 503
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件侯嘀,死亡現(xiàn)場離奇詭異,居然都是意外死亡谱轨,警方通過查閱死者的電腦和手機戒幔,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,732評論 3 393
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來土童,“玉大人溪食,你說我怎么就攤上這事∧壬龋” “怎么了错沃?”我有些...
    開封第一講書人閱讀 163,711評論 0 353
  • 文/不壞的土叔 我叫張陵,是天一觀的道長雀瓢。 經(jīng)常有香客問我枢析,道長,這世上最難降的妖魔是什么刃麸? 我笑而不...
    開封第一講書人閱讀 58,380評論 1 293
  • 正文 為了忘掉前任醒叁,我火速辦了婚禮,結果婚禮上泊业,老公的妹妹穿的比我還像新娘把沼。我一直安慰自己,他們只是感情好吁伺,可當我...
    茶點故事閱讀 67,432評論 6 392
  • 文/花漫 我一把揭開白布饮睬。 她就那樣靜靜地躺著,像睡著了一般篮奄。 火紅的嫁衣襯著肌膚如雪捆愁。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,301評論 1 301
  • 那天窟却,我揣著相機與錄音昼丑,去河邊找鬼。 笑死夸赫,一個胖子當著我的面吹牛菩帝,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 40,145評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼呼奢,長吁一口氣:“原來是場噩夢啊……” “哼宜雀!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起控妻,我...
    開封第一講書人閱讀 39,008評論 0 276
  • 序言:老撾萬榮一對情侶失蹤州袒,失蹤者是張志新(化名)和其女友劉穎揭绑,沒想到半個月后弓候,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,443評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡他匪,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,649評論 3 334
  • 正文 我和宋清朗相戀三年菇存,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片邦蜜。...
    茶點故事閱讀 39,795評論 1 347
  • 序言:一個原本活蹦亂跳的男人離奇死亡依鸥,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出悼沈,到底是詐尸還是另有隱情贱迟,我是刑警寧澤,帶...
    沈念sama閱讀 35,501評論 5 345
  • 正文 年R本政府宣布絮供,位于F島的核電站衣吠,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏壤靶。R本人自食惡果不足惜缚俏,卻給世界環(huán)境...
    茶點故事閱讀 41,119評論 3 328
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望贮乳。 院中可真熱鬧忧换,春花似錦、人聲如沸向拆。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,731評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽浓恳。三九已至才写,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間奖蔓,已是汗流浹背赞草。 一陣腳步聲響...
    開封第一講書人閱讀 32,865評論 1 269
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留吆鹤,地道東北人厨疙。 一個月前我還...
    沈念sama閱讀 47,899評論 2 370
  • 正文 我出身青樓,卻偏偏與公主長得像疑务,于是被迫代替她去往敵國和親沾凄。 傳聞我的和親對象是個殘疾皇子梗醇,可洞房花燭夜當晚...
    茶點故事閱讀 44,724評論 2 354

推薦閱讀更多精彩內(nèi)容