標籤:rancher k8s
接上一篇通過Rancher部署並擴容Kubernetes叢集基礎篇一
7. 使用ConfigMap配置redis
https://github.com/kubernetes/kubernetes.github.io/blob/master/docs/user-guide/configmap/redis/redis-config
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 yamlapiVersion: v1data: redis-config: | maxmemory 2mb maxmemory-policy allkeys-lrukind: ConfigMapmetadata: 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: v1kind: Podmetadata: name: redisspec: 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-cli127.0.0.1:6379> 127.0.0.1:6379> 127.0.0.1:6379> config get maxmemory1) "maxmemory"2) "2097152"127.0.0.1:6379> config get maxmemory-policy1) "maxmemory-policy"2) "allkeys-lru"127.0.0.1:6379>
8. 使用kubectl命令管理kubernetes對象
# kubectl run nginx --image nginxdeployment "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/v1beta1kind: Deploymentmetadata: name: nginx-deploymentspec: 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叢集基礎篇二