LFS258-LAB-Services

2018-12-04  本文已影响0人  xiao_b4b1

部署service

1.创建 deployment

student@ubuntu:~/job$cat nginx-one.yaml 
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: nginx-one
  labels:
    system: secondary
spec:
  replicas: 2
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - image: nginx
        imagePullPolicy: Always
        name: nginx
        ports:
        - containerPort: 80
          protocol: TCP

student@ubuntu:~/job$kubectl create -f nginx-one.yaml
  1. 创建service
student@ubuntu:~/job$kubectl expose deployment nginx-one 
service/nginx-one exposed

student@ubuntu:~/job$kubectl get svc
NAME         TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)   AGE
kubernetes   ClusterIP   10.96.0.1        <none>        443/TCP   5d17h
nginx-one    ClusterIP   10.106.204.175   <none>        80/TCP    4s

student@ubuntu:~/job$curl 10.106.204.175
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;

配置NodePort

student@ubuntu:~/job$kubectl expose deployment nginx-one --name=nginx-node-port --type=NodePort
service/nginx-node-port exposed

student@ubuntu:~/job$kubectl get svc
NAME              TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE
kubernetes        ClusterIP   10.96.0.1        <none>        443/TCP        5d17h
nginx-node-port   NodePort    10.101.146.38    <none>        80:31555/TCP   3s
nginx-one         ClusterIP   10.106.204.175   <none>        80/TCP         99s

使用label管理资源

1.删除pod

student@ubuntu:~/addons/efk$kubectl get pod --show-labels
NAME                        READY   STATUS    RESTARTS   AGE   LABELS
nginx-one-c5b5c6f7c-l569b   1/1     Running   0          17m   app=nginx,pod-template-hash=c5b5c6f7c
nginx-one-c5b5c6f7c-xf2gj   1/1     Running   0          17m   app=nginx,pod-template-hash=c5b5c6f7c
student@ubuntu:~/addons/efk$kubectl delete pod -l app=nginx
pod "nginx-one-c5b5c6f7c-l569b" deleted
pod "nginx-one-c5b5c6f7c-xf2gj" deleted

2.删除deployment

student@ubuntu:~/addons/efk$kubectl get deployments. --show-labels
NAME        DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE   LABELS
nginx-one   2         2         2            2           21m   system=secondary


student@ubuntu:~/addons/efk$kubectl get deployments. --show-labels
NAME        DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE   LABELS
nginx-one   2         2         2            2           21m   system=secondary

3.给资源添加标签

student@ubuntu:~/addons/efk$kubectl get nodes --show-labels
NAME       STATUS   ROLES    AGE     VERSION   LABELS
node-193   Ready    worker   5d16h   v1.12.1   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/fluentd-ds-ready=true,beta.kubernetes.io/os=linux,kubernetes.io/hostname=node-193,node-role.kubernetes.io/worker=
ubuntu     Ready    master   5d17h   v1.12.1   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/fluentd-ds-ready=true,beta.kubernetes.io/os=linux,kubernetes.io/hostname=ubuntu,node-role.kubernetes.io/master=
student@ubuntu:~/addons/efk$kubectl label nodes key=value
error: resource(s) were provided, but no name, label selector, or --all flag specified
student@ubuntu:~/addons/efk$kubectl label nodes ubuntu key=value
node/ubuntu labeled
student@ubuntu:~/addons/efk$kubectl get nodes --show-labels
NAME       STATUS   ROLES    AGE     VERSION   LABELS
node-193   Ready    worker   5d16h   v1.12.1   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/fluentd-ds-ready=true,beta.kubernetes.io/os=linux,kubernetes.io/hostname=node-193,node-role.kubernetes.io/worker=
ubuntu     Ready    master   5d17h   v1.12.1   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/fluentd-ds-ready=true,beta.kubernetes.io/os=linux,key=value,kubernetes.io/hostname=ubuntu,node-role.kubernetes.io/master=
上一篇下一篇

猜你喜欢

热点阅读