-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlxd-for-lxc-user.html
254 lines (236 loc) · 9.99 KB
/
lxd-for-lxc-user.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Getting started with LXD as an LXC user | gpocentek's webspace</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="keywords" content="" />
<meta name="author" content="Gauvain Pocentek" />
<meta name="kittycheck_rumble" content="true" />
<meta name="kittycheck_position" content="top=60,right=60" />
<!-- Le styles -->
<link rel="stylesheet" href="./theme/css/bootstrap.min.css" type="text/css" />
<style type="text/css">
body {
padding-top: 60px;
padding-bottom: 40px;
}
.sidebar-nav {
padding: 9px 0;
}
.tag-1 {
font-size: 13pt;
}
.tag-2 {
font-size: 10pt;
}
.tag-2 {
font-size: 8pt;
}
.tag-4 {
font-size: 6pt;
}
</style>
<link href="./theme/css/bootstrap-responsive.min.css" rel="stylesheet">
<link href="./theme/css/font-awesome.css" rel="stylesheet">
<link href="./theme/css/pygments.css" rel="stylesheet">
<link href="./theme/css/local.css" rel="stylesheet">
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<!-- Le fav and touch icons -->
<link rel="shortcut icon" href="./theme/img/favicon.ico">
<link rel="apple-touch-icon" href="./theme/img/apple-touch-icon.png">
<link rel="apple-touch-icon" sizes="72x72" href="./theme/img/apple-touch-icon-72x72.png">
<link rel="apple-touch-icon" sizes="114x114" href="./theme/img/apple-touch-icon-114x114.png">
<link href="./" type="application/atom+xml" rel="alternate" title="gpocentek's webspace ATOM Feed" />
</head>
<body>
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container-fluid">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<a class="brand" href="./index.html"><strong>gpocentek's webspace</strong> – Random dev & ops notes</a>
<div class="nav-collapse">
<ul class="nav">
</ul>
<!--<p class="navbar-text pull-right">Logged in as <a href="#">username</a></p>-->
</div><!--/.nav-collapse -->
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="span8" id="content">
<div class="row">
<div class="span8">
<section id="content" class="well">
<article>
<header>
<h1>
<a href=""
rel="bookmark"
title="Permalink to Getting started with LXD as an LXC user">
Getting started with LXD as an LXC user
</a>
</h1>
<a href="./tag/lxd.html" class="label"><i class="icon-tag"></i> lxd</a>
<a href="./tag/lxc.html" class="label"><i class="icon-tag"></i> lxc</a>
<abbr class="published pull-right" title="2016-11-27T13:33:00+01:00">
<i class="icon-calendar"></i> sön 27 november 2016
</abbr>
</header>
<div class="entry-content">
<p>I use LXC on my ubuntu workstation quite often. LXD has been out for a while,
and I tested it to see if I could use it as a direct replacement for LXC. And
the answer is yes! LXD provides nice management tools that didn't exist in LXC,
but the mechanics are the same.</p>
<p>This blog is a recap of what I did to setup a local installation. It assumes
you already know what is LXC and how to use it.</p>
<div class="section" id="some-differences-with-lxc">
<h2>Some differences with LXC</h2>
<ul class="simple">
<li>No more template scripts, LXD uses pre-built images. This has become quite
common (think Docker/EC2/OpenStack Glance).</li>
<li>LXD runs as a daemon and can be managed remotely. If run locally any user in
the <tt class="docutils literal">lxd</tt> group can talk to the daemon. APIs are great.</li>
<li>Network management is way simpler, and doesn't require tweaking configuration
files.</li>
</ul>
</div>
<div class="section" id="install-and-configure-lxd">
<h2>Install and configure LXD</h2>
<p>Ubuntu 16.04 seems to come with LXD installed, but in case it isn't there:</p>
<div class="highlight"><pre><span></span>sudo apt install lxd
</pre></div>
<p>You can then use the <tt class="docutils literal">lxd init</tt> tool to setup the initial configuration:</p>
<div class="highlight"><pre><span></span>sudo lxd init
</pre></div>
<p>You will have to answer questions about:</p>
<ul class="simple">
<li>The storage back-end, directory or zfs. The zfs back-end is nice. It uses
clones and snapshots to optimize performance when creating containers, and
consumes less disk space.</li>
<li>The initial network.</li>
<li>The LXD API access: local only or exposed on a network.</li>
</ul>
<p>The <tt class="docutils literal">lxd</tt> command manages the daemon, use the <tt class="docutils literal">lxc</tt> command to manage your
containers.</p>
</div>
<div class="section" id="create-and-access-containers">
<h2>Create and access containers</h2>
<p>The containers creation is straightforward:</p>
<div class="highlight"><pre><span></span>lxc launch ubuntu:16.04 c1
</pre></div>
<p><tt class="docutils literal">ubuntu:16.04</tt> is the reference to an existing container image. If LXD cannot
find it locally, it will download it from a repository (canonical's by
default). The image will then be stored locally.</p>
<p>The container will be started after creation. Use the <tt class="docutils literal">list</tt> or <tt class="docutils literal">info</tt>
subcommands to get information about the new container.</p>
<p>You will not be able to access the container using SSH by default:</p>
<div class="highlight"><pre><span></span><span class="gp">$</span> ssh [email protected]
<span class="go">Permission denied (publickey).</span>
</pre></div>
<p>Just like for ubuntu cloud instances the default user doesn't have a password
set, and you need to use an SSH key to authenticate. An initial setup needs to
be done. Not handy but should only be done once.</p>
<p>To configure your SSH key inside the container use the <tt class="docutils literal">exec</tt> subcommand:</p>
<div class="highlight"><pre><span></span><span class="gp">$</span> lxc <span class="nb">exec</span> c1 /bin/bash
<span class="gp">root@c1:~#</span> <span class="nb">echo</span> <span class="s2">"YOU PUBLIC KEY"</span> > /home/ubuntu/.ssh/authorized_keys
<span class="gp">root@c1:~#</span> <span class="nb">exit</span>
<span class="go">exit</span>
</pre></div>
<p>Validate that you can access the container:</p>
<div class="highlight"><pre><span></span><span class="gp">$</span> ssh [email protected]
<span class="go">...</span>
<span class="gp">ubuntu@c1:~$</span>
</pre></div>
<p>Congrats!</p>
<p>Now you can build a new image that contains you SSH key:</p>
<div class="highlight"><pre><span></span><span class="gp">$</span> lxc stop c1
<span class="gp">$</span> lxc publish c1 --alias ubuntu-ssh
<span class="gp">$</span> lxc image list <span class="p">|</span> grep ubuntu-ssh
<span class="gp">$</span> lxc launch ubuntu-ssh c2
</pre></div>
</div>
<div class="section" id="what-s-next">
<h2>What's next</h2>
<p><a class="reference external" href="https://www.stgraber.org">Stéphane Graber's blog</a> contains a lot a very
interesting articles about LXC/LXD.</p>
<p>You can setup DNS resolution in <a class="reference external" href="https://gauvain.pocentek.net/name-resolution-lxc-containers.html">the same way you might have done for LXC</a>.</p>
<p>The next step for me will be testing LXD as <a class="reference external" href="https://linuxcontainers.org/lxd/getting-started-openstack/">OpenStack nova plugin</a>.</p>
</div>
</div><!-- /.entry-content -->
</article>
</section>
</div>
</div>
</div><!--/span-->
<div class="span3 well sidebar-nav" id="sidebar">
<ul class="nav nav-list">
<li class="nav-header"><h4><i class="icon-home icon-large"></i> social</h4></li>
<li><a href="https://www.linkedin.com/in/gauvainpocentek"><i class="icon-linkedin-sign icon-large"></i>linkedin</a></li>
<li><a href="https://github.com/gpocentek"><i class="icon-github-sign icon-large"></i>github</a></li>
<li class="nav-header"><h4><i class="icon-folder-close icon-large"></i>Categories</h4></li>
<li>
<a href="./category/ansible.html">
<i class="icon-folder-open icon-large"></i>ansible
</a>
</li>
<li>
<a href="./category/containers.html">
<i class="icon-folder-open icon-large"></i>containers
</a>
</li>
<li>
<a href="./category/lxc.html">
<i class="icon-folder-open icon-large"></i>lxc
</a>
</li>
<li>
<a href="./category/lxd.html">
<i class="icon-folder-open icon-large"></i>lxd
</a>
</li>
<li>
<a href="./category/medibuntu.html">
<i class="icon-folder-open icon-large"></i>medibuntu
</a>
</li>
<li>
<a href="./category/misc.html">
<i class="icon-folder-open icon-large"></i>misc
</a>
</li>
<li>
<a href="./category/openstack.html">
<i class="icon-folder-open icon-large"></i>openstack
</a>
</li>
<li>
<a href="./category/python-gitlab.html">
<i class="icon-folder-open icon-large"></i>python-gitlab
</a>
</li>
<li class="nav-header"><h4><i class="icon-th-list icon-large"></i>Archives</h4></li>
<li><a href="./archives.html"><i class="icon-edit icon-large"></i>articles</a></li>
<li class="nav-header"><h4><i class="icon-inbox icon-large"></i>Contact</h4></li>
<li><a href="mailto:[email protected]">
<i class="icon-envelope icon-large"></i>email</a></li>
</li>
<li></li>
</ul> </div><!--/.well -->
</div><!--/row-->
<hr>
</div><!--/.fluid-container-->
<!-- Le javascript -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="./theme/js/jquery-1.7.2.min.js"></script>
<script src="./theme/js/bootstrap.min.js"></script>
</body>
</html>