systemctl disable firewalld
systemctl stop firewalld

#install
yum install -y etcd kubernetes

#start
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

 

#mysql-rc.yaml

apiVersion: v1
kind: ReplicationController                            #副本控制器RC
metadata:
  name: mysql                                          #RC的名称,全局唯一
spec:
  replicas: 1                                          #Pod副本的期待数量
  selector:
    app: mysql                                         #符合目标的Pod拥有此标签
  template:                                            #根据此模板创建Pod的副本(实例)
    metadata:
      labels:
        app: mysql                                     #Pod副本拥有的标签,对应RC的Selector
    spec:
      containers:                                      #Pod内容器的定义部分
      - name: mysql                                    #容器的名称
        image: hub.c.163.com/library/mysql              #容器对应的Docker image
        ports: 
        - containerPort: 3306                          #容器应用监听的端口号
        env:                                           #注入容器内的环境变量
        - name: MYSQL_ROOT_PASSWORD 
          value: "123456"
kubectl create -f mysql-rc.yaml

kubectl get rc

kubectl get pods


# 删除
kubectl delete -f mysql-rc.yaml


# 如果pod没启动 可以查看信息
kubectl describe pods ${podName}

 



# mysql-svc.yaml
# 外网通过 docker主机IP+30306端口访问
apiVersion: v1
kind: Service
metadata:
  name: mysql
spec:
  type: NodePort
  ports:
    - port: 3306
      nodePort: 30306
  selector:
    app: mysql


kubectl create -f mysql-svc.yaml
 
kubectl get svc

kubectl get services