接上一篇通过Rancher部署并扩容Kubernetes集群基础篇一
7. 使用ConfigMap配置redis
redis-config
maxmemory 2mb maxmemory-policy allkeys-lru
# kubectl create configmap example-redis-config --from-file=./redis-config
# kubectl get configmap example-redis-config -o yaml apiVersion: v1 data: redis-config: | maxmemory 2mb maxmemory-policy allkeys-lru kind: ConfigMap metadata: creationTimestamp: 2017-07-12T13:27:56Z name: example-redis-config namespace: default resourceVersion: "45707" selfLink: /api/v1/namespaces/default/configmaps/example-redis-config uid: eab522fd-6705-11e7-94da-02672b869d7f
redis-pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: redis
spec:
containers:
- name: redis
image: kubernetes/redis:v1
env:
- name: MASTER
value: "true"
ports:
- containerPort: 6379
resources:
limits:
cpu: "0.1"
volumeMounts:
- mountPath: /redis-master-data
name: data
- mountPath: /redis-master
name: config
volumes:
- name: data
emptyDir: {}
- name: config
configMap:
name: example-redis-config
items:
- key: redis-config
path: redis.conf
# kubectl create -f redis-pod.yaml pod "redis" created
# kubectl exec -it redis redis-cli 127.0.0.1:6379> 127.0.0.1:6379> 127.0.0.1:6379> config get maxmemory 1) "maxmemory" 2) "2097152" 127.0.0.1:6379> config get maxmemory-policy 1) "maxmemory-policy" 2) "allkeys-lru" 127.0.0.1:6379>
8. 使用kubectl命令管理kubernetes对象
# kubectl run nginx --image nginx deployment "nginx" created
或者
# kubectl create deployment nginx --image nginx
使用kubectl create创建一个配置文件中定义的对象
#kubectl create -f nginx.yaml
删除两个配置文件中定义的对象
#kubectl delete -f nginx.yaml -f redis.yaml
更新对象
#kubectl replace -f nginx.yaml
处理configs目录下所有的对象配置文件,创建新的对象或者打补丁现有的对象
#kubectl apply -f configs/
递推处理子目录下的对象配置文件
#kubectl apply -R -f configs/
9. 部署无状态应用
9.1 使用deployment运行一个无状态应用
deployment.yaml
apiVersion: apps/v1beta1 kind: Deployment metadata: name: nginx-deployment spec: replicas: 2 # tells deployment to run 2 pods matching the template template: # create pods using pod definition in this template metadata: # unlike pod-nginx.yaml, the name is not included in the meta data as a unique name is # generated from the deployment name labels: app: nginx spec: containers: - name: nginx image: nginx:1.7.9 ports: - containerPort: 80
kubectl create -f https://k8s.io/docs/tasks/run-application/deployment.yaml
这里需要注意一下,rancher1.6.2部署的是kubernetes 1.5.4
这里的apiVersion要改一下,改成extensions/v1beta1
kubernetes从1.6引入apps/v1beta1.Deployment 替代 extensions/v1beta1.Deployment
显示这个deployment的信息
# kubectl describe deployment nginx-deployment
10.部署有状态应用
本文出自 “Linux SA John” 博客,请务必保留此出处http://john88wang.blog.51cto.com/2165294/1946903
通过Rancher部署并扩容Kubernetes集群基础篇二
原文地址:http://john88wang.blog.51cto.com/2165294/1946903