systemctl daemon-reload \
&& systemctl enable docker \
&& systemctl start docker \
&& systemctl restart docker \
查看服务状态
systemctl status docker
调试服务:(以kubelet为例)
查看service的启动命令 查看启动配置 修改启动配置 重新启动 查看命令的执行日志 查看系统日志 vagrant@ubuntu-xenial:/vagrant$ systemctl status kubelet ● kubelet.service - Kubernetes Kubelet Server Loaded: loaded (/etc/systemd/system/kubelet.service; enabled; vendor preset: enabled) Active: active (running) since Sat -- :: UTC; 1h 23min ago Docs: https://github.com/GoogleCloudPlatform/kubernetes Process: ExecStartPre=/bin//SUCCESS) Process: ExecStartPre=/bin//SUCCESS) Process: ExecStartPre=/bin//SUCCESS) Process: ExecStartPre=/bin//SUCCESS) Process: ExecStartPre=/bin//SUCCESS) Process: ExecStartPre=/bin//SUCCESS) Process: ExecStartPre=/bin//SUCCESS) Process: ExecStartPre=/bin//SUCCESS) Process: ExecStartPre=/bin//SUCCESS) Process: ExecStartPre=/bin//SUCCESS) Process: ExecStartPre=/bin//SUCCESS) Process: ExecStartPre=/bin//SUCCESS) Process: ExecStartPre=/bin//SUCCESS) Process: ExecStartPre=/bin//SUCCESS) Process: ExecStartPre=/bin//SUCCESS) Process: ExecStartPre=/bin//SUCCESS) Process: ExecStartPre=/bin//SUCCESS) Main PID: (kubelet) Tasks: Memory: 87.2M CPU: 13min .454s CGroup: /system.slice/kubelet.service └─ /usr/bin/kubelet --v= --address=0.0.0.0 --hostname-override=10.0.2.15 --kubeconfig=/etc/kubernetes/kubelet.kubeconfig --pod-manifest-path=/etc/kubernetes/manifests --log-dir=/root/info/logs/k8s - lines -/ (END) ctrl+c退出 查看命令脚本: vagrant@ubuntu-xenial:/vagrant$ cat /etc/systemd/system/kubelet.service [Unit] Description=Kubernetes Kubelet Server Documentation=https://github.com/GoogleCloudPlatform/kubernetes After=docker.service Requires=docker.service [Service] WorkingDirectory=/var/lib/kubelet ExecStartPre=/bin/mkdir -p /sys/fs/cgroup/cpuset/system.slice ExecStartPre=/bin/mkdir -p /sys/fs/cgroup/perf_event/system.slice ExecStartPre=/bin/mkdir -p /sys/fs/cgroup/net_cls,net_prio/system.slice ExecStartPre=/bin/mkdir -p /sys/fs/cgroup/freezer/system.slice ExecStartPre=/bin/mkdir -p /sys/fs/cgroup/hugetlb/system.slice ExecStartPre=/bin/mkdir -p /sys/fs/cgroup/pids/system.slice ExecStartPre=/bin/mkdir -p /sys/fs/cgroup/pids/kubelet.service ExecStartPre=/bin/mkdir -p /sys/fs/cgroup/blkio/kubelet.service ExecStartPre=/bin/mkdir -p /sys/fs/cgroup/cpu,cpuacct/kubelet.service ExecStartPre=/bin/mkdir -p /sys/fs/cgroup/systemd/kubelet.service ExecStartPre=/bin/mkdir -p /sys/fs/cgroup/net_cls,net_prio/kubelet.service ExecStartPre=/bin/mkdir -p /sys/fs/cgroup/freezer/kubelet.service ExecStartPre=/bin/mkdir -p /sys/fs/cgroup/memory/kubelet.service ExecStartPre=/bin/mkdir -p /sys/fs/cgroup/cpuset/kubelet.service ExecStartPre=/bin/mkdir -p /sys/fs/cgroup/perf_event/kubelet.service ExecStartPre=/bin/mkdir -p /sys/fs/cgroup/devices/kubelet.service ExecStartPre=/bin/mkdir -p /sys/fs/cgroup/hugetlb/kubelet.service EnvironmentFile=-/etc/kubernetes/config EnvironmentFile=-/etc/kubernetes/kubelet ExecStart=/usr/bin/kubelet \ $KUBE_LOGTOSTDERR \ $KUBE_LOG_LEVEL \ $KUBELET_API_SERVER \ $KUBELET_ADDRESS \ $KUBELET_PORT \ $KUBELET_HOSTNAME \ $KUBE_ALLOW_PRIV \ $KUBELET_ARGS Restart=always RestartSec= [Install] WantedBy=multi-user.target vagrant@ubuntu-xenial:/vagrant$ cat /etc/kubernetes/kubelet.kubeconfig apiVersion: v1 kind: Config current-context: kubelet-to-cluster.local preferences: {} clusters: - cluster: certificate-authority: /etc/kubernetes/certs/ca.crt server: https://10.0.2.15:6443 name: cluster.local contexts: - context: cluster: cluster.local user: kubelet name: kubelet-to-cluster.local users: - name: kubelet user: token: lHiWR3ogjcdq691yX4QxMq06SRmv1DfF 此处可以修改kubelet服务地址,比如:此时虚机网络设置为private-network, ip=192.168.33.10, 可以将server地址改为192.168.33.10,外面就可以通过小网192.168.33.10访问。
vagrant@ubuntu-xenial:/vagrant$ cat /etc/kubernetes/config ### # kubernetes system config # # The following values are used to configure various aspects of all # kubernetes services, including # # kube-apiserver.service # kube-controller-manager.service # kube-scheduler.service # kubelet.service # kube-proxy.service # journal verbosity level, the higher is the more verbose KUBE_LOG_LEVEL="--v=0" # How the replication controller, scheduler, and proxy KUBE_MASTER="--master=https://10.0.2.15:6443" vagrant@ubuntu-xenial:/vagrant$ systemctl restart kubelet