Install kubernetes

2台机器,1台为Master,1台为Node

修改Host Master为dmaster,Node为dslave

安装K8s and Etcd



在Master机器上安装

yum install etcd

yum install kubernetes 

Node机器只需要

yum install kubernetes 

安装k8s会自动安装docker,目前版本是1.8

配置K8s



Etcd默认的监听端口是4001,在这里修改

vim /etc/etcd/etcd.conf

修改Master机器K8s配置

1. apiserver配置

vim /etc/kubernetes/apiserver

###
# kubernetes system config
#
# The following values are used to configure the kube-apiserver
#

# The address on the local server to listen to.
KUBE_API_ADDRESS="--address=0.0.0.0"

# The port on the local server to listen on.
KUBE_API_PORT="--port=8080"

# Port minions listen on
KUBELET_PORT="--kubelet_port=10250"

# Comma separated list of nodes in the etcd cluster
KUBE_ETCD_SERVERS="--etcd_servers=http://127.0.0.1:4001"

# Address range to use for services
KUBE_SERVICE_ADDRESSES="--service-cluster-ip-range=10.254.0.0/16"

# default admission control policies
KUBE_ADMISSION_CONTROL="--admission_control=NamespaceLifecycle,NamespaceExists,LimitRanger,SecurityContextDeny,ResourceQuota"

# Add your own!
KUBE_API_ARGS="--secure-port=0"

2.K8s配置

vim /etc/kubernetes/config

# kubernetes system config
#
# The following values are used to configure various aspects of all
# kubernetes services, including
#
#   kube-apiserver.service
#   kube-controller-manager.service
#   kube-scheduler.service
#   kubelet.service
#   kube-proxy.service
# logging to stderr means we get it in the systemd journal
KUBE_LOGTOSTDERR="--logtostderr=true"

# journal message level, 0 is debug
KUBE_LOG_LEVEL="--v=0"

# Should this cluster be allowed to run privileged docker containers
KUBE_ALLOW_PRIV="--allow_privileged=false"

# How the controller-manager, scheduler, and proxy find the apiserver
KUBE_MASTER="--master=http://dmaster:8080"
KUBE_ETCD_SERVERS="--etcd-servers=http://dmaster:4001"

3.启动服务

systemctl enable kube-apiserver kube-controller-manager kube-scheduler

systemctl restart kube-apiserver kube-controller-manager kube-scheduler

systemctl status kube-apiserver kube-controller-manager kube-scheduler

修改Node机器配置

1. K8s配置

vim /etc/kubernetes/kubelet

# kubernetes kubelet (minion) config

# The address for the info server to serve on (set to 0.0.0.0 or "" for all interfaces)
KUBELET_ADDRESS="--address=127.0.0.1"

# The port for the info server to serve on
KUBELET_PORT="--port=10250"

# You may leave this blank to use the actual hostname
KUBELET_HOSTNAME="--hostname_override=dslave"

# location of the api-server
KUBELET_API_SERVER="--api_servers=http://dmaster:8080"

# Add your own!
KUBELET_ARGS=""

2. 启动服务

systemctl enable kube-proxy kubeletdocker

systemctl restart kube-proxy kubeletdocker

systemctl status kube-proxy kubeletdocker

新增Pod



1. 在Master机器查看Node状态

[[email protected]192 k8s]# kubectl get nodes
NAME      LABELS                          STATUS
dslave    kubernetes.io/hostname=dslave   Ready

2. 新建Pod资源文件

apiVersion: v1
kind: Pod
metadata:
  name: mysql
  labels:
    name: mysql
spec:
  containers:
    - resources:
        limits :
          cpu: 0.5
      image: mysql
      name: mysql
      env:
        - name: MYSQL_ROOT_PASSWORD
          # change this
          value: rootpwd
      ports:
        - containerPort: 3306
          name: mysql
      volumeMounts:
          # name must match the volume name below
        - name: mysql-persistent-storage
          # mount path within the container
          mountPath: /var/lib/mysql
  volumes:
    - name: mysql-persistent-storage
      cinder:
        volumeID: bd82f7e2-wece-4c01-a505-4acf60b07f4a
        fsType: ext4

3. 导入资源

kubectl create -f mysql.yaml

4. 查看资源状态

[[email protected]192 k8s]# kubectl get pods
NAME      READY     STATUS    RESTARTS   AGE
mysql     1/1       Running   0          1h

这里已经部署在运行了,所以是Running。Status开始是Ready。

5. 查看日志

Master机器日志

tail -f /var/log/messages |grepkube

Dec 11 09:54:11 192 kube-scheduler: I1211 09:54:11.380994   20445 event.go:203] Event(api.ObjectReference{Kind:"Pod", Namespace:"default", Name:"mysql", UID:"2f192467-a030-11e5-8a55-000c298cfaa1", APIVersion:"v1", ResourceVersion:"3522", FieldPath:""}): reason: ‘scheduled‘ Successfully assigned mysql to dslave

在部署Pod时,在Node机器日志中报错

Dec 11 09:30:22 dslave kubelet: E1211 09:30:22.745867   99650 manager.go:1557] Failed to create pod infra container: image pull failed for gcr.io/google_containers/pause:0.8.0, this may be because there are no credentials on this request.  details: (Network timed out while trying to connect to http://gcr.io/v1/repositories/google_containers/pause/images. You may want to check your internet connection or if you are behind a proxy.); Skipping pod "mysql_default"
Dec 11 09:30:22 dslave kubelet: E1211 09:30:22.955470   99650 pod_workers.go:111] Error syncing pod bcbb3b8a-a02a-11e5-8a55-000c298cfaa1, skipping: image pull failed for gcr.io/google_containers/pause:0.8.0, this may be because there are no credentials on this request.  details: (Network timed out while trying to connect to http://gcr.io/v1/repositories/google_containers/pause/images. You may want to check your internet connection or if you are behind a proxy.)

Google被墙了,下载资源包到本地

http://www.sunmite.com/linux/installing-kubernetes-cluster-on-centos7-to-manage-pods-and-services/attachment/pause-0-8-0/

在Node节点导入

docker load --input pause-0.8.0.tar

这是一个容器,负责Pod内部的网络

还有一个问题是权限的问题

no API token found for service account default/default, retry after the token is automatically created and added to the service account

这样即可解决

#vim /etc/kubernetes/apiserver
KUBE_ADMISSION_CONTROL="--admission_control=NamespaceLifecycle,NamespaceExists,LimitRanger,ResourceQuota"

#systemctl restart kube-apiserver.service
时间: 2024-12-28 12:50:05

Install kubernetes的相关文章

Install kubernetes without yum

下载最新版本: https://github.com/kubernetes/kubernetes/releases 下载kubernetes.tar.gz即可 解压缩后到cluster目录下 执行get-kube-binaries.sh 执行目录要控制好,这个脚本会自动下载client与server相关的文件,会自动放到kubernetes目录下 随后在相应的bin下就可以找到对应的文件 kube-apiserver kube-controller-manager kube-scheduler 

kubernetes学习笔记

docker实现了更便捷的单机容器虚拟化的管理, docker的位置处于操作系统层与应用层之间; 相对传统虚拟化(KVM,XEN): docker可以更加灵活的去实现一些应用层功能, 同时对资源的利用率也更高 相对应用: docker可以把应用更操作系统(镜像)做更好的结合, 降低部署与维护的的成本 处于这样一个位置在单机使用docker进行业务部署是可以感觉到质的提升; 但是针对跨机器, 大规模, 需要对业务质量进行保证的时候, docker本身又有些不足, 而传统的运维自动化工具无论是在do

基于 CentOS7 的 Kubernetes 集群

一.环境 相关主机 master 192.168.12.197 minion 192.168.12.198~232 etcd 192.168.12.233~236 相关软件 OS CentOS 7 软件版本: kubernetes-0.19.3 etcd-2.0.9-2.el7.x86_64 docker-1.6.0-11.0.1.el7.centos.x86_64 flannel-0.2.0-7.el7.x86_64 二.部署和配置 2.1 Prerequisites systemctl st

Docker实践(6)—CentOS7上部署Kubernetes

Kubernetes架构 Kubernetes的整体架构如下: Master为主控节点,上面运行apiserver,scheduler,controller-manager等组件.Minion相当于工作节点,上面运行kubelet,proxy,cAdvisor以及最重要的docker等组件.下面来实际部署一下这套集群管理工具. 环境 yy1  10.193.6.35 yy2  10.193.6.36 yy1作为master,yy2作为minion. # cat /etc/centos-relea

基于kubernetes构建Docker集群管理详解-转

http://blog.liuts.com/post/247/ 一.前言        Kubernetes 是Google开源的容器集群管理系统,基于Docker构建一个容器的调度服务,提供资源调度.均衡容灾.服务注册.动态扩缩容等功能套件,目前最新版本为0.6.2.本文介绍如何基于Centos7.0构建Kubernetes平台,在正式介绍之前,大家有必要先理解Kubernetes几个核心概念及其承担的功能.以下为Kubernetes的架构设计图:1. Pods        在Kuberne

centos7 kubernetes安装手册

安装之前,将三台centos7服务器禁止防火墙,同时需要启动的镜像2台node机器都要保持时间一致,否则pod不能启动 1 有三台centos7服务器:10.1.1.170(master),10.1.1.169 node1,10.1.1.171 node2 2 在三台机器上安装ntp服务,以保证所有时间可以同步 #yum -y install ntp #systemctl start ntpd #systemctl enable ntpd 3 在10.1.1.170上安装kubernetes m

Kubernetes的安装配置

1.环境准备: 三台服务器: 192.168.42.128 master+node 192.168.42.129 node1 192.168.42.130 node2 2.准备yum源 vi virt7-docker-common-release.repo [virt7-docker-common-release] name=virt7-docker-common-release baseurl=http://cbs.centos.org/repos/virt7-docker-common-re

CentOS7部署Kubernetes集群

CentOS7部署Kubernetes集群 简介 Kubernetes是什么? Kubernetes一个用于容器集群的自动化部署.扩容以及运维的开源平台. 通过Kubernetes,你可以快速有效地响应用户需求: a.快速而有预期地部署你的应用 b.极速地扩展你的应用 c.无缝对接新的应用功能 d.节省资源,优化硬件资源的使用 我们希望培育出一个组件及工具的生态,帮助大家减轻在公有云及私有云上运行应用的负担. Kubernetes特点: a.可移植: 支持公有云,私有云,混合云,多重云(mult

三、安装并配置Kubernetes Node节点

1. 安装并配置Kubernetes Node节点 1.1 安装Kubernetes Node节点所需服务 yum -y install kubernetes ? 通过yum安装kubernetes服务时默认将所有的Kubernetes服务全部安装,我们只需要在Master和Node上启动相应的服务即可. 1.2 修改Kubernetes服务配置文件 vim /etc/kubernetes/config KUBE_LOGTOSTDERR="--logtostderr=true" KUB