在虚拟机centos 7上安装kubernetes k8s

作者: 陈俊飞 分类: Linux 发布时间: 2017-08-02 11:49
  • 首先创建虚拟机

这里我们使用VM创建一个centos7 的虚拟系统。这里要注意一下的,网络设置我们先使用NAT设置。暂不要使用桥接方式

  • 安装docker

具体看参考另立一篇博客CentOS 7 Docker的安装与使用

这里我们还是只是用yum安装

[root@localhost ~]# yum install docker-io
  •  暂停firewall
[root@localhost ~]# systemctl stop firewalld
  • yum安装etcd 和kubernetes
[root@localhost ~]# yum install etcd kubernetes
  • 修改docker的配置文件
[root@localhost ~]# vim /etc/sysconfig/docker

将OPTIONS修改为

OPTIONS='--selinux-enabled=false --insecure-registry gcr.io'
  • 修改k8s的配置
vim /etc/kubernetes/apiserver
-- 删除ServiceAccount
KUBE_ADMISSION_CONTROL="--admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,SecurityContextDeny,ServiceAccount,ResourceQuota"
  • 启动相关服务
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 ~]# curl http://127.0.0.1:8080/
{
 "paths": [
 "/api",
 "/api/v1",
 "/apis",
 "/apis/apps",
 "/apis/apps/v1beta1",
 "/apis/authentication.k8s.io",
 "/apis/authentication.k8s.io/v1beta1",
 "/apis/authorization.k8s.io",
 "/apis/authorization.k8s.io/v1beta1",
 "/apis/autoscaling",
 "/apis/autoscaling/v1",
 "/apis/batch",
 "/apis/batch/v1",
 "/apis/batch/v2alpha1",
 "/apis/certificates.k8s.io",
 "/apis/certificates.k8s.io/v1alpha1",
 "/apis/extensions",
 "/apis/extensions/v1beta1",
 "/apis/policy",
 "/apis/policy/v1beta1",
 "/apis/rbac.authorization.k8s.io",
 "/apis/rbac.authorization.k8s.io/v1alpha1",
 "/apis/storage.k8s.io",
 "/apis/storage.k8s.io/v1beta1",
 "/healthz",
 "/healthz/ping",
 "/healthz/poststarthook/bootstrap-controller",
 "/healthz/poststarthook/extensions/third-party-resources",
 "/healthz/poststarthook/rbac/bootstrap-roles",
 "/logs",
 "/metrics",
 "/swaggerapi/",
 "/ui/",
 "/version"
 ]
}

kubernetes-dashboard.yaml

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
# Keep the name in sync with image version and
# gce/coreos/kube-manifests/addons/dashboard counterparts
  name: kubernetes-dashboard-latest
  namespace: kube-system
spec:
  replicas: 1
  template:
    metadata:
      labels:
        k8s-app: kubernetes-dashboard
        version: latest
        kubernetes.io/cluster-service: "true"
    spec:
      containers:
      - name: kubernetes-dashboard
        image: gcr.io/google_containers/kubernetes-dashboard-amd64:v1.5.1
        resources:
          # keep request = limit to keep this container in guaranteed class
          limits:
            cpu: 100m
            memory: 50Mi
          requests:
            cpu: 100m
            memory: 50Mi
        ports:
        - containerPort: 9090
        args:
         -  --apiserver-host=http://127.0.0.1:8080
        livenessProbe:
          httpGet:
            path: /
            port: 9090
          initialDelaySeconds: 30
          timeoutSeconds: 30
---
kind: Service
metadata:
  name: kubernetes-dashboard
  namespace: kube-system
  labels:
    k8s-app: kubernetes-dashboard
    kubernetes.io/cluster-service: "true"
spec:
  selector:
    k8s-app: kubernetes-dashboard
  ports:
  - port: 80
    targetPort: 9090

 

mysql-rc.yaml

apiVersion: v1
kind: ReplicationController
metadata:
# Keep the name in sync with image version and
# gce/coreos/kube-manifests/addons/dashboard counterparts
  name: mysql
spec:
  replicas: 1
  selector:
    app: mysql
  template:
    metadata:
      labels:
        app: mysql
    spec:
      containers:
      - name: mysql
        image: mysql
        ports:
        - containerPort: 3306
        env:
        - name: MYSQL_ROOT_PASSWORD
          value: "root"