Kubernetes常用命令

1.使用配置文件创建一个可持续高可用容器

配置文件样本

apiVersion: v1
kind: ReplicationController
metadata:
  name: my-nginx
spec:
  replicas: 3
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.7.9
        ports:
        - containerPort: 80

创建命令

kubectl create -f ./my-nginx-rc.yaml
  • 查看pod状态
kubectl get pods
  • 对资源进行配置(动态伸缩)
kubectl apply -f ./my-nginx-rc.yaml
  • 删除pods
kubectl delete pod my-nginx
  • 删除rc
kubectl delete rc my-nginx

连接应用

使用k8s的service,配置样本如下

kind: Service
apiVersion: v1
metadata:
  name: nginxsvc
spec:
  type: NodePort
  selector:
    app: nginx
  ports:
    - port: 80
      targetPort: 80
      nodePort: 32767 

你可能感兴趣的:(Kubernetes,docker,docker)