1.系统配置

centos7.5

docker 1.13.1 centos7下安装docker

2.关闭防火墙,selinux,swapoff

systemctl disable firewalld #停止firewall
systemctl stop firewalld #禁止firewall开机启动
firewall-cmd --state #查看防火墙状态
swapoff -a
 
# 临时关闭
$ setenforce 0
# 永久关闭
$ vim /etc/selinux/config
SELINUX=disabled
 

3.yum安装k8s

[root@localhost yum.repos.d]# pwd
/etc/yum.repos.d
[root@localhost yum.repos.d]# cat kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=
gpgcheck=
repo_gpgcheck=
gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
[root@localhost yum.repos.d]#

安装,     安装指定版本的Kubernetes

[root@localhost yum.repos.d]#yum remove etcd kubernetes

[root@localhost yum.repos.d]# yum install -y etcd kubernetes
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.cqu.edu.cn
* extras: mirrors.nwsuaf.edu.cn
* updates: mirrors.cqu.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package etcd.x86_64 :3.3.-.el7.centos will be installed
---> Package kubernetes.x86_64 :1.5.-0.7.git269f928.el7 will be installed
--> Finished Dependency Resolution Dependencies Resolved ============================================================================================================================================================================
Package Arch Version Repository Size
============================================================================================================================================================================
Installing:
etcd x86_64 3.3.-.el7.centos extras M
kubernetes x86_64 1.5.-0.7.git269f928.el7 extras k Transaction Summary
============================================================================================================================================================================
Install Packages Total download size: M
Installed size: M
Downloading packages:
(/): kubernetes-1.5.-0.7.git269f928.el7.x86_64.rpm | kB ::
(/): etcd-3.3.-.el7.centos.x86_64.rpm | MB ::
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 1.6 MB/s | MB ::
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : kubernetes-1.5.-0.7.git269f928.el7.x86_64 /
Installing : etcd-3.3.-.el7.centos.x86_64 /
Verifying : etcd-3.3.-.el7.centos.x86_64 /
Verifying : kubernetes-1.5.-0.7.git269f928.el7.x86_64 / Installed:
etcd.x86_64 :3.3.-.el7.centos kubernetes.x86_64 :1.5.-0.7.git269f928.el7 Complete!

修改配置

/etc/sysconfig/docker 修改OPTIONS='--selinux-enabled=false --insecure-registry gcr.io'并重启docker
/etc/kubernetes/apiserver KUBE_ADMISSION_CONTROL项删除ServiceAccount
[root@localhost yum.repos.d]# vi /etc/sysconfig/docker

# /etc/sysconfig/docker

# Modify these options if you want to change the way the docker daemon runs
##OPTIONS='--selinux-enabled --log-driver=journald --signature-verification=false'
OPTIONS='--selinux-enabled=false --insecure-registry gcr.io'
if [ -z "${DOCKER_CERT_PATH}" ]; then
DOCKER_CERT_PATH=/etc/docker
fi # Do not add registries in this file anymore. Use /etc/containers/registries.conf
# instead. For more information reference the registries.conf() man page. # Location used for temporary files, such as those created by
# docker load and build operations. Default is /var/lib/docker/tmp
# Can be overriden by setting the following environment variable.
# DOCKER_TMPDIR=/var/tmp # Controls the /etc/cron.daily/docker-logrotate cron job status.
# To disable, uncomment the line below.
# LOGROTATE=false # docker-latest daemon can be used by starting the docker-latest unitfile.
# To use docker-latest client, uncomment below lines
Entering Ex mode. Type "visual" to go to Normal mode.
:wq
"/etc/sysconfig/docker" 27L, 1157C written
[root@localhost yum.repos.d]# service docker restart
Redirecting to /bin/systemctl restart docker.service
[root@localhost yum.repos.d]# vi /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="--insecure-bind-address=127.0.0.1" # 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:2379" # 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,ServiceAccount,ResourceQuota"
KUBE_ADMISSION_CONTROL="--admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,SecurityContextDeny,ResourceQuota" Entering Ex mode. Type "visual" to go to Normal mode.
:wq
"/etc/kubernetes/apiserver" 27L, 894C written

4.启动服务

启动服务:systemctl start serviceName 或者 service serviceName start
查看状态:systemctl status serviceName 或者 service serviceName status
systemctl start etcd
systemctl start docker
systemctl start kube-apiserver
systemctl start kube-controller-manager
systemctl start kube-scheduler
systemctl start kubelet
systemctl start kube-proxy

验证

[root@localhost .kube]# kubectl version
Client Version: version.Info{Major:"", Minor:"", GitVersion:"v1.10.3", GitCommit:"2bba0127d85d5a46ab4b778548be28623b32d0b0", GitTreeState:"clean", BuildDate:"2018-05-21T09:17:39Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"", Minor:"", GitVersion:"v1.5.2", GitCommit:"269f928217957e7126dc87e6adfa82242bfe5b1e", GitTreeState:"clean", BuildDate:"2017-07-03T15:31:10Z", GoVersion:"go1.7.4", Compiler:"gc", Platform:"linux/amd64"}
[root@localhost .kube]# kubectl get componentstatus
NAME STATUS MESSAGE ERROR
etcd- Healthy {"health":"true"}
scheduler Healthy ok
controller-manager Healthy ok
[root@localhost .kube]# ps -ef|grep kube
root : pts/ :: kubectl proxy --port=
kube : ? :: /usr/bin/kube-apiserver --logtostderr=true --v= --etcd-servers=http://127.0.0.1:2379 --insecure-bind-address=127.0.0.1 --allow-privileged=false --service-cluster-ip-range=10.254.0.0/16 --admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,SecurityContextDeny,ResourceQuota
kube : ? :: /usr/bin/kube-controller-manager --logtostderr=true --v= --master=http://127.0.0.1:8080
kube : ? :: /usr/bin/kube-scheduler --logtostderr=true --v= --master=http://127.0.0.1:8080
root : ? :: /usr/bin/kube-proxy --logtostderr=true --v= --master=http://127.0.0.1:8080
root      38641      1  2 10:26 ?        00:01:10 /usr/bin/kubelet --logtostderr=true --v=0 --api-servers=http://127.0.0.1:8080 --address=127.0.0.1 --hostname-override=127.0.0.1 --allow-privileged=false --pod-infra-container-image=registry.access.redhat.com/rhel7/pod-infrastructure:latest
root : pts/ :: grep --color=auto kube

[root@localhost shell]# kubectl cluster-info
Kubernetes master is running at http://localhost:8080


To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.

[root@localhost software]# kubectl get nodes
NAME STATUS AGE
127.0.0.1 Ready 1h
[root@localhost software]#

5.入门实验

先拉取纯净centos镜像 docker pull centos慢问题的解决方案

dockerfile制作自己的镜像 docker利用Dockerfile来制作镜像

部署自己的镜像


[root@localhost software]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
base_tomcat tomcat-centos 0bed71f53b94 52 minutes ago 612 MB
docker.io/centos latest 9f38484d220f 2 weeks ago 202 MB


[root@localhost software]# kubectl run myk8s-pod --image=base_tomcat --replicas=2 --port=80
deployment "myk8s-pod" created
[root@localhost software]# kubectl get pods
NAME READY STATUS RESTARTS AGE
myk8s-pod-1394982580-11h8h 0/1 ContainerCreating 0 30s
myk8s-pod-1394982580-37wlc 0/1 ContainerCreating 0 30s

[root@localhost software]# kubectl run myk8s-pod-2 --image=base_tomcat --replicas=5 --port=8070
deployment "myk8s-pod-2" created
[root@localhost software]# kubectl get pods
NAME READY STATUS RESTARTS AGE
myk8s-pod-1394982580-11h8h 0/1 ContainerCreating 0 2m
myk8s-pod-1394982580-37wlc 0/1 ContainerCreating 0 2m
myk8s-pod-2-2707079129-1305m 0/1 ContainerCreating 0 5s
myk8s-pod-2-2707079129-2nvff 0/1 ContainerCreating 0 5s
myk8s-pod-2-2707079129-dk9m5 0/1 ContainerCreating 0 5s
myk8s-pod-2-2707079129-mwn3g 0/1 ContainerCreating 0 5s
myk8s-pod-2-2707079129-r282t 0/1 ContainerCreating 0 5s

[root@localhost software]# kubectl get deployments
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
myk8s-pod 2 2 2 0 13m
myk8s-pod-2 5 5 5 0 11m

发现pod状态无论多久都是处于pending。READY字段一直是0/1,服务部署失败的原因是”中国墙“的问题导致无法下载pod启动时需要的谷歌镜像,所以我们得间接的创建所需的镜像。

补充: Pending状态表示API Server已经创建Pod,但Pod内还有一个或者多个容器没有创建,或者正在下载镜像的过程。详细的参考Pod声明周期和重启策略

查看pod信息

[root@localhost software]# kubectl describe pod myk8s-pod--11h8h
Name: myk8s-pod--11h8h
Namespace: default
Node: 127.0.0.1/127.0.0.1
Start Time: Fri, Mar :: +
Labels: pod-template-hash=
run=myk8s-pod
Status: Pending
IP:
Controllers: ReplicaSet/myk8s-pod-
Containers:
myk8s-pod:
Container ID:
Image: base_tomcat
Image ID:
Port: /TCP
State: Waiting
Reason: ContainerCreating
Ready: False
Restart Count:
Volume Mounts: <none>
Environment Variables: <none>
Conditions:
Type Status
Initialized True
Ready False
PodScheduled True
No volumes.
QoS Class: BestEffort
Tolerations: <none>
Events:
FirstSeen LastSeen Count From SubObjectPath Type Reason Message
--------- -------- ----- ---- ------------- -------- ------ -------
15m 15m {default-scheduler } Normal Scheduled Successfully assigned myk8s-pod--11h8h to 127.0.0.1
15m 4m {kubelet 127.0.0.1} Warning FailedSync Error syncing pod, skipping: failed to "StartContainer" for "POD" with ErrImagePull: "image pull failed for registry.access.redhat.com/rhel7/pod-infrastructure:latest, this may be because there are no credentials on this request. details: (open /etc/docker/certs.d/registry.access.redhat.com/redhat-ca.crt: no such file or directory)" 14m 11s {kubelet 127.0.0.1} Warning FailedSync Error syncing pod, skipping: failed to "StartContainer" for "POD" with
ImagePullBackOff: "Back-off pulling image \"registry.access.redhat.com/rhel7/pod-infrastructure:latest\"" [root@localhost software]#

##百度 pod ContainerCreating

[root@localhost shell]# docker pull registry.access.redhat.com/rhel7/pod-infrastructure:latest
Trying to pull repository registry.access.redhat.com/rhel7/pod-infrastructure ...
sha256:92d43c37297da3ab187fc2b9e9ebfb243c1110d446c783ae1b989088495db931: Pulling from registry.access.redhat.com/rhel7/pod-infrastructure
26e5ed6899db: Pull complete
66dbe984a319: Pull complete
9138e7863e08: Pull complete
Digest: sha256:92d43c37297da3ab187fc2b9e9ebfb243c1110d446c783ae1b989088495db931
Status: Image is up to date for registry.access.redhat.com/rhel7/pod-infrastructure:latest

##制作新镜像,因kubectl describe pod myk8s-pod-2-2707079129-1305m 提示找不到 docker.io/base-tomcat,那么我们就制作一个

[root@localhost registry.access.redhat.com]# docker tag base_tomcat:tomcat-centos docker.io/base-tomcat:v1

[root@localhost registry.access.redhat.com]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
base_tomcat tomcat-centos 0bed71f53b94 3 hours ago 612 MB
docker.io/base-tomcat v1 0bed71f53b94 3 hours ago 612 MB
docker.io/centos latest 9f38484d220f 2 weeks ago 202 MB
registry.access.redhat.com/rhel7/pod-infrastructure latest 99965fb98423 17 months ago 209 MB
[root@localhost registry.access.redhat.com]#

[root@localhost registry.access.redhat.com]# kubectl get pods
NAME READY STATUS RESTARTS AGE
myk8s-pod-2-2707079129-1305m 0/1 ImagePullBackOff 0 2h
myk8s-pod-2-2707079129-2nvff 0/1 ImagePullBackOff 0 2h
myk8s-pod-2-2707079129-dk9m5 0/1 ImagePullBackOff 0 2h
myk8s-pod-2-2707079129-mwn3g 0/1 ImagePullBackOff 0 2h
myk8s-pod-2-2707079129-r282t 0/1 ImagePullBackOff 0 2h
[root@localhost registry.access.redhat.com]# kubectl run myk8s-pod-3 --image=docker.io/base-tomcat:v1 --replicas=3 --port=8060
deployment "myk8s-pod-3" created
[root@localhost registry.access.redhat.com]# kubectl get pods
NAME READY STATUS RESTARTS AGE
myk8s-pod-2-2707079129-1305m 0/1 ImagePullBackOff 0 2h
myk8s-pod-2-2707079129-2nvff 0/1 ImagePullBackOff 0 2h
myk8s-pod-2-2707079129-dk9m5 0/1 ImagePullBackOff 0 2h
myk8s-pod-2-2707079129-mwn3g 0/1 ImagePullBackOff 0 2h
myk8s-pod-2-2707079129-r282t 0/1 ErrImagePull 0 2h
myk8s-pod-3-4228761222-5gdvr 1/1 Running 0 22s
myk8s-pod-3-4228761222-dngwc 1/1 Running 0 22s
myk8s-pod-3-4228761222-hl85l 1/1 Running

 

删除pod,再次查看pods,结果replication重新生成了一个pod myk8s-pod-1394982580-n8sv6 ,这样deployment myk8s-pod始终保持两个

[root@localhost software]# kubectl get pods
NAME READY STATUS RESTARTS AGE
myk8s-pod-1394982580-11h8h / ContainerCreating 17m
myk8s-pod--37wlc / ContainerCreating 17m
myk8s-pod---1305m / ContainerCreating 15m
myk8s-pod---2nvff / ContainerCreating 15m
myk8s-pod---dk9m5 / ContainerCreating 15m
myk8s-pod---mwn3g / ContainerCreating 15m
myk8s-pod---r282t / ContainerCreating 15m
[root@localhost software]# kubectl delete myk8s-pod--11h8h
error: resource(s) were provided, but no name, label selector, or --all flag specified
[root@localhost software]# kubectl delete pod myk8s-pod--11h8h
pod "myk8s-pod-1394982580-11h8h" deleted
[root@localhost software]# kubectl get pods
NAME READY STATUS RESTARTS AGE
myk8s-pod--37wlc / ContainerCreating 17m
myk8s-pod-1394982580-n8sv6 / ContainerCreating 4s
myk8s-pod---1305m / ContainerCreating 15m
myk8s-pod---2nvff / ContainerCreating 15m
myk8s-pod---dk9m5 / ContainerCreating 15m
myk8s-pod---mwn3g / ContainerCreating 15m
myk8s-pod---r282t / ContainerCreating 15m
[root@localhost software]#

删除部署myk8s-pod的服务,彻底删除pod

[root@localhost software]# kubectl get pods
NAME READY STATUS RESTARTS AGE
myk8s-pod--37wlc / ContainerCreating 20m
myk8s-pod--n8sv6 / ContainerCreating 3m
myk8s-pod---1305m / ContainerCreating 18m
myk8s-pod---2nvff / ContainerCreating 18m
myk8s-pod---dk9m5 / ContainerCreating 18m
myk8s-pod---mwn3g / ContainerCreating 18m
myk8s-pod---r282t / ContainerCreating 18m
[root@localhost software]# kubectl delete deployment myk8s-pod
deployment "myk8s-pod" deleted
[root@localhost software]# kubectl get pods
NAME READY STATUS RESTARTS AGE
myk8s-pod---1305m / ContainerCreating 19m
myk8s-pod---2nvff / ContainerCreating 19m
myk8s-pod---dk9m5 / ContainerCreating 19m
myk8s-pod---mwn3g / ContainerCreating 19m
myk8s-pod---r282t / ContainerCreating 19m
[root@localhost software]# kubectl get deployments
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
myk8s-pod- 19m

centos7.5单机yum安装kubernetes的更多相关文章

  1. centos7下使用yum安装mysql

    CentOS7的yum源中默认好像是没有mysql的.为了解决这个问题,我们要先下载mysql的repo源. 1. 下载mysql的repo源 wget http://repo.mysql.com/m ...

  2. CentOS7下使用YUM安装mariadb10

    1:由于centos7 默认使用yum安装MySQL的话就会安装mariadb,只是安装的版本停留在mariadb5.x,版本比较低.如果我们需要安装mariadb10这里就需要删除mariadb-l ...

  3. centos7下使用yum安装pip

    centos7下使用yum安装pip 首先安装epel扩展源: yum -y install epel-release 更新完成之后,就可安装pip: yum -y install python-pi ...

  4. <亲测>CentOS7中使用yum安装Nginx的方法

    CentOS7中使用yum安装Nginx的方法   最近无意间发现Nginx官方提供了Yum源.因此写个文章记录下. 1.添加源 默认情况Centos7中无Nginx的源,最近发现Nginx官网提供了 ...

  5. centos7中使用yum安装tomcat以及它的启动、停止、重启

    centos7中使用yum安装tomcat 介绍 Apache Tomcat是用于提供Java应用程序的Web服务器和servlet容器. Tomcat是Apache Software Foundat ...

  6. centos7下使用yum安装redis

    centos7下使用yum安装Redis 第一步:安装 yum –y install redis 第二步:启动 systemctl start redis.service 第三步:设置开机启动 sys ...

  7. Centos7.6使用yum安装PHP7.2

    Centos7.6使用yum安装PHP7.2 1.安装源 安装php72w,是需要配置额外的yum源地址的,否则会报错不能找到相关软件包. php高版本的yum源地址,有两部分,其中一部分是epel- ...

  8. centos7 hive 单机模式安装配置

    前言:由于只是在自己的虚拟机上进行学习,所以对hive只是进行最简单的配置,其他复杂的配置文件没有配置. 1.前提 1.1 安装配置jdk1.8 1.2 安装hadoop2.x hadoop单机模式安 ...

  9. Centos7下yum安装kubernetes

    一.前言    Kubernetes 是Google开源的容器集群管理系统,基于Docker构建一个容器的调度服务,提供资源调度.均衡容灾.服务注册.动态扩缩容等功能套件,目前centos yum源上 ...

随机推荐

  1. 【Https】Spring RestTemplete支持Https安全请求

    实现步骤 Step1: 自定义ClientHttpRequestFactory package com.example.demo.https; import org.springframework.h ...

  2. 发现TCP的一种错误----客户端连接失败(10055错误号)

    在客户端连接7302TCP端口失败,关闭程序,启动sockettool也不行,出现错误号为 10055(发现队列满了或者空间不足).通过查网上资料,发现有两个方法:设置 ( TcpTimedWaitD ...

  3. IP地址基础

    第一台计算机的名字   1946年2月14日,世界上第一台电脑ENIAC在美国宾夕法尼亚大学诞生,名叫ENIAC(爱尼阿克). 第一个网络的名字: arpanet 计算机网络定义: 物理位置不同.功能 ...

  4. 阿里云OSS图片云存储测试上传

    在开发DEMO之前首先要确定 你开发OSS服务并获取了 accessKeyId和accessKeySecret final String key = MD5.Md5(DateFormat.format ...

  5. windows10如何查看wifi密码

    1.首先,在你的电脑的右下角的WiFi的图标,右击它,选择"网络和internet设置"或者选择打开设置 :如下图 点击"更改适配器选项" 选择 WLAN选项, ...

  6. hadoop ha环境下的datanode启动报错java.lang.NumberFormatException: For input string: "10m"

    hadoop ha环境启动start-dfs.sh的时候datanode启动不了,并且报错. [hadoop@datanode2 ~]$ cat /home/hadoop/hadoop-2.7.3/l ...

  7. 卷积神经网络之GoogleNet:inceptionV3模型学习

    Rethinking the Inception Architecture for Computer Vision 论文地址:https://arxiv.org/abs/1512.00567 Abst ...

  8. 软硬链接ln

    1:软链接 -- 快捷方式 I:ln -s 文件名 快捷方式的名字 文件名:使用绝对路径 II':目录也可以创建链接 2:硬链接 I: ln 文件名 硬链接的名字

  9. pthread mutex

    pthead_mutex_t mutex; 1:create: pthread_mutex_init(pthread_mutex_t* mutex, const pthread_mutexattr_t ...

  10. spark dataFrame withColumn

    说明:withColumn用于在原有DF新增一列 1. 初始化sqlContext val sqlContext = new org.apache.spark.sql.SQLContext(sc) 2 ...