码迷,mamicode.com
首页 > 其他好文 > 详细

K8S 通过 yaml 文件创建资源

时间:2018-11-03 22:03:06      阅读:455      评论:0      收藏:0      [点我收藏+]

标签:ada   aml   esc   mat   test   and   cal   Kubernete   desc   

创建 pod

cd ~
vi pod-demo.yaml
# 内容如下 
apiVersion: v1
kind: Pod
metadata:
  name: pod-demo
  namespace: default
  labels:
    app: myapp
    tier: frontend
spec:
  containers:
  - name: myapp
    image: ikubernetes/myapp:v1
  - name: busybox
    image: busybox:latest
    command:
    - "/bin/sh"
    - "-c"
    - "sleep 3600"

# 使用 kubectl create 创建 pod
kubectl create -f pod-demo.yaml

# 这个 pod 里面有两个容器,一个是 myapp,一个是 busybox
# 查看日志
kubectl logs pod-demo myapp

# 进入 pod 中的容器内部
kubectl exec -it pod-demo -c myapp -- /bin/sh

创建 deployment

vi deploy-demo.yaml
# 内容如下 
apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp-deploy
  namespace: default
spec:
  replicas: 2
  selector:
    matchLabels:
      app: myapp
      release: canary
  template:
    metadata:
      labels:
        app: myapp
        release: canary
    spec:
      containers:
      - name: myapp
        image: ikubernetes/myapp:v1
        ports:
        - name: http
          containerPort: 80

# 使用 kubectl apply 创建 deployment
kubectl apply -f deploy-demo.yaml 

技术分享图片
技术分享图片

# 通过 kubectl describe 查看 deployment 信息
kubectl describe deploy myapp-deploy

创建 DeamonSet

vi ds-demo.yaml 
# 内容如下
apiVersion: apps/v1
kind: Deployment
metadata:
  name: redis
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      app: redis
      role: logstor
  template:
    metadata:
      labels:
        app: redis
        role: logstor
    spec:
      containers:
      - name: redis
        image: redis:4.0-alpine
        ports:
        - name: redis
          containerPort: 6379

---
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: myapp-ds
  namespace: default
spec:
  selector:
    matchLabels:
      app: filebeat
      release: stable
  template:
    metadata:
      labels:
        app: filebeat
        release: stable
    spec:
      containers:
      - name: filebeat
        image: ikubernetes/filebeat:5.6.5-alpine
        env:
        - name: REDIS_HOST
          value: redis.default.svc.cluster.local
        - name: REDIS_LOG_LEVEL
          value: info

K8S 通过 yaml 文件创建资源

标签:ada   aml   esc   mat   test   and   cal   Kubernete   desc   

原文地址:https://www.cnblogs.com/klvchen/p/9901514.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!