kubeadm 安装kubetnetes(flannel)

声明:本文参照官网进行安装,具体请前往官网查看
1.环境准备

ip hostname
192.168.1.108 master
192.168.1.107 slave
192.168.1.109 slave1

配置hosts

vi /etc/hosts

kubeadm 安装kubetnetes(flannel)_第1张图片


2.安装docker

yum install docker

3.安装kubectl
相关的bash自动补全,以及配置文件详情参考官网

curl -LO
https://storage.googleapis.com/kubernetes-release/release/$(curl -s
https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl

chmod +x ./kubectl

sudo mv ./kubectl /usr/local/bin/kubectl

4.安装kubeadm,kubelet,kubernetes-cni等工具(记得关闭防火墙,每个节 点上都要执行)

cat < /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
EOF
setenforce 0  -- 暂时关闭selinux
yum install -y docker kubelet kubeadm kubernetes-cni
systemctl enable docker && systemctl start docker
systemctl enable kubelet && systemctl start kubelet
[root@master hosts]# kubeadm version
kubeadm version: version.Info{Major:"1", Minor:"6", GitVersion:"v1.6.6", GitCommit:"7fa1c1756d8bc963f1a389f4a6937dc71f08ada2", GitTreeState:"clean", BuildDate:"2017-06-16T18:21:54Z", GoVersion:"go1.7.6", Compiler:"gc", Platform:"linux/amd64"}

5.执行 kubeadm init 初始化集群master

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

[root@master kubernetes]# kubeadm init --apiserver-advertise-address 192.168.1.108 --pod-network-cidr=10.244.0.0/16
[kubeadm] WARNING: kubeadm is in beta, please do not use it for production clusters.
[init] Using Kubernetes version: v1.6.6
[init] Using Authorization mode: RBAC
[preflight] Running pre-flight checks
[preflight] WARNING: kubelet service is not enabled, please run 'systemctl enable kubelet.service'
[preflight] WARNING: docker service is not enabled, please run 'systemctl enable docker.service'
[preflight] Starting the kubelet service
[certificates] Generated CA certificate and key.
[certificates] Generated API server certificate and key.
[certificates] API Server 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.1.108]
[certificates] Generated API server kubelet client certificate and key.
[certificates] Generated service account token signing key and public key.
[certificates] Generated front-proxy CA certificate and key.
[certificates] Generated front-proxy client certificate and key.
[certificates] Valid certificates and keys now exist in "/etc/kubernetes/pki"
[kubeconfig] Wrote KubeConfig file to disk: "/etc/kubernetes/admin.conf"
[kubeconfig] Wrote KubeConfig file to disk: "/etc/kubernetes/kubelet.conf"
[kubeconfig] Wrote KubeConfig file to disk: "/etc/kubernetes/controller-manager.conf"
[kubeconfig] Wrote KubeConfig file to disk: "/etc/kubernetes/scheduler.conf"
[apiclient] Created API client, waiting for the control plane to become ready
[apiclient] All control plane components are healthy after 17.014389 seconds
[apiclient] Waiting for at least one node to register
[apiclient] First node has registered after 3.008786 seconds
[token] Using token: e025a1.74de7b5a01f581dc
[apiconfig] Created RBAC rules
[addons] Created essential addon: kube-proxy
[addons] Created essential addon: kube-dns

Your Kubernetes master has initialized successfully!

To start using your cluster, you need to run (as a regular user):

  sudo cp /etc/kubernetes/admin.conf $HOME/
  sudo chown $(id -u):$(id -g) $HOME/admin.conf
  export KUBECONFIG=$HOME/admin.conf

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

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

  kubeadm join --token e025a1.74de7b5a01f581dc 192.168.1.108:6443
  sudo cp /etc/kubernetes/admin.conf $HOME/
  sudo chown $(id -u):$(id -g) $HOME/admin.conf
  export KUBECONFIG=$HOME/admin.conf

  [root@master kubernetes]# kubectl get nodes
    NAME      STATUS     AGE       VERSION
    master    NotReady   1m        v1.6.6

用到的镜像

[root@slave hosts]# docker images 
REPOSITORY                                               TAG                 IMAGE ID            CREATED             SIZE
gcr.io/google_containers/kube-apiserver-amd64            v1.6.6              eaedf2552acd        7 days ago          150.7 MB
gcr.io/google_containers/kube-controller-manager-amd64   v1.6.6              a1b8bfeff845        7 days ago          132.9 MB
gcr.io/google_containers/kube-scheduler-amd64            v1.6.6              b662c4a72c62        7 days ago          76.75 MB
gcr.io/google_containers/etcd-amd64                      3.0.17              243830dae7dd        4 months ago        168.9 MB
gcr.io/google_containers/pause-amd64                     3.0                 99e59f495ffa        13 months ago       746.9 kB
[root@slave hosts]# 

6.安装CNI,我这里选择flannel addons
必须先创建RBAC 否侧会失败
kube-flannel-rbac.yml下载链接
kube-flannel.yml下载链接

[root@master kubernetes]# kubectl create -f rbac.yaml 
clusterrole "flannel" created
clusterrolebinding "flannel" created
[root@master kubernetes]# kubectl apply -f kube-flannel.yaml 
serviceaccount "flannel" created
configmap "kube-flannel-cfg" created
daemonset "kube-flannel-ds" created
[root@master kubernetes]# kubectl get pods -n kube-system
NAME                             READY     STATUS    RESTARTS   AGE
etcd-master                      1/1       Running   0          44m
kube-apiserver-master            1/1       Running   0          44m
kube-controller-manager-master   1/1       Running   0          44m
kube-dns-692378583-1h70j         3/3       Running   3          45m
kube-flannel-ds-n8jn0            2/2       Running   0          2m
kube-proxy-3rk7z                 1/1       Running   0          45m
kube-scheduler-master            1/1       Running   0          44m

7.添加节点

kubeadm join --token e025a1.74de7b5a01f581dc 192.168.1.108:6443
[root@slave ~]# kubeadm join --token e025a1.74de7b5a01f581dc 192.168.1.108:6443
[kubeadm] WARNING: kubeadm is in beta, please do not use it for production clusters.
[preflight] Running pre-flight checks
[preflight] WARNING: kubelet service is not enabled, please run 'systemctl enable kubelet.service'
[preflight] WARNING: docker service is not enabled, please run 'systemctl enable docker.service'
[preflight] Starting the kubelet service
[discovery] Trying to connect to API Server "192.168.1.108:6443"
[discovery] Created cluster-info discovery client, requesting info from "https://192.168.1.108:6443"
[discovery] Cluster info signature and contents are valid, will use API Server "https://192.168.1.108:6443"
[discovery] Successfully established connection with API Server "192.168.1.108:6443"
[bootstrap] Detected server version: v1.6.6
[bootstrap] The server supports the Certificates API (certificates.k8s.io/v1beta1)
[csr] Created API client to obtain unique certificate for this node, generating keys and certificate signing request
[csr] Received signed certificate from the API server, generating KubeConfig...
[kubeconfig] Wrote KubeConfig file to disk: "/etc/kubernetes/kubelet.conf"

Node join complete:
* Certificate signing request sent to master and response
  received.
* Kubelet informed of new secure connection details.

Run 'kubectl get nodes' on the master to see this machine join.
[root@slave1 ~]# kubeadm join --token e025a1.74de7b5a01f581dc 192.168.1.108:6443
[kubeadm] WARNING: kubeadm is in beta, please do not use it for production clusters.
[preflight] Running pre-flight checks
[preflight] WARNING: kubelet service is not enabled, please run 'systemctl enable kubelet.service'
[preflight] WARNING: docker service is not enabled, please run 'systemctl enable docker.service'
[preflight] Starting the kubelet service
[discovery] Trying to connect to API Server "192.168.1.108:6443"
[discovery] Created cluster-info discovery client, requesting info from "https://192.168.1.108:6443"
[discovery] Cluster info signature and contents are valid, will use API Server "https://192.168.1.108:6443"
[discovery] Successfully established connection with API Server "192.168.1.108:6443"
[bootstrap] Detected server version: v1.6.6
[bootstrap] The server supports the Certificates API (certificates.k8s.io/v1beta1)
[csr] Created API client to obtain unique certificate for this node, generating keys and certificate signing request
[csr] Received signed certificate from the API server, generating KubeConfig...
[kubeconfig] Wrote KubeConfig file to disk: "/etc/kubernetes/kubelet.conf"

Node join complete:
* Certificate signing request sent to master and response
  received.
* Kubelet informed of new secure connection details.

Run 'kubectl get nodes' on the master to see this machine join.
[root@master kubernetes]# kubectl get nodes
NAME      STATUS    AGE       VERSION
master    Ready     1h        v1.6.6
slave     Ready     5m        v1.6.6
slave1    Ready     5m        v1.6.6
[root@master kubernetes]# kubectl get pods --all-namespaces
NAMESPACE     NAME                             READY     STATUS    RESTARTS   AGE
kube-system   etcd-master                      1/1       Running   0          1h
kube-system   kube-apiserver-master            1/1       Running   0          1h
kube-system   kube-controller-manager-master   1/1       Running   0          1h
kube-system   kube-dns-692378583-1h70j         3/3       Running   3          1h
kube-system   kube-flannel-ds-43n8m            2/2       Running   0          23s
kube-system   kube-flannel-ds-btz82            2/2       Running   1          5m
kube-system   kube-flannel-ds-n8jn0            2/2       Running   0          28m
kube-system   kube-proxy-2gzvq                 1/1       Running   0          5m
kube-system   kube-proxy-31lrc                 1/1       Running   0          5m
kube-system   kube-proxy-3rk7z                 1/1       Running   0          1h
kube-system   kube-scheduler-master            1/1       Running   0          1h
[root@master kubernetes]# docker images 
REPOSITORY                                                  TAG                 IMAGE ID            CREATED             SIZE
gcr.io/google_containers/kube-proxy-amd64                   v1.6.6              b01133efa4f0        7 days ago          109 MB
gcr.io/google_containers/kube-apiserver-amd64               v1.6.6              eaedf2552acd        7 days ago          150.7 MB
gcr.io/google_containers/kube-controller-manager-amd64      v1.6.6              a1b8bfeff845        7 days ago          132.9 MB
gcr.io/google_containers/kube-scheduler-amd64               v1.6.6              b662c4a72c62        7 days ago          76.75 MB
192.168.1.113:5000/google_containers/kube-apiserver-amd64   v1.6.4              4e3810a19a64        5 weeks ago         150.6 MB
gcr.io/google_containers/k8s-dns-sidecar-amd64              1.14.2              7c4034e4ffa4        6 weeks ago         44.5 MB
gcr.io/google_containers/k8s-dns-kube-dns-amd64             1.14.2              ca8759c215c9        6 weeks ago         52.36 MB
gcr.io/google_containers/k8s-dns-dnsmasq-nanny-amd64        1.14.2              e5c335701995        6 weeks ago         44.84 MB
quay.io/coreos/flannel                                      v0.7.1-amd64        cd4ae0be5e1b        9 weeks ago         77.76 MB
gcr.io/google_containers/etcd-amd64                         3.0.17              243830dae7dd        4 months ago        168.9 MB
gcr.io/google_containers/pause-amd64                        3.0                 99e59f495ffa        13 months ago       746.9 kB

8.最后部署dashboard

Service 修改为nodePort方式,如下图


---
kind: Service
apiVersion: v1
metadata:
  labels:
    k8s-app: kubernetes-dashboard
  name: kubernetes-dashboard
  namespace: kube-system
spec:
  type: NodePort
  ports:
  - port: 80
    targetPort: 9090
    nodePort: 31001
  selector:
    k8s-app: kubernetes-dashboard
[root@master kubernetes]# kubectl get pods --all-namespaces
NAMESPACE     NAME                                    READY     STATUS    RESTARTS   AGE
kube-system   etcd-master                             1/1       Running   0          1h
kube-system   kube-apiserver-master                   1/1       Running   0          1h
kube-system   kube-controller-manager-master          1/1       Running   0          1h
kube-system   kube-dns-692378583-1h70j                3/3       Running   3          1h
kube-system   kube-flannel-ds-43n8m                   2/2       Running   0          18m
kube-system   kube-flannel-ds-btz82                   2/2       Running   1          23m
kube-system   kube-flannel-ds-n8jn0                   2/2       Running   0          46m
kube-system   kube-proxy-2gzvq                        1/1       Running   0          23m
kube-system   kube-proxy-31lrc                        1/1       Running   0          23m
kube-system   kube-proxy-3rk7z                        1/1       Running   0          1h
kube-system   kube-scheduler-master                   1/1       Running   0          1h
kube-system   kubernetes-dashboard-2039414953-sxhdl   1/1       Running   0          6m
[root@master kubernetes]# docker images 
REPOSITORY                                                  TAG                 IMAGE ID            CREATED             SIZE
gcr.io/google_containers/kube-proxy-amd64                   v1.6.6              b01133efa4f0        7 days ago          109 MB
gcr.io/google_containers/kube-controller-manager-amd64      v1.6.6              a1b8bfeff845        7 days ago          132.9 MB
gcr.io/google_containers/kube-apiserver-amd64               v1.6.6              eaedf2552acd        7 days ago          150.7 MB
gcr.io/google_containers/kube-scheduler-amd64               v1.6.6              b662c4a72c62        7 days ago          76.75 MB
192.168.1.113:5000/google_containers/kube-apiserver-amd64   v1.6.4              4e3810a19a64        5 weeks ago         150.6 MB
gcr.io/google_containers/kubernetes-dashboard-amd64         v1.6.1              71dfe833ce74        5 weeks ago         134.4 MB
gcr.io/google_containers/k8s-dns-sidecar-amd64              1.14.2              7c4034e4ffa4        6 weeks ago         44.5 MB
gcr.io/google_containers/k8s-dns-kube-dns-amd64             1.14.2              ca8759c215c9        6 weeks ago         52.36 MB
gcr.io/google_containers/k8s-dns-dnsmasq-nanny-amd64        1.14.2              e5c335701995        6 weeks ago         44.84 MB
quay.io/coreos/flannel                                      v0.7.1-amd64        cd4ae0be5e1b        9 weeks ago         77.76 MB
gcr.io/google_containers/etcd-amd64                         3.0.17              243830dae7dd        4 months ago        168.9 MB
gcr.io/google_containers/pause-amd64                        3.0                 99e59f495ffa        13 months ago       746.9 kB

kubeadm 安装kubetnetes(flannel)_第2张图片
end

你可能感兴趣的:(kubetnetes)