k8s 1.5.2 环境安装

所有节点

1.关闭防火墙

systemctl stop firewalld
systemctl disable firewalld

2.禁用SELINUX:

setenforce 0
vim /etc/selinux/config
SELINUX=disabled

3.配置hosts

echo "192.168.1.33  centos-master" >> /etc/hosts
echo "192.168.1.134 centos-minion " >> /etc/hosts

ping centos-minion
ping centos-master

4.配置yum源

cd /etc/yum.repos.d
vim kubernetes.repo

[kubernetes]
name=Kubernetes
baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
       http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg

5.安装k8s

yum -y install kubernetes flannel 

6.配置k8s flannel

vim /etc/kubernetes/config

# How the controller-manager, scheduler, and proxy find the apiserver 
KUBE_MASTER="--master=http://centos-master:8080" 

vim /etc/sysconfig/flanneld

FLANNEL_ETCD_ENDPOINTS="http://centos-master:2379"

主节点

7.主节点安装etcd

yum install etcd -y

vi /etc/etcd/etcd.conf
ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379,http://0.0.0.0:4001"

ETCD_ADVERTISE_CLIENT_URLS="http://centos-master:2379,http://centos-master:4001"

systemctl start etcd


etcdctl set testdir/testkey0 0

etcdctl get testdir/testkey0 

etcdctl -C http://etcd:4001 cluster-health

etcdctl -C http://etcd:2379 cluster-health

etcdctl mk /atomic.io/network/config '{ "Network": "10.0.0.0/16" }'

8配置主节点

Master节点上

vim /etc/kubernetes/apiserver

# The address on the local server to listen to. 
KUBE_API_ADDRESS="--address=0.0.0.0" 
KUBE_API_PORT="--port=8080" 
# Comma separated list of nodes in the etcd cluster 
KUBE_ETCD_SERVERS="--etcd_servers=http://127.0.0.1:2379"
KUBE_ADMISSION_CONTROL="-admission_control=NamespaceLifecycle,NamespaceExists,LimitRanger,Secu rityContextDeny,ResourceQuota"

9.启动主节点服务etcd kube-apiserver kube-controller-manager kube-scheduler Master执行

systemctl restart etcd kube-apiserver kube-scheduler kube-controller-manager flanneld
systemctl enable etcd kube-apiserver kube-scheduler kube-controller-manager flanneld
systemctl status etcd kube-apiserver kube-scheduler kube-controller-manager flanneld

10.查看进程

ps -ef|grep kube 

从节点

11.配置从节点

vim /etc/kubernetes/kubelet
### 
# kubernetes kubelet (minion) config 
KUBELET_ADDRESS="--address=0.0.0.0" 
KUBELET_PORT="--port=10250" 
KUBELET_HOSTNAME="--hostname_override=centos-minion" 
KUBELET_API_SERVER="--api_servers=http://centos-master:8080" 
# Add your own! 
KUBELET_ARGS=""

12.docker 启动bug

vim /etc/sysconfig/docker

linux的内核中的SELinux不支持 overlay2 graph driver ,在docker里禁用selinux,–selinux-enabled=false

12.启动从节点服务,必须保证docker服务已经安装

systemctl restart kube-proxy kubelet docker  flanneld
systemctl enable kube-proxy kubelet docker flanneld
systemctl status kube-proxy kubelet docker flanneld

主节点

13查看日志

tail -f /var/log/messages |grep kube

kubectl get nodes 

kubectl cluster-info 

14编写nginx yaml文件

vi nginx-pod.yaml
apiVersion: v1
kind: Pod 
metadata: 
   name: nginx
spec: 
    containers: 
        - name: nginx 
          image: nginx
          ports: 
             - containerPort: 80

15创建

kubectl create -f nginx-pod.yaml

16查看pods

kubectl get pods

bug
解决k8s出现pod服务一直处于ContainerCreating状态的问题的过程

从节点上执行

 yum remove *rhsm* -y
 
 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

你可能感兴趣的:(k8s)